public DeleteResponse Delete(DeleteRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.ResourceReferenceProperty == null) { throw new ArgumentNullException("ResourceReferenceProperty"); } Message deleteRequest = null; lock (request) { deleteRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.DeleteAction, request, new ClientSerializer(typeof(DeleteRequest))); ClientHelper.AddRmHeaders(request as WsTransfer.TransferRequest, deleteRequest); } Message deleteResponse = Delete(deleteRequest); if (deleteResponse.IsFault) { ClientHelper.HandleFault(deleteResponse); } // the response has no information if it isn't a fault // return deleteResponse.GetBody<DeleteResponse>(new ClientSerializer(typeof(DeleteResponse))); return(new DeleteResponse()); }
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))); }
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 Message CreateDeleteRequest(RmReference objectId) { if (objectId == null) { throw new ArgumentNullException("objectId"); } RequestDelete deleteRequest = new RequestDelete(); deleteRequest.ResourceReferenceProperty = objectId.Value; Message msgRequest = null; lock (deleteRequest) { msgRequest = Message.CreateMessage(MessageVersion.Default, Constants.WsTransfer.DeleteAction, deleteRequest, new ClientSerializer(typeof(RequestDelete))); ClientHelper.AddRmHeaders(deleteRequest, msgRequest); } return(msgRequest); }
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); } }
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); }