コード例 #1
0
        public PullResponse Pull(PullRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.EnumerationContext == null)
            {
                throw new InvalidOperationException("EnumerationContext must be set in order to call Pull");
            }
            Message pullRequest;

            lock (request) {
                pullRequest = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, Constants.WsEnumeration.PullAction, request, new ClientSerializer(typeof(PullRequest)));
            }
            Message pullResponse = Pull(pullRequest);

            if (pullResponse.IsFault)
            {
                // handle fault will throw a .NET exception
                ClientHelper.HandleFault(pullResponse);
            }

            PullResponse pullResponseTyped = pullResponse.GetBody <PullResponse>(new ClientSerializer(typeof(PullResponse)));

            return(pullResponseTyped);
        }
コード例 #2
0
        /// <summary>
        /// Creates a list of resources based on the pull or enumerate response.
        /// </summary>
        /// <param name="pullOrEnumerateResponse">The pull or enumerate response to use when creating resources.</param>
        /// <returns>The list of strongly-typed resources in the pull or enumerate response.</returns>
        public List<RmResource> CreateResource(PullResponse pullOrEnumerateResponse)
        {
            if (pullOrEnumerateResponse == null) {
                throw new ArgumentNullException("pullOrEnumerateResponse");
            }
            if (pullOrEnumerateResponse.Items == null || pullOrEnumerateResponse.Items.Values == null) {
                return new List<RmResource>();
            }
            lock (pullOrEnumerateResponse) {
                List<RmResource> retList = new List<RmResource>();

                foreach (XmlNode obj in pullOrEnumerateResponse.Items.Values) {
                    // look ahead for the type info;
                    String objectType = null;
                    foreach (XmlNode child in obj.ChildNodes) {
                        if (child.NodeType == XmlNodeType.Element) {
                            if (child.LocalName.Equals(@"ObjectType")) {
                                objectType = child.InnerText;
                                break;
                            }
                        }
                    }
                    if (objectType == null) {
                        objectType = String.Empty;
                    }

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

                    // now add the attributes to the resource object
                    foreach (XmlNode child in obj.ChildNodes) {
                        if (child.NodeType == XmlNodeType.Element) {
                            RmAttributeName attributeName = new RmAttributeName(child.LocalName);
                            IComparable attributeValue = this.ConstructAttributeValue(attributeName, child.InnerText);
                            if (attributeValue == null)
                                continue;

                            RmAttributeValue newAttribute = null;
                            if (rmResource.TryGetValue(attributeName, out newAttribute) == false) {
                                newAttribute = CreateRmAttributeValue(attributeName);
                                rmResource[attributeName] = newAttribute;
                            }
                            if (base.IsMultiValued(attributeName) == false)
                                newAttribute.Values.Clear();
                            if (attributeName.Name.Equals(ObjectType) || attributeName.Name.Equals(ObjectID))
                                newAttribute.Values.Clear();
                            newAttribute.Values.Add(attributeValue);
                        }
                    }
                    retList.Add(rmResource);
                }

                return retList;
            }
        }