Beispiel #1
0
        public void Put(PutRequest request, out PutResponse response)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.ModifyRequest == null)
            {
                throw new ArgumentNullException("ModifyRequest");
            }
            if (request.ResourceReferenceProperty == null)
            {
                throw new ArgumentNullException("ResourceReferenceProperty");
            }

            Message putRequest = null;

            lock (request)
            {
                putRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.PutAction, request.ModifyRequest, new ClientSerializer(typeof(ModifyRequest)));
                ClientHelper.AddImdaHeaders(request as ImdaRequest, putRequest);
                ClientHelper.AddRmHeaders(request as WsTransfer.TransferRequest, putRequest);
            }
            Message putResponse = Put(putRequest);

            response = new PutResponse(putResponse);
            if (putResponse.IsFault)
            {
                ClientHelper.HandleFault(putResponse);
            }

            // the response has no information if it isn't a fault
            // PutResponse putResponseTyped = putResponse.GetBody<PutResponse>(new ClientSerializer(typeof(PutResponse)));
        }
Beispiel #2
0
        public Message CreateGetRequest(RmReference objectId, CultureInfo culture, string[] attributes)
        {
            if (objectId == null || string.IsNullOrEmpty(objectId.Value))
            {
                throw new ArgumentNullException("objectId");
            }

            Message msgGetRequest            = null;
            bool    isAttributeSearchRequest = false;

            RequestGet requestGet = new RequestGet()
            {
                ResourceReferenceProperty = objectId.Value
            };

            if (culture != null)
            {
                requestGet.ResourceLocaleProperty = culture.Name;
            }
            if (attributes != null && attributes.Length != 0)
            {
                isAttributeSearchRequest = true;
                List <string> attributeList = new List <string>(attributes);
                if (string.IsNullOrEmpty(attributeList.Find(a => a.ToLower() == "objecttype")))
                {
                    attributeList.Add("ObjectType");
                }
                requestGet.RequestAttributeSearch = new RequestAttributeSearch(attributeList.ToArray());
            }

            if (!isAttributeSearchRequest)
            {
                msgGetRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.GetAction);
            }
            else
            {
                msgGetRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.GetAction,
                                                      requestGet.RequestAttributeSearch, new ClientSerializer(typeof(RequestAttributeSearch)));
                ClientHelper.AddImdaHeaders(requestGet, msgGetRequest);
            }

            ClientHelper.AddRmHeaders(requestGet, msgGetRequest);

            return(msgGetRequest);
        }
        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);
        }
Beispiel #4
0
        public Message CreateCreateRequest(RmGeneric 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 (!string.IsNullOrEmpty(ProhibitedAttributes.Find(p => p.Equals(attribute.Key.Name, StringComparison.OrdinalIgnoreCase))))
                    {
                        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);
                    }
                }

                Message msgCreateRequest = null;
                lock (createRequest)
                {
                    msgCreateRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.CreateAction, createRequest.AddRequest, new ClientSerializer(typeof(AddRequest)));
                    ClientHelper.AddImdaHeaders(createRequest, msgCreateRequest);

                    return(msgCreateRequest);
                }
            }
        }
Beispiel #5
0
        public Message CreatePutRequest(RmResourceChanges transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentException("transaction");
            }
            RmResource rmObject = transaction.RmObject;

            if (rmObject == null)
            {
                throw new InvalidOperationException("transaction does not have rmObject");
            }

            lock (rmObject)
            {
                RequestPut putRequest = new RequestPut();
                putRequest.ResourceReferenceProperty = rmObject.ObjectID.ToString();
                if (String.IsNullOrEmpty(rmObject.Locale) == false)
                {
                    putRequest.ResourceLocaleProperty = CultureInfo.GetCultureInfo(rmObject.Locale).ToString(); //System.Globalization.CultureInfo(rmObject.Locale)
                }

                putRequest.ModifyRequest = new ModifyRequest();

                IList <RmAttributeChange> changes = transaction.GetChanges();

                foreach (RmAttributeChange attributeChange in changes)
                {
                    if (!string.IsNullOrEmpty(ProhibitedAttributes.Find(p => p.Equals(attributeChange.Name.Name, StringComparison.OrdinalIgnoreCase))))
                    {
                        continue;
                    }

                    DirectoryAccessChange putReqChange = BuildDirectoryAccessChange(attributeChange);

                    if (base.IsMultiValued(attributeChange.Name))
                    {
                        putReqChange.Operation = attributeChange.Operation.ToString();
                    }
                    else
                    {
                        if (attributeChange.Operation == RmAttributeChangeOperation.Add)
                        {
                            putReqChange.Operation = RmAttributeChangeOperation.Replace.ToString();
                        }
                        else if (attributeChange.Operation == RmAttributeChangeOperation.Delete)
                        {
                            putReqChange.Operation      = RmAttributeChangeOperation.Replace.ToString();
                            putReqChange.AttributeValue = null;
                        }
                    }
                    putRequest.ModifyRequest.Changes.Add(putReqChange);
                }

                Message msgRequest = null;
                lock (putRequest)
                {
                    msgRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.PutAction, putRequest.ModifyRequest, new ClientSerializer(typeof(ModifyRequest)));
                    ClientHelper.AddImdaHeaders(putRequest, msgRequest);
                    ClientHelper.AddRmHeaders(putRequest, msgRequest);
                }

                return(msgRequest);
            }
        }
Beispiel #6
0
        public GetResponse Get(GetRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            Message getRequest = null;
            bool    isBaseObjectSearchRequest = false;

            lock (request)
            {
                if (request.BaseObjectSearchRequest == null || request.BaseObjectSearchRequest.AttributeTypes.Count == 0)
                {
                    getRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.GetAction);
                }
                else
                {
                    isBaseObjectSearchRequest = true;
                    getRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.GetAction, request.BaseObjectSearchRequest, new ClientSerializer(typeof(BaseObjectSearchRequest)));
                    ClientHelper.AddImdaHeaders(request as ImdaRequest, getRequest);
                }

                ClientHelper.AddRmHeaders(request as WsTransfer.TransferRequest, getRequest);
            }
            Message getResponse = Get(getRequest);

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

            GetResponse getResponseTyped = new GetResponse();

            if (isBaseObjectSearchRequest)
            {
                BaseObjectSearchResponse baseObjectSearchResponse = getResponse.GetBody <BaseObjectSearchResponse>(new ClientSerializer(typeof(BaseObjectSearchResponse)));
                getResponseTyped.BaseObjectSearchResponse = baseObjectSearchResponse;
            }
            else
            {
                // we manually construct the partial attributes as if the client had selected all attributes
                // the purpose is to unify the API of the get request
                XmlNode retObject = getResponse.GetBody <XmlNode>(new ClientSerializer(typeof(XmlNode)));
                Dictionary <String, List <XmlNode> > seenAttributes = new Dictionary <string, List <XmlNode> >();
                foreach (XmlNode child in retObject.ChildNodes)
                {
                    if (child.NodeType == XmlNodeType.Element)
                    {
                        if (seenAttributes.ContainsKey(child.Name) == false)
                        {
                            seenAttributes[child.Name] = new List <XmlNode>();
                        }
                        seenAttributes[child.Name].Add(child);
                    }
                }

                getResponseTyped.BaseObjectSearchResponse = new BaseObjectSearchResponse();
                foreach (KeyValuePair <String, List <XmlNode> > item in seenAttributes)
                {
                    PartialAttributeType partialAttribute = new PartialAttributeType();
                    partialAttribute.Values.AddRange(item.Value);
                }
            }
            return(getResponseTyped);
        }