public override DirectoryResponse SendRequest(DirectoryRequest request) { if (request == null) { throw new ArgumentNullException("request"); } DsmlRequestDocument document = new DsmlRequestDocument(); document.Add(request); DsmlResponseDocument document2 = this.SendRequestHelper(document.ToXml().InnerXml); if (document2.Count == 0) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("MissingResponse")); } DirectoryResponse response = document2[0]; if (response is DsmlErrorResponse) { ErrorResponseException exception = new ErrorResponseException((DsmlErrorResponse)response); throw exception; } ResultCode resultCode = response.ResultCode; if (((resultCode != ResultCode.Success) && (resultCode != ResultCode.CompareFalse)) && (((resultCode != ResultCode.CompareTrue) && (resultCode != ResultCode.Referral)) && (resultCode != ResultCode.ReferralV2))) { throw new DirectoryOperationException(response, OperationErrorMappings.MapResultCode((int)resultCode)); } return(response); }
internal DsmlResponseDocument(StringBuilder responseString, string xpathToResponse) : this() { this.dsmlDocument = new XmlDocument(); try { this.dsmlDocument.LoadXml(responseString.ToString()); } catch (XmlException) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("NotWellFormedResponse")); } this.dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); this.dsmlBatchResponse = (XmlElement)this.dsmlDocument.SelectSingleNode(xpathToResponse, this.dsmlNS); if (this.dsmlBatchResponse == null) { throw new DsmlInvalidDocumentException(System.DirectoryServices.Protocols.Res.GetString("NotWellFormedResponse")); } foreach (XmlNode node in this.dsmlBatchResponse.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { DirectoryResponse response = this.ConstructElement((XmlElement)node); this.dsmlResponse.Add(response); } } }
internal DsmlResponseDocument(StringBuilder responseString, string xpathToResponse) : this() { this.dsmlDocument = new XmlDocument(); try { this.dsmlDocument.LoadXml(responseString.ToString()); } catch (XmlException xmlException) { throw new DsmlInvalidDocumentException(Res.GetString("NotWellFormedResponse")); } this.dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); this.dsmlBatchResponse = (XmlElement)this.dsmlDocument.SelectSingleNode(xpathToResponse, this.dsmlNS); if (this.dsmlBatchResponse != null) { XmlNodeList childNodes = this.dsmlBatchResponse.ChildNodes; foreach (XmlNode childNode in childNodes) { if (childNode.NodeType != XmlNodeType.Element) { continue; } DirectoryResponse directoryResponse = this.ConstructElement((XmlElement)childNode); this.dsmlResponse.Add(directoryResponse); } return; } else { throw new DsmlInvalidDocumentException(Res.GetString("NotWellFormedResponse")); } }
internal DsmlResponseDocument(HttpWebResponse resp, string xpathToResponse) : this() { // Our caller (the DsmlConnection-derived class) passes us the XPath telling us // how to locate the batchResponse element. This permits us to work with // different transport protocols. // Get the response stream Stream respStream = resp.GetResponseStream(); StreamReader respStreamReader = new StreamReader(respStream); try { // Load the response from the stream into the XmlDocument _dsmlDocument = new XmlDocument(); try { _dsmlDocument.Load(respStreamReader); } catch (XmlException) { // The server didn't return well-formed XML to us throw new DsmlInvalidDocumentException(Res.GetString(Res.NotWellFormedResponse)); } // Locate the batchResponse element within the response document _dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); _dsmlBatchResponse = (XmlElement)_dsmlDocument.SelectSingleNode(xpathToResponse, _dsmlNS); if (_dsmlBatchResponse == null) { throw new DsmlInvalidDocumentException(Res.GetString(Res.NotWellFormedResponse)); } // parse the response and put it in our internal store XmlNodeList nodeList = _dsmlBatchResponse.ChildNodes; // Unfortunately, we can't just index into the XmlNodeList, // because it's a list of all the nodes, not just the elements. // We're interested in the Nth element, not the Nth node. foreach (XmlNode node in nodeList) { if (node.NodeType == XmlNodeType.Element) { Debug.Assert(node is XmlElement); DirectoryResponse el = ConstructElement((XmlElement)node); _dsmlResponse.Add(el); } } } finally { respStreamReader.Close(); } }
private static string CreateMessage(DirectoryResponse response, string message) { string result = message ?? SR.DefaultOperationsError; if (!string.IsNullOrEmpty(response?.ErrorMessage)) { result += " " + response.ErrorMessage; } return(result); }
private DirectoryResponse ConstructElement(XmlElement node) { DirectoryResponse dsmlErrorResponse = null; string localName = node.LocalName; string str = localName; if (localName != null) { if (str == "errorResponse") { dsmlErrorResponse = new DsmlErrorResponse(node); } else if (str == "searchResponse") { dsmlErrorResponse = new SearchResponse(node); } else if (str == "modifyResponse") { dsmlErrorResponse = new ModifyResponse(node); } else if (str == "addResponse") { dsmlErrorResponse = new AddResponse(node); } else if (str == "delResponse") { dsmlErrorResponse = new DeleteResponse(node); } else if (str == "modDNResponse") { dsmlErrorResponse = new ModifyDNResponse(node); } else if (str == "compareResponse") { dsmlErrorResponse = new CompareResponse(node); } else if (str == "extendedResponse") { dsmlErrorResponse = new ExtendedResponse(node); } else if (str == "authResponse") { dsmlErrorResponse = new DsmlAuthResponse(node); } else { throw new DsmlInvalidDocumentException(Res.GetString("UnknownResponseElement")); } return(dsmlErrorResponse); } throw new DsmlInvalidDocumentException(Res.GetString("UnknownResponseElement")); }
private DirectoryResponse ConstructElement(XmlElement node) { DirectoryResponse el = null; Debug.Assert(node != null); switch (node.LocalName) { case DsmlConstants.DsmlErrorResponse: el = new DsmlErrorResponse(node); break; case DsmlConstants.DsmlSearchResponse: el = new SearchResponse(node); break; case DsmlConstants.DsmlModifyResponse: el = new ModifyResponse(node); break; case DsmlConstants.DsmlAddResponse: el = new AddResponse(node); break; case DsmlConstants.DsmlDelResponse: el = new DeleteResponse(node); break; case DsmlConstants.DsmlModDNResponse: el = new ModifyDNResponse(node); break; case DsmlConstants.DsmlCompareResponse: el = new CompareResponse(node); break; case DsmlConstants.DsmlExtendedResponse: el = new ExtendedResponse(node); break; case DsmlConstants.DsmlAuthResponse: el = new DsmlAuthResponse(node); break; default: throw new DsmlInvalidDocumentException(Res.GetString(Res.UnknownResponseElement)); } Debug.Assert(el != null); return(el); }
internal DsmlResponseDocument(HttpWebResponse resp, string xpathToResponse) : this() { Stream responseStream = resp.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); try { this.dsmlDocument = new XmlDocument(); try { this.dsmlDocument.Load(streamReader); } catch (XmlException xmlException) { throw new DsmlInvalidDocumentException(Res.GetString("NotWellFormedResponse")); } this.dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); this.dsmlBatchResponse = (XmlElement)this.dsmlDocument.SelectSingleNode(xpathToResponse, this.dsmlNS); if (this.dsmlBatchResponse != null) { XmlNodeList childNodes = this.dsmlBatchResponse.ChildNodes; foreach (XmlNode childNode in childNodes) { if (childNode.NodeType != XmlNodeType.Element) { continue; } DirectoryResponse directoryResponse = this.ConstructElement((XmlElement)childNode); this.dsmlResponse.Add(directoryResponse); } } else { throw new DsmlInvalidDocumentException(Res.GetString("NotWellFormedResponse")); } } finally { streamReader.Close(); } }
internal DsmlResponseDocument(StringBuilder responseString, string xpathToResponse) : this() { _dsmlDocument = new XmlDocument(); try { _dsmlDocument.LoadXml(responseString.ToString()); } catch (XmlException) { // The server didn't return well-formed XML to us throw new DsmlInvalidDocumentException(Res.GetString(Res.NotWellFormedResponse)); } // Locate the batchResponse element within the response document _dsmlNS = NamespaceUtils.GetDsmlNamespaceManager(); _dsmlBatchResponse = (XmlElement)_dsmlDocument.SelectSingleNode(xpathToResponse, _dsmlNS); if (_dsmlBatchResponse == null) { throw new DsmlInvalidDocumentException(Res.GetString(Res.NotWellFormedResponse)); } // parse the response and put it in our internal store XmlNodeList nodeList = _dsmlBatchResponse.ChildNodes; // Unfortunately, we can't just index into the XmlNodeList, // because it's a list of all the nodes, not just the elements. // We're interested in the Nth element, not the Nth node. foreach (XmlNode node in nodeList) { if (node.NodeType == XmlNodeType.Element) { Debug.Assert(node is XmlElement); DirectoryResponse el = ConstructElement((XmlElement)node); _dsmlResponse.Add(el); } } }
public override DirectoryResponse SendRequest(DirectoryRequest request) { if (request == null) { throw new ArgumentNullException("request"); } DsmlRequestDocument doc = new DsmlRequestDocument(); doc.Add(request); DsmlResponseDocument response = SendRequestHelper(doc.ToXml().InnerXml); if (response.Count == 0) { throw new DsmlInvalidDocumentException(Res.GetString(Res.MissingResponse)); } DirectoryResponse result = response[0]; if (result is DsmlErrorResponse) { // need to throw ErrorResponseException ErrorResponseException e = new ErrorResponseException((DsmlErrorResponse)result); throw e; } else { ResultCode error = result.ResultCode; if (error == ResultCode.Success || error == ResultCode.CompareFalse || error == ResultCode.CompareTrue || error == ResultCode.Referral || error == ResultCode.ReferralV2) { return(result); } else { throw new DirectoryOperationException(result, OperationErrorMappings.MapResultCode((int)error)); } } }
public override DirectoryResponse SendRequest(DirectoryRequest request) { if (request != null) { DsmlRequestDocument dsmlRequestDocuments = new DsmlRequestDocument(); dsmlRequestDocuments.Add(request); DsmlResponseDocument dsmlResponseDocuments = this.SendRequestHelper(dsmlRequestDocuments.ToXml().InnerXml); if (dsmlResponseDocuments.Count != 0) { DirectoryResponse item = dsmlResponseDocuments[0]; if (item as DsmlErrorResponse == null) { ResultCode resultCode = item.ResultCode; if (resultCode == ResultCode.Success || resultCode == ResultCode.CompareFalse || resultCode == ResultCode.CompareTrue || resultCode == ResultCode.Referral || resultCode == ResultCode.ReferralV2) { return(item); } else { throw new DirectoryOperationException(item, OperationErrorMappings.MapResultCode((int)resultCode)); } } else { ErrorResponseException errorResponseException = new ErrorResponseException((DsmlErrorResponse)item); throw errorResponseException; } } else { throw new DsmlInvalidDocumentException(Res.GetString("MissingResponse")); } } else { throw new ArgumentNullException("request"); } }
public TlsOperationException (DirectoryResponse response, string message, Exception inner) : base (response, message, inner) { }
public int IndexOf (DirectoryResponse value) { return list.IndexOf (value); }
public DirectoryOperationException(DirectoryResponse response) : base(CreateMessage(response, message: null)) { Response = response; }
public int IndexOf(DirectoryResponse value) { return(list.IndexOf(value)); }
public DirectoryOperationException(DirectoryResponse response, string message) : this(message) { }
public DirectoryOperationException(DirectoryResponse response, string message) : base(message) { Response = response; }
public DirectoryOperationException (DirectoryResponse response, string message) : this (message) { }
public DirectoryOperationException (DirectoryResponse response) : this () { }
public TlsOperationException(DirectoryResponse response, string message) : this(response, message, null) { }
public TlsOperationException(DirectoryResponse response) : base(response) { }
public TlsOperationException(DirectoryResponse response) : base(response, default_message) { }
public bool Contains (DirectoryResponse value) { return list.Contains (value); }
public DirectoryOperationException(DirectoryResponse response, string message, Exception inner) : base(CreateMessage(response, message), inner) { Response = response; }
public void Insert(int index, DirectoryResponse value) { list.Insert(index, value); }
public void Remove(DirectoryResponse value) { list.Remove(value); }
public void CopyTo(DirectoryResponse[] value, int i) { _dsmlResponse.CopyTo(value, i); }
public void Remove (DirectoryResponse value) { list.Remove (value); }
public DirectoryOperationException(DirectoryResponse response) : base(SR.DefaultOperationsError) { Response = response; }
public void Insert (int index, DirectoryResponse value) { list.Insert (index, value); }
public DirectoryOperationException(DirectoryResponse response) : base(String.Format(CultureInfo.CurrentCulture, SR.DefaultOperationsError)) { this.response = response; }
public DirectoryOperationException(DirectoryResponse response) : this() { }
public DirectoryOperationException(DirectoryResponse response) : base(Res.GetString(Res.DefaultOperationsError)) { this.response = response; }
public DirectoryOperationException(DirectoryResponse response) : base(Res.GetString("DefaultOperationsError")) { this.response = response; }
public int Add (DirectoryResponse request) { return list.Add (request); }
public bool Contains(DirectoryResponse value) { return(list.Contains(value)); }
public TlsOperationException (DirectoryResponse response) : base (response, default_message) { }
public TlsOperationException(DirectoryResponse response, string message, Exception inner) : base(response, message, inner) { }
public TlsOperationException (DirectoryResponse response, string message) : this (response, message, null) { }
public DirectoryOperationException(DirectoryResponse response, string message, Exception inner) : base(message, inner) { this.response = response; }
public void CopyTo (DirectoryResponse [] value, int i) { list.CopyTo (value, i); }
public int Add(DirectoryResponse request) { return(list.Add(request)); }