Microsoft.ResourceManagement.Client.RmResourceFactory.CreateResource C# (CSharp) Méthode

CreateResource() public méthode

Returns a generic RmResource object from the getResponse object.
public CreateResource ( GetResponse getResponse ) : RmResource
getResponse Microsoft.ResourceManagement.Client.WsTransfer.GetResponse The get response from the server.
Résultat Microsoft.ResourceManagement.ObjectModel.RmResource
        public RmResource CreateResource(GetResponse getResponse)
        {
            if (getResponse == null) {
                throw new ArgumentNullException("getResponse");
            }
            if (getResponse.BaseObjectSearchResponse == null) {
                throw new ArgumentNullException("getResponse.BaseObjectSearchResponse");
            }
            lock (getResponse) {
                // look ahead for the type
                String objectType = null;
                foreach (PartialAttributeType partialAttribute in getResponse.BaseObjectSearchResponse.PartialAttributes) {
                    if (partialAttribute.Values.Count > 0) {
                        String localName = partialAttribute.Values[0].LocalName;
                        if (String.IsNullOrEmpty(localName)) {
                            continue;
                        }
                        if (localName.Equals(ObjectType)) {
                            objectType = partialAttribute.Values[0].InnerText;
                            break;
                        }

                    }
                }

                if (objectType == null) {
                    objectType = string.Empty;
                }

                RmResource rmResource = this.resourceTypeFactory.CreateResource(objectType);

                // fill in the attribute values
                foreach (PartialAttributeType partialAttribute in getResponse.BaseObjectSearchResponse.PartialAttributes) {
                    RmAttributeName attributeName = null;
                    RmAttributeValue newAttribute = null;
                    if (partialAttribute.Values.Count > 0) {
                        String localName = partialAttribute.Values[0].LocalName;
                        if (String.IsNullOrEmpty(localName)) {
                            continue;
                        } else {
                            attributeName = new RmAttributeName(localName);
                        }
                    } else {
                        continue;
                    }

                    if (rmResource.TryGetValue(attributeName, out newAttribute) == false) {
                        newAttribute = CreateRmAttributeValue(attributeName);
                        // PATCHED: the following line was missing
                        rmResource[attributeName] = newAttribute;
                    }

                    // add values to the typed list
                    foreach (XmlNode value in partialAttribute.Values) {
                        IComparable newValue = this.ConstructAttributeValue(attributeName, value.InnerText);
                        if (base.IsMultiValued(attributeName) == false)
                            newAttribute.Values.Clear();
                        if (attributeName.Name.Equals(ObjectType) || attributeName.Name.Equals(ObjectID))
                            newAttribute.Values.Clear();

                        newAttribute.Values.Add(newValue);
                    }
                }
                return rmResource;
            }
        }

Same methods

RmResourceFactory::CreateResource ( PullResponse pullOrEnumerateResponse ) : List

Usage Example

Exemple #1
0
        public bool MoveNext()
        {
            lock (this.client) {
                if (resultIndex < results.Count)
                {
                    this.current = results[resultIndex++];
                    return(true);
                }
                else
                {
                    PullResponse response;
                    if (this.context == null)
                    {
                        if (resultIndex > 0)
                        {
                            // case: previous pull returned an invalid context
                            return(false);
                        }
                        EnumerationRequest request = new EnumerationRequest(filter);
                        if (attributes != null)
                        {
                            request.Selection = new List <string>();
                            request.Selection.AddRange(this.attributes);
                        }
                        response           = client.Enumerate(request);
                        this.endOfSequence = response.EndOfSequence != null;
                    }
                    else
                    {
                        if (this.endOfSequence == true)
                        {
                            // case: previous pull returned an end of sequence flag
                            this.current = null;
                            return(false);
                        }
                        PullRequest request = new PullRequest();
                        request.EnumerationContext = this.context;
                        response = client.Pull(request);
                    }

                    if (response == null)
                    {
                        return(false);
                    }
                    resultIndex        = 0;
                    this.results       = resourceFactory.CreateResource(response);
                    this.context       = response.EnumerationContext;
                    this.endOfSequence = response.IsEndOfSequence;
                    if (this.results.Count > 0)
                    {
                        this.current = results[resultIndex++];
                        return(true);
                    }
                    else
                    {
                        this.current = null;
                        return(false);
                    }
                }
            }
        }