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);
        }
Esempio n. 2
0
 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);
         }
     }
 }
Esempio n. 3
0
 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"));
     }
 }
Esempio n. 4
0
        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);
        }
Esempio n. 6
0
        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"));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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();
            }
        }
Esempio n. 9
0
        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);
                }
            }
        }
Esempio n. 10
0
        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));
                }
            }
        }
Esempio n. 11
0
 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");
     }
 }
Esempio n. 12
0
		public TlsOperationException (DirectoryResponse response, string message, Exception inner)
			: base (response, message, inner)
		{
		}
Esempio n. 13
0
		public int IndexOf (DirectoryResponse value)
		{
			return list.IndexOf (value);
		}
Esempio n. 14
0
 public DirectoryOperationException(DirectoryResponse response) :
     base(CreateMessage(response, message: null))
 {
     Response = response;
 }
Esempio n. 15
0
 public int IndexOf(DirectoryResponse value)
 {
     return(list.IndexOf(value));
 }
 public DirectoryOperationException(DirectoryResponse response, string message)
     : this(message)
 {
 }
Esempio n. 17
0
 public DirectoryOperationException(DirectoryResponse response, string message) : base(message)
 {
     Response = response;
 }
Esempio n. 18
0
		public DirectoryOperationException (DirectoryResponse response, string message)
			: this (message)
		{
		}
Esempio n. 19
0
		public DirectoryOperationException (DirectoryResponse response)
			: this ()
		{
		}
Esempio n. 20
0
 public TlsOperationException(DirectoryResponse response, string message)
     : this(response, message, null)
 {
 }
 public TlsOperationException(DirectoryResponse response) : base(response)
 {
 }
Esempio n. 22
0
 public TlsOperationException(DirectoryResponse response)
     : base(response, default_message)
 {
 }
Esempio n. 23
0
		public bool Contains (DirectoryResponse value)
		{
			return list.Contains (value);
		}
Esempio n. 24
0
 public DirectoryOperationException(DirectoryResponse response, string message, Exception inner)
     : base(CreateMessage(response, message), inner)
 {
     Response = response;
 }
Esempio n. 25
0
 public void Insert(int index, DirectoryResponse value)
 {
     list.Insert(index, value);
 }
Esempio n. 26
0
 public void Remove(DirectoryResponse value)
 {
     list.Remove(value);
 }
Esempio n. 27
0
 public void CopyTo(DirectoryResponse[] value, int i)
 {
     _dsmlResponse.CopyTo(value, i);
 }
Esempio n. 28
0
		public void Remove (DirectoryResponse value)
		{
			list.Remove (value);
		}
Esempio n. 29
0
 public DirectoryOperationException(DirectoryResponse response) : base(SR.DefaultOperationsError)
 {
     Response = response;
 }
Esempio n. 30
0
		public void Insert (int index, DirectoryResponse value)
		{
			list.Insert (index, value);
		}
Esempio n. 31
0
 public DirectoryOperationException(DirectoryResponse response) : base(String.Format(CultureInfo.CurrentCulture, SR.DefaultOperationsError))
 {
     this.response = response;
 }
Esempio n. 32
0
 public TlsOperationException(DirectoryResponse response) : base(response)
 {
 }
 public DirectoryOperationException(DirectoryResponse response)
     : this()
 {
 }
Esempio n. 34
0
 public DirectoryOperationException(DirectoryResponse response) : base(Res.GetString(Res.DefaultOperationsError))
 {
     this.response = response;
 }
Esempio n. 35
0
 public DirectoryOperationException(DirectoryResponse response) : base(Res.GetString("DefaultOperationsError"))
 {
     this.response = response;
 }
Esempio n. 36
0
		public int Add (DirectoryResponse request)
		{
			return list.Add (request);
		}
Esempio n. 37
0
 public bool Contains(DirectoryResponse value)
 {
     return(list.Contains(value));
 }
Esempio n. 38
0
		public TlsOperationException (DirectoryResponse response)
			: base (response, default_message)
		{
		}
Esempio n. 39
0
 public TlsOperationException(DirectoryResponse response, string message, Exception inner) : base(response, message, inner)
 {
 }
Esempio n. 40
0
		public TlsOperationException (DirectoryResponse response, string message)
			: this (response, message, null)
		{
		}
Esempio n. 41
0
 public DirectoryOperationException(DirectoryResponse response, string message, Exception inner) : base(message, inner)
 {
     this.response = response;
 }
Esempio n. 42
0
		public void CopyTo (DirectoryResponse [] value, int i)
		{
			list.CopyTo (value, i);
		}
Esempio n. 43
0
 public DirectoryOperationException(DirectoryResponse response, string message, Exception inner) : base(message, inner)
 {
     this.response = response;
 }
Esempio n. 44
0
 public int Add(DirectoryResponse request)
 {
     return(list.Add(request));
 }