Inheritance: ImdaRequest
示例#1
0
        /// <summary>
        /// Constructs a create request based on the provided object.
        /// </summary>
        /// <param name="newResource">The RmResource object for which to construct a create request.</param>
        /// <returns></returns>
        public virtual CreateRequest CreateCreateRequest(RmResource newResource)
        {
            if (newResource == null)
            {
                throw new ArgumentNullException("newResource");
            }
            lock (newResource)
            {
                CreateRequest createRequest = new CreateRequest();

                createRequest.AddRequest = new AddRequest();
                createRequest.AddRequest.AttributeTypeAndValues = new List<DirectoryAccessChange>();
                foreach (KeyValuePair<RmAttributeName, RmAttributeValue> attribute in newResource.Attributes)
                {
                    if (this.ProhibitedAttributes.ContainsKey(attribute.Key.Name))
                        continue;

                    foreach (IComparable value in attribute.Value.Values)
                    {
                        DirectoryAccessChange createReqChange = BuildDirectoryAccessChange(attribute.Key, value);
                        // cannot specify the operation on create
                        createReqChange.Operation = null;
                        createRequest.AddRequest.AttributeTypeAndValues.Add(createReqChange);
                    }
                }
                return createRequest;
            }
        }
        public CreateResponse Create(CreateRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.AddRequest == null)
            {
                throw new ArgumentNullException("AddRequest");
            }
            Message createRequest = null;

            lock (request) {
                createRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.CreateAction, request.AddRequest, new ClientSerializer(typeof(AddRequest)));
                ClientHelper.AddImdaHeaders(request as ImdaRequest, createRequest);
            }
            Message createResponse = Create(createRequest);

            if (createResponse.IsFault)
            {
                ClientHelper.HandleFault(createResponse);
            }

            CreateResponse createResponseTyped = new CreateResponse();

            // for a reason which is not clear, this isn't working
            // createResponseTyped.ResourceCreated = createResponse.GetBody<ResourceCreated>(new ClientSerializer(typeof(ResourceCreated)));

            // alternative way to de-serialize the message...
            System.Xml.XmlNode body = createResponse.GetBody <System.Xml.XmlNode>(new ClientSerializer(typeof(System.Xml.XmlNode)));
            createResponseTyped.ResourceCreated = new ResourceCreated();
            createResponseTyped.ResourceCreated.EndpointReference = new EndpointReference();
            try {
                createResponseTyped.ResourceCreated.EndpointReference.Address             = body["EndpointReference"]["Address"].InnerText;
                createResponseTyped.ResourceCreated.EndpointReference.ReferenceProperties = new ReferenceProperties();
                createResponseTyped.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty       = new ResourceReferenceProperty();
                createResponseTyped.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value = body["EndpointReference"]["ReferenceProperties"]["ResourceReferenceProperty"].InnerText;
            } catch (NullReferenceException) {
            }
            return(createResponseTyped);
        }