public DirectoryResponse GetCompleteResult(LdapPartialAsyncResult asyncResult)
        {
            DirectoryResponse directoryResponse;

            lock (this)
            {
                if (this.resultList.Contains(asyncResult))
                {
                    this.resultList.Remove(asyncResult);
                    if (asyncResult.exception == null)
                    {
                        directoryResponse = asyncResult.response;
                    }
                    else
                    {
                        throw asyncResult.exception;
                    }
                }
                else
                {
                    throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
                }
            }
            return(directoryResponse);
        }
        public void RetrievingSearchResults()
        {
            int count = 0;
            int num2  = 0;
            LdapPartialAsyncResult asyncResult = null;
            AsyncCallback          callback    = null;

            lock (this)
            {
                count = this.resultList.Count;
                if (count == 0)
                {
                    this.workThreadWaitHandle.Reset();
                    this.workToDo = false;
                    return;
                }
Label_003D:
                if (this.currentIndex >= count)
                {
                    this.currentIndex = 0;
                }
                asyncResult = (LdapPartialAsyncResult)this.resultList[this.currentIndex];
                num2++;
                this.currentIndex++;
                if (asyncResult.resultStatus == ResultsStatus.Done)
                {
                    if (num2 >= count)
                    {
                        this.workToDo = false;
                        this.workThreadWaitHandle.Reset();
                        return;
                    }
                    goto Label_003D;
                }
                this.GetResultsHelper(asyncResult);
                if (asyncResult.resultStatus == ResultsStatus.Done)
                {
                    asyncResult.manualResetEvent.Set();
                    asyncResult.completed = true;
                    if (asyncResult.callback != null)
                    {
                        callback = asyncResult.callback;
                    }
                }
                else if ((((asyncResult.callback != null) && asyncResult.partialCallback) && (asyncResult.response != null)) && ((asyncResult.response.Entries.Count > 0) || (asyncResult.response.References.Count > 0)))
                {
                    callback = asyncResult.callback;
                }
            }
            if (callback != null)
            {
                callback(asyncResult);
            }
        }
 public void Remove(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.resultList.Contains(asyncResult))
         {
             throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
         }
         this.resultList.Remove(asyncResult);
     }
 }
Exemplo n.º 4
0
        public void Remove(LdapPartialAsyncResult asyncResult)
        {
            // called by Abort operation
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                    throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));

                // remove this async operation from the list
                _resultList.Remove(asyncResult);
            }
        }
 public void Add(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         this.resultList.Add(asyncResult);
         if (!this.workToDo)
         {
             this.workThreadWaitHandle.Set();
             this.workToDo = true;
         }
     }
 }
 public void Add(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         this.resultList.Add(asyncResult);
         if (!this.workToDo)
         {
             this.workThreadWaitHandle.Set();
             this.workToDo = true;
         }
     }
 }
 public void NeedCompleteResult(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.resultList.Contains(asyncResult))
         {
             throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
         }
         if (asyncResult.resultStatus == ResultsStatus.PartialResult)
         {
             asyncResult.resultStatus = ResultsStatus.CompleteResult;
         }
     }
 }
Exemplo n.º 8
0
        public void Remove(LdapPartialAsyncResult asyncResult)
        {
            // Called by Abort operation.
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                {
                    throw new ArgumentException(SR.InvalidAsyncResult);
                }

                // Remove this async operation from the list.
                _resultList.Remove(asyncResult);
            }
        }
Exemplo n.º 9
0
        public void Add(LdapPartialAsyncResult asyncResult)
        {
            lock (this)
            {
                _resultList.Add(asyncResult);

                if (!_workToDo)
                {
                    // need to wake up the workthread if it is not running already
                    _workThreadWaitHandle.Set();
                    _workToDo = true;
                }
            }
        }
Exemplo n.º 10
0
        public void Remove(LdapPartialAsyncResult asyncResult)
        {
            // called by Abort operation
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                {
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.InvalidAsyncResult));
                }

                // remove this async operation from the list
                _resultList.Remove(asyncResult);
            }
        }
Exemplo n.º 11
0
        public void Add(LdapPartialAsyncResult asyncResult)
        {
            lock (this)
            {
                _resultList.Add(asyncResult);

                if (!_workToDo)
                {
                    // Need to wake up the workthread if it is not running already.
                    _workThreadWaitHandle.Set();
                    _workToDo = true;
                }
            }
        }
        public void Remove(LdapPartialAsyncResult asyncResult)
        {
            // called by Abort operation
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                {
                    throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));
                }

                // remove this async operation from the list
                _resultList.Remove(asyncResult);
            }
        }
 public DirectoryResponse GetCompleteResult(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.resultList.Contains(asyncResult))
         {
             throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
         }
         this.resultList.Remove(asyncResult);
         if (asyncResult.exception != null)
         {
             throw asyncResult.exception;
         }
         return asyncResult.response;
     }
 }
Exemplo n.º 14
0
        public PartialResultsCollection GetPartialResults(LdapPartialAsyncResult asyncResult)
        {
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                {
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.InvalidAsyncResult));
                }

                if (asyncResult.exception != null)
                {
                    // remove this async operation

                    // the async operation basically failed, we won't do it any more, so throw exception to the user and remove it from the list
                    _resultList.Remove(asyncResult);
                    throw asyncResult.exception;
                }

                PartialResultsCollection collection = new PartialResultsCollection();

                if (asyncResult.response != null)
                {
                    if (asyncResult.response.Entries != null)
                    {
                        for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                        {
                            collection.Add(asyncResult.response.Entries[i]);
                        }

                        asyncResult.response.Entries.Clear();
                    }

                    if (asyncResult.response.References != null)
                    {
                        for (int i = 0; i < asyncResult.response.References.Count; i++)
                        {
                            collection.Add(asyncResult.response.References[i]);
                        }

                        asyncResult.response.References.Clear();
                    }
                }

                return(collection);
            }
        }
        public PartialResultsCollection GetPartialResults(LdapPartialAsyncResult asyncResult)
        {
            PartialResultsCollection partialResultsCollection;

            lock (this)
            {
                if (this.resultList.Contains(asyncResult))
                {
                    if (asyncResult.exception == null)
                    {
                        PartialResultsCollection partialResultsCollection1 = new PartialResultsCollection();
                        if (asyncResult.response != null)
                        {
                            if (asyncResult.response.Entries != null)
                            {
                                for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                                {
                                    partialResultsCollection1.Add(asyncResult.response.Entries[i]);
                                }
                                asyncResult.response.Entries.Clear();
                            }
                            if (asyncResult.response.References != null)
                            {
                                for (int j = 0; j < asyncResult.response.References.Count; j++)
                                {
                                    partialResultsCollection1.Add(asyncResult.response.References[j]);
                                }
                                asyncResult.response.References.Clear();
                            }
                        }
                        partialResultsCollection = partialResultsCollection1;
                    }
                    else
                    {
                        this.resultList.Remove(asyncResult);
                        throw asyncResult.exception;
                    }
                }
                else
                {
                    throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
                }
            }
            return(partialResultsCollection);
        }
Exemplo n.º 16
0
 public void NeedCompleteResult(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (_resultList.Contains(asyncResult))
         {
             // we don't need partial results anymore, polling for complete results
             if (asyncResult.resultStatus == ResultsStatus.PartialResult)
             {
                 asyncResult.resultStatus = ResultsStatus.CompleteResult;
             }
         }
         else
         {
             throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, SR.InvalidAsyncResult));
         }
     }
 }
Exemplo n.º 17
0
 public void NeedCompleteResult(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (_resultList.Contains(asyncResult))
         {
             // We don't need partial results anymore, polling for complete results.
             if (asyncResult._resultStatus == ResultsStatus.PartialResult)
             {
                 asyncResult._resultStatus = ResultsStatus.CompleteResult;
             }
         }
         else
         {
             throw new ArgumentException(SR.InvalidAsyncResult);
         }
     }
 }
Exemplo n.º 18
0
        public DirectoryResponse GetCompleteResult(LdapPartialAsyncResult asyncResult)
        {
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                {
                    throw new ArgumentException(SR.InvalidAsyncResult);
                }

                Debug.Assert(asyncResult._resultStatus == ResultsStatus.Done);

                _resultList.Remove(asyncResult);

                if (asyncResult._exception != null)
                {
                    throw asyncResult._exception;
                }
                else
                {
                    return(asyncResult._response);
                }
            }
        }
 public PartialResultsCollection GetPartialResults(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.resultList.Contains(asyncResult))
         {
             throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
         }
         if (asyncResult.exception != null)
         {
             this.resultList.Remove(asyncResult);
             throw asyncResult.exception;
         }
         PartialResultsCollection resultss = new PartialResultsCollection();
         if (asyncResult.response != null)
         {
             if (asyncResult.response.Entries != null)
             {
                 for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                 {
                     resultss.Add(asyncResult.response.Entries[i]);
                 }
                 asyncResult.response.Entries.Clear();
             }
             if (asyncResult.response.References != null)
             {
                 for (int j = 0; j < asyncResult.response.References.Count; j++)
                 {
                     resultss.Add(asyncResult.response.References[j]);
                 }
                 asyncResult.response.References.Clear();
             }
         }
         return resultss;
     }
 }
Exemplo n.º 20
0
 public void NeedCompleteResult(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (_resultList.Contains(asyncResult))
         {
             // we don't need partial results anymore, polling for complete results
             if (asyncResult.resultStatus == ResultsStatus.PartialResult)
                 asyncResult.resultStatus = ResultsStatus.CompleteResult;
         }
         else
             throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));
     }
 }
Exemplo n.º 21
0
        private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
        {
            LdapConnection con = asyncResult.con;
            IntPtr ldapResult = (IntPtr)0;
            IntPtr entryMessage = (IntPtr)0;
            ResultAll resultType = ResultAll.LDAP_MSG_RECEIVED;

            if (asyncResult.resultStatus == ResultsStatus.CompleteResult)
                resultType = ResultAll.LDAP_MSG_POLLINGALL;

            try
            {
                SearchResponse response = (SearchResponse)con.ConstructResponse(asyncResult.messageID, LdapOperation.LdapSearch, resultType, asyncResult.requestTimeout, false);
                // this should only happen in the polling thread case                    
                if (response == null)
                {
                    // only when request time out has not yet expiered
                    if ((asyncResult.startTime.Ticks + asyncResult.requestTimeout.Ticks) > DateTime.Now.Ticks)
                    {
                        // this is expected, just the client does not have the result yet 
                        return;
                    }
                    else
                    {
                        // time out, now we need to throw proper exception                   
                        throw new LdapException((int)LdapError.TimeOut, LdapErrorMappings.MapResultCode((int)LdapError.TimeOut));
                    }
                }

                if (asyncResult.response != null)
                    AddResult(asyncResult.response, response);
                else
                    asyncResult.response = response;

                // if search is done, set the flag
                if (response.searchDone)
                    asyncResult.resultStatus = ResultsStatus.Done;
            }
            catch (Exception e)
            {
                if (e is DirectoryOperationException)
                {
                    SearchResponse response = (SearchResponse)(((DirectoryOperationException)e).Response);

                    if (asyncResult.response != null)
                        AddResult(asyncResult.response, response);
                    else
                        asyncResult.response = response;

                    // set the response back to the exception so it holds all the results up to now
                    ((DirectoryOperationException)e).response = asyncResult.response;
                }
                else if (e is LdapException)
                {
                    LdapException ldapE = (LdapException)e;
                    LdapError errorCode = (LdapError)ldapE.ErrorCode;

                    if (asyncResult.response != null)
                    {
                        // add previous retrieved entries if available
                        if (asyncResult.response.Entries != null)
                        {
                            for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                            {
                                ldapE.results.Add(asyncResult.response.Entries[i]);
                            }
                        }

                        // add previous retrieved references if available
                        if (asyncResult.response.References != null)
                        {
                            for (int i = 0; i < asyncResult.response.References.Count; i++)
                            {
                                ldapE.results.Add(asyncResult.response.References[i]);
                            }
                        }
                    }
                }

                // exception occurs, this operation is done.
                asyncResult.exception = e;
                asyncResult.resultStatus = ResultsStatus.Done;

                // need to abandon this request
                Wldap32.ldap_abandon(con.ldapHandle, asyncResult.messageID);
            }
        }
Exemplo n.º 22
0
        public IAsyncResult BeginSendRequest(DirectoryRequest request, TimeSpan requestTimeout, PartialResultProcessing partialMode, AsyncCallback callback, object state)
        {
            int messageID = 0;
            int error = 0;

            if (this.disposed)
                throw new ObjectDisposedException(GetType().Name);

            // parameter validation
            if (request == null)
                throw new ArgumentNullException("request");

            if (partialMode < PartialResultProcessing.NoPartialResultSupport || partialMode > PartialResultProcessing.ReturnPartialResultsAndNotifyCallback)
                throw new InvalidEnumArgumentException("partialMode", (int)partialMode, typeof(PartialResultProcessing));

            if (partialMode != PartialResultProcessing.NoPartialResultSupport && !(request is SearchRequest))
                throw new NotSupportedException(Res.GetString(Res.PartialResultsNotSupported));

            if (partialMode == PartialResultProcessing.ReturnPartialResultsAndNotifyCallback && (callback == null))
                throw new ArgumentException(Res.GetString(Res.CallBackIsNull), "callback");

            error = SendRequestHelper(request, ref messageID);

            LdapOperation operation = LdapOperation.LdapSearch;
            if (request is DeleteRequest)
                operation = LdapOperation.LdapDelete;
            else if (request is AddRequest)
                operation = LdapOperation.LdapAdd;
            else if (request is ModifyRequest)
                operation = LdapOperation.LdapModify;
            else if (request is SearchRequest)
                operation = LdapOperation.LdapSearch;
            else if (request is ModifyDNRequest)
                operation = LdapOperation.LdapModifyDn;
            else if (request is CompareRequest)
                operation = LdapOperation.LdapCompare;
            else if (request is ExtendedRequest)
                operation = LdapOperation.LdapExtendedRequest;

            if (error == 0 && messageID != -1)
            {
                if (partialMode == PartialResultProcessing.NoPartialResultSupport)
                {
                    LdapRequestState rs = new LdapRequestState();
                    LdapAsyncResult asyncResult = new LdapAsyncResult(callback, state, false);

                    rs.ldapAsync = asyncResult;
                    asyncResult.resultObject = rs;

                    s_asyncResultTable.Add(asyncResult, messageID);

                    _fd.BeginInvoke(messageID, operation, ResultAll.LDAP_MSG_ALL, requestTimeout, true, new AsyncCallback(ResponseCallback), rs);

                    return (IAsyncResult)asyncResult;
                }
                else
                {
                    // the user registers to retrieve partial results
                    bool partialCallback = false;
                    if (partialMode == PartialResultProcessing.ReturnPartialResultsAndNotifyCallback)
                        partialCallback = true;
                    LdapPartialAsyncResult asyncResult = new LdapPartialAsyncResult(messageID, callback, state, true, this, partialCallback, requestTimeout);
                    s_partialResultsProcessor.Add(asyncResult);

                    return (IAsyncResult)asyncResult;
                }
            }
            else
            {
                if (error == 0)
                {
                    // success code but message is -1, unexpected
                    error = Wldap32.LdapGetLastError();
                }

                throw ConstructException(error, operation);
            }
        }
Exemplo n.º 23
0
        private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
        {
            LdapConnection connection = asyncResult._con;
            ResultAll      resultType = ResultAll.LDAP_MSG_RECEIVED;

            if (asyncResult._resultStatus == ResultsStatus.CompleteResult)
            {
                resultType = ResultAll.LDAP_MSG_POLLINGALL;
            }

            try
            {
                ValueTask <DirectoryResponse> vt = connection.ConstructResponseAsync(asyncResult._messageID, LdapOperation.LdapSearch, resultType, asyncResult._requestTimeout, false, sync: true);
                Debug.Assert(vt.IsCompleted);
                SearchResponse response = (SearchResponse)vt.GetAwaiter().GetResult();

                // This should only happen in the polling thread case.
                if (response == null)
                {
                    // Only when request time out has not yet expiered.
                    if ((asyncResult._startTime.Ticks + asyncResult._requestTimeout.Ticks) > DateTime.Now.Ticks)
                    {
                        // This is expected, just the client does not have the result yet .
                        return;
                    }
                    else
                    {
                        // time out, now we need to throw proper exception
                        throw new LdapException((int)LdapError.TimeOut, LdapErrorMappings.MapResultCode((int)LdapError.TimeOut));
                    }
                }

                if (asyncResult._response != null)
                {
                    AddResult(asyncResult._response, response);
                }
                else
                {
                    asyncResult._response = response;
                }

                // If search is done, set the flag.
                if (response.searchDone)
                {
                    asyncResult._resultStatus = ResultsStatus.Done;
                }
            }
            catch (Exception exception)
            {
                if (exception is DirectoryOperationException directoryOperationException)
                {
                    SearchResponse response = (SearchResponse)directoryOperationException.Response;
                    if (asyncResult._response != null)
                    {
                        AddResult(asyncResult._response, response);
                    }
                    else
                    {
                        asyncResult._response = response;
                    }

                    // Set the response back to the exception so it holds all the results up to now.
                    directoryOperationException.Response = asyncResult._response;
                }
                else if (exception is LdapException ldapException)
                {
                    if (asyncResult._response != null)
                    {
                        // add previous retrieved entries if available
                        if (asyncResult._response.Entries != null)
                        {
                            for (int i = 0; i < asyncResult._response.Entries.Count; i++)
                            {
                                ldapException.PartialResults.Add(asyncResult._response.Entries[i]);
                            }
                        }

                        // add previous retrieved references if available
                        if (asyncResult._response.References != null)
                        {
                            for (int i = 0; i < asyncResult._response.References.Count; i++)
                            {
                                ldapException.PartialResults.Add(asyncResult._response.References[i]);
                            }
                        }
                    }
                }

                // Exception occurs, this operation is done.
                asyncResult._exception    = exception;
                asyncResult._resultStatus = ResultsStatus.Done;

                // Need to abandon this request.
                LdapPal.CancelDirectoryAsyncOperation(connection._ldapHandle, asyncResult._messageID);
            }
        }
Exemplo n.º 24
0
        public DirectoryResponse GetCompleteResult(LdapPartialAsyncResult asyncResult)
        {
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                    throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));

                Debug.Assert(asyncResult.resultStatus == ResultsStatus.Done);

                _resultList.Remove(asyncResult);

                if (asyncResult.exception != null)
                {
                    throw asyncResult.exception;
                }
                else
                {
                    return asyncResult.response;
                }
            }
        }
Exemplo n.º 25
0
        public PartialResultsCollection GetPartialResults(LdapPartialAsyncResult asyncResult)
        {
            lock (this)
            {
                if (!_resultList.Contains(asyncResult))
                    throw new ArgumentException(Res.GetString(Res.InvalidAsyncResult));

                if (asyncResult.exception != null)
                {
                    // remove this async operation

                    // the async operation basically failed, we won't do it any more, so throw exception to the user and remove it from the list
                    _resultList.Remove(asyncResult);
                    throw asyncResult.exception;
                }

                PartialResultsCollection collection = new PartialResultsCollection();

                if (asyncResult.response != null)
                {
                    if (asyncResult.response.Entries != null)
                    {
                        for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                            collection.Add(asyncResult.response.Entries[i]);

                        asyncResult.response.Entries.Clear();
                    }

                    if (asyncResult.response.References != null)
                    {
                        for (int i = 0; i < asyncResult.response.References.Count; i++)
                            collection.Add(asyncResult.response.References[i]);

                        asyncResult.response.References.Clear();
                    }
                }

                return collection;
            }
        }
Exemplo n.º 26
0
        private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
        {
            LdapConnection con          = asyncResult.con;
            IntPtr         ldapResult   = (IntPtr)0;
            IntPtr         entryMessage = (IntPtr)0;
            ResultAll      resultType   = ResultAll.LDAP_MSG_RECEIVED;

            if (asyncResult.resultStatus == ResultsStatus.CompleteResult)
            {
                resultType = ResultAll.LDAP_MSG_POLLINGALL;
            }

            try
            {
                SearchResponse response = (SearchResponse)con.ConstructResponse(asyncResult.messageID, LdapOperation.LdapSearch, resultType, asyncResult.requestTimeout, false);
                // this should only happen in the polling thread case
                if (response == null)
                {
                    // only when request time out has not yet expiered
                    if ((asyncResult.startTime.Ticks + asyncResult.requestTimeout.Ticks) > DateTime.Now.Ticks)
                    {
                        // this is expected, just the client does not have the result yet
                        return;
                    }
                    else
                    {
                        // time out, now we need to throw proper exception
                        throw new LdapException((int)LdapError.TimeOut, LdapErrorMappings.MapResultCode((int)LdapError.TimeOut));
                    }
                }

                if (asyncResult.response != null)
                {
                    AddResult(asyncResult.response, response);
                }
                else
                {
                    asyncResult.response = response;
                }

                // if search is done, set the flag
                if (response.searchDone)
                {
                    asyncResult.resultStatus = ResultsStatus.Done;
                }
            }
            catch (Exception e)
            {
                if (e is DirectoryOperationException)
                {
                    SearchResponse response = (SearchResponse)(((DirectoryOperationException)e).Response);

                    if (asyncResult.response != null)
                    {
                        AddResult(asyncResult.response, response);
                    }
                    else
                    {
                        asyncResult.response = response;
                    }

                    // set the response back to the exception so it holds all the results up to now
                    ((DirectoryOperationException)e).Response = asyncResult.response;
                }
                else if (e is LdapException)
                {
                    LdapException ldapE     = (LdapException)e;
                    LdapError     errorCode = (LdapError)ldapE.ErrorCode;

                    if (asyncResult.response != null)
                    {
                        // add previous retrieved entries if available
                        if (asyncResult.response.Entries != null)
                        {
                            for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                            {
                                ldapE.results.Add(asyncResult.response.Entries[i]);
                            }
                        }

                        // add previous retrieved references if available
                        if (asyncResult.response.References != null)
                        {
                            for (int i = 0; i < asyncResult.response.References.Count; i++)
                            {
                                ldapE.results.Add(asyncResult.response.References[i]);
                            }
                        }
                    }
                }

                // exception occurs, this operation is done.
                asyncResult.exception    = e;
                asyncResult.resultStatus = ResultsStatus.Done;

                // need to abandon this request
                Wldap32.ldap_abandon(con.ldapHandle, asyncResult.messageID);
            }
        }
        private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
        {
            LdapConnection con        = asyncResult.con;
            IntPtr         ldapHandle = con.ldapHandle;
            ResultAll      resultType = ResultAll.LDAP_MSG_RECEIVED;

            if (asyncResult.resultStatus == ResultsStatus.CompleteResult)
            {
                resultType = ResultAll.LDAP_MSG_POLLINGALL;
            }
            try
            {
                SearchResponse newResult = (SearchResponse)con.ConstructResponse(asyncResult.messageID, LdapOperation.LdapSearch, resultType, asyncResult.requestTimeout, false);
                if (newResult == null)
                {
                    if ((asyncResult.startTime.Ticks + asyncResult.requestTimeout.Ticks) <= DateTime.Now.Ticks)
                    {
                        throw new LdapException(0x55, LdapErrorMappings.MapResultCode(0x55));
                    }
                }
                else
                {
                    if (asyncResult.response != null)
                    {
                        this.AddResult(asyncResult.response, newResult);
                    }
                    else
                    {
                        asyncResult.response = newResult;
                    }
                    if (newResult.searchDone)
                    {
                        asyncResult.resultStatus = ResultsStatus.Done;
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception is DirectoryOperationException)
                {
                    SearchResponse response = (SearchResponse)((DirectoryOperationException)exception).Response;
                    if (asyncResult.response != null)
                    {
                        this.AddResult(asyncResult.response, response);
                    }
                    else
                    {
                        asyncResult.response = response;
                    }
                    ((DirectoryOperationException)exception).response = asyncResult.response;
                }
                else if (exception is LdapException)
                {
                    LdapException exception2 = (LdapException)exception;
                    int           errorCode  = exception2.ErrorCode;
                    if (asyncResult.response != null)
                    {
                        if (asyncResult.response.Entries != null)
                        {
                            for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                            {
                                exception2.results.Add(asyncResult.response.Entries[i]);
                            }
                        }
                        if (asyncResult.response.References != null)
                        {
                            for (int j = 0; j < asyncResult.response.References.Count; j++)
                            {
                                exception2.results.Add(asyncResult.response.References[j]);
                            }
                        }
                    }
                }
                asyncResult.exception    = exception;
                asyncResult.resultStatus = ResultsStatus.Done;
                Wldap32.ldap_abandon(con.ldapHandle, asyncResult.messageID);
            }
        }
 private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
 {
     LdapConnection con = asyncResult.con;
     IntPtr ldapHandle = con.ldapHandle;
     ResultAll resultType = ResultAll.LDAP_MSG_RECEIVED;
     if (asyncResult.resultStatus == ResultsStatus.CompleteResult)
     {
         resultType = ResultAll.LDAP_MSG_POLLINGALL;
     }
     try
     {
         SearchResponse newResult = (SearchResponse) con.ConstructResponse(asyncResult.messageID, LdapOperation.LdapSearch, resultType, asyncResult.requestTimeout, false);
         if (newResult == null)
         {
             if ((asyncResult.startTime.Ticks + asyncResult.requestTimeout.Ticks) <= DateTime.Now.Ticks)
             {
                 throw new LdapException(0x55, LdapErrorMappings.MapResultCode(0x55));
             }
         }
         else
         {
             if (asyncResult.response != null)
             {
                 this.AddResult(asyncResult.response, newResult);
             }
             else
             {
                 asyncResult.response = newResult;
             }
             if (newResult.searchDone)
             {
                 asyncResult.resultStatus = ResultsStatus.Done;
             }
         }
     }
     catch (Exception exception)
     {
         if (exception is DirectoryOperationException)
         {
             SearchResponse response = (SearchResponse) ((DirectoryOperationException) exception).Response;
             if (asyncResult.response != null)
             {
                 this.AddResult(asyncResult.response, response);
             }
             else
             {
                 asyncResult.response = response;
             }
             ((DirectoryOperationException) exception).response = asyncResult.response;
         }
         else if (exception is LdapException)
         {
             LdapException exception2 = (LdapException) exception;
             int errorCode = exception2.ErrorCode;
             if (asyncResult.response != null)
             {
                 if (asyncResult.response.Entries != null)
                 {
                     for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                     {
                         exception2.results.Add(asyncResult.response.Entries[i]);
                     }
                 }
                 if (asyncResult.response.References != null)
                 {
                     for (int j = 0; j < asyncResult.response.References.Count; j++)
                     {
                         exception2.results.Add(asyncResult.response.References[j]);
                     }
                 }
             }
         }
         asyncResult.exception = exception;
         asyncResult.resultStatus = ResultsStatus.Done;
         Wldap32.ldap_abandon(con.ldapHandle, asyncResult.messageID);
     }
 }
Exemplo n.º 29
0
		public IAsyncResult BeginSendRequest(DirectoryRequest request, TimeSpan requestTimeout, PartialResultProcessing partialMode, AsyncCallback callback, object state)
		{
			int num = 0;
			if (!this.disposed)
			{
				if (request != null)
				{
					if (partialMode < PartialResultProcessing.NoPartialResultSupport || partialMode > PartialResultProcessing.ReturnPartialResultsAndNotifyCallback)
					{
						throw new InvalidEnumArgumentException("partialMode", (int)partialMode, typeof(PartialResultProcessing));
					}
					else
					{
						if (partialMode == PartialResultProcessing.NoPartialResultSupport || request as SearchRequest != null)
						{
							if (partialMode != PartialResultProcessing.ReturnPartialResultsAndNotifyCallback || callback != null)
							{
								int num1 = this.SendRequestHelper(request, ref num);
								LdapOperation ldapOperation = LdapOperation.LdapSearch;
								if (request as DeleteRequest == null)
								{
									if (request as AddRequest == null)
									{
										if (request as ModifyRequest == null)
										{
											if (request as SearchRequest == null)
											{
												if (request as ModifyDNRequest == null)
												{
													if (request as CompareRequest == null)
													{
														if (request as ExtendedRequest != null)
														{
															ldapOperation = LdapOperation.LdapExtendedRequest;
														}
													}
													else
													{
														ldapOperation = LdapOperation.LdapCompare;
													}
												}
												else
												{
													ldapOperation = LdapOperation.LdapModifyDn;
												}
											}
											else
											{
												ldapOperation = LdapOperation.LdapSearch;
											}
										}
										else
										{
											ldapOperation = LdapOperation.LdapModify;
										}
									}
									else
									{
										ldapOperation = LdapOperation.LdapAdd;
									}
								}
								else
								{
									ldapOperation = LdapOperation.LdapDelete;
								}
								if (num1 != 0 || num == -1)
								{
									if (num1 == 0)
									{
										num1 = Wldap32.LdapGetLastError();
									}
									throw this.ConstructException(num1, ldapOperation);
								}
								else
								{
									if (partialMode != PartialResultProcessing.NoPartialResultSupport)
									{
										bool flag = false;
										if (partialMode == PartialResultProcessing.ReturnPartialResultsAndNotifyCallback)
										{
											flag = true;
										}
										LdapPartialAsyncResult ldapPartialAsyncResult = new LdapPartialAsyncResult(num, callback, state, true, this, flag, requestTimeout);
										LdapConnection.partialResultsProcessor.Add(ldapPartialAsyncResult);
										return ldapPartialAsyncResult;
									}
									else
									{
										LdapRequestState ldapRequestState = new LdapRequestState();
										LdapAsyncResult ldapAsyncResult = new LdapAsyncResult(callback, state, false);
										ldapRequestState.ldapAsync = ldapAsyncResult;
										ldapAsyncResult.resultObject = ldapRequestState;
										LdapConnection.asyncResultTable.Add(ldapAsyncResult, num);
										this.fd.BeginInvoke(num, ldapOperation, ResultAll.LDAP_MSG_ALL, requestTimeout, true, new AsyncCallback(this.ResponseCallback), ldapRequestState);
										return ldapAsyncResult;
									}
								}
							}
							else
							{
								throw new ArgumentException(Res.GetString("CallBackIsNull"), "callback");
							}
						}
						else
						{
							throw new NotSupportedException(Res.GetString("PartialResultsNotSupported"));
						}
					}
				}
				else
				{
					throw new ArgumentNullException("request");
				}
			}
			else
			{
				throw new ObjectDisposedException(base.GetType().Name);
			}
		}
        public void RetrievingSearchResults()
        {
            int num = 0;
            LdapPartialAsyncResult item          = null;
            AsyncCallback          asyncCallback = null;

            lock (this)
            {
                int count = this.resultList.Count;
                if (count != 0)
                {
                    do
                    {
                        if (this.currentIndex >= count)
                        {
                            this.currentIndex = 0;
                        }
                        item = (LdapPartialAsyncResult)this.resultList[this.currentIndex];
                        num++;
                        LdapPartialResultsProcessor ldapPartialResultsProcessor = this;
                        ldapPartialResultsProcessor.currentIndex = ldapPartialResultsProcessor.currentIndex + 1;
                        if (item.resultStatus == ResultsStatus.Done)
                        {
                            continue;
                        }
                        this.GetResultsHelper(item);
                        if (item.resultStatus != ResultsStatus.Done)
                        {
                            if (item.callback != null && item.partialCallback && item.response != null && (item.response.Entries.Count > 0 || item.response.References.Count > 0))
                            {
                                asyncCallback = item.callback;
                            }
                        }
                        else
                        {
                            item.manualResetEvent.Set();
                            item.completed = true;
                            if (item.callback != null)
                            {
                                asyncCallback = item.callback;
                            }
                        }
                        if (asyncCallback != null)
                        {
                            asyncCallback(item);
                        }
                        return;
                    }while (num < count);
                    this.workToDo = false;
                    this.workThreadWaitHandle.Reset();
                    return;
                }
                else
                {
                    this.workThreadWaitHandle.Reset();
                    this.workToDo = false;
                    return;
                }
            }
            if (asyncCallback != null)
            {
                asyncCallback(item);
            }
        }
 public void NeedCompleteResult(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.resultList.Contains(asyncResult))
         {
             throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
         }
         if (asyncResult.resultStatus == ResultsStatus.PartialResult)
         {
             asyncResult.resultStatus = ResultsStatus.CompleteResult;
         }
     }
 }
        private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
        {
            LdapConnection ldapConnection = asyncResult.con;
            ResultAll      resultAll      = ResultAll.LDAP_MSG_RECEIVED;

            if (asyncResult.resultStatus == ResultsStatus.CompleteResult)
            {
                resultAll = ResultAll.LDAP_MSG_POLLINGALL;
            }
            try
            {
                SearchResponse searchResponse = (SearchResponse)ldapConnection.ConstructResponse(asyncResult.messageID, LdapOperation.LdapSearch, resultAll, asyncResult.requestTimeout, false);
                if (searchResponse != null)
                {
                    if (asyncResult.response == null)
                    {
                        asyncResult.response = searchResponse;
                    }
                    else
                    {
                        this.AddResult(asyncResult.response, searchResponse);
                    }
                    if (searchResponse.searchDone)
                    {
                        asyncResult.resultStatus = ResultsStatus.Done;
                    }
                }
                else
                {
                    DateTime now = DateTime.Now;
                    if (asyncResult.startTime.Ticks + asyncResult.requestTimeout.Ticks <= now.Ticks)
                    {
                        throw new LdapException(85, LdapErrorMappings.MapResultCode(85));
                    }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (exception as DirectoryOperationException == null)
                {
                    if (exception as LdapException != null)
                    {
                        LdapException ldapException = (LdapException)exception;
                        //TODO: Review: ldapException.ErrorCode;
                        if (asyncResult.response != null)
                        {
                            if (asyncResult.response.Entries != null)
                            {
                                for (int i = 0; i < asyncResult.response.Entries.Count; i++)
                                {
                                    ldapException.results.Add(asyncResult.response.Entries[i]);
                                }
                            }
                            if (asyncResult.response.References != null)
                            {
                                for (int j = 0; j < asyncResult.response.References.Count; j++)
                                {
                                    ldapException.results.Add(asyncResult.response.References[j]);
                                }
                            }
                        }
                    }
                }
                else
                {
                    SearchResponse response = (SearchResponse)((DirectoryOperationException)exception).Response;
                    if (asyncResult.response == null)
                    {
                        asyncResult.response = response;
                    }
                    else
                    {
                        this.AddResult(asyncResult.response, response);
                    }
                    ((DirectoryOperationException)exception).response = asyncResult.response;
                }
                asyncResult.exception    = exception;
                asyncResult.resultStatus = ResultsStatus.Done;
                Wldap32.ldap_abandon(ldapConnection.ldapHandle, asyncResult.messageID);
            }
        }
 public void Remove(LdapPartialAsyncResult asyncResult)
 {
     lock (this)
     {
         if (!this.resultList.Contains(asyncResult))
         {
             throw new ArgumentException(Res.GetString("InvalidAsyncResult"));
         }
         this.resultList.Remove(asyncResult);
     }
 }
 public IAsyncResult BeginSendRequest(DirectoryRequest request, TimeSpan requestTimeout, PartialResultProcessing partialMode, AsyncCallback callback, object state)
 {
     int messageID = 0;
     int error = 0;
     if (this.disposed)
     {
         throw new ObjectDisposedException(base.GetType().Name);
     }
     if (request == null)
     {
         throw new ArgumentNullException("request");
     }
     if ((partialMode < PartialResultProcessing.NoPartialResultSupport) || (partialMode > PartialResultProcessing.ReturnPartialResultsAndNotifyCallback))
     {
         throw new InvalidEnumArgumentException("partialMode", (int) partialMode, typeof(PartialResultProcessing));
     }
     if ((partialMode != PartialResultProcessing.NoPartialResultSupport) && !(request is SearchRequest))
     {
         throw new NotSupportedException(System.DirectoryServices.Protocols.Res.GetString("PartialResultsNotSupported"));
     }
     if ((partialMode == PartialResultProcessing.ReturnPartialResultsAndNotifyCallback) && (callback == null))
     {
         throw new ArgumentException(System.DirectoryServices.Protocols.Res.GetString("CallBackIsNull"), "callback");
     }
     error = this.SendRequestHelper(request, ref messageID);
     LdapOperation ldapSearch = LdapOperation.LdapSearch;
     if (request is DeleteRequest)
     {
         ldapSearch = LdapOperation.LdapDelete;
     }
     else if (request is AddRequest)
     {
         ldapSearch = LdapOperation.LdapAdd;
     }
     else if (request is ModifyRequest)
     {
         ldapSearch = LdapOperation.LdapModify;
     }
     else if (request is SearchRequest)
     {
         ldapSearch = LdapOperation.LdapSearch;
     }
     else if (request is ModifyDNRequest)
     {
         ldapSearch = LdapOperation.LdapModifyDn;
     }
     else if (request is CompareRequest)
     {
         ldapSearch = LdapOperation.LdapCompare;
     }
     else if (request is ExtendedRequest)
     {
         ldapSearch = LdapOperation.LdapExtendedRequest;
     }
     if ((error == 0) && (messageID != -1))
     {
         if (partialMode == PartialResultProcessing.NoPartialResultSupport)
         {
             LdapRequestState state2 = new LdapRequestState();
             LdapAsyncResult key = new LdapAsyncResult(callback, state, false);
             state2.ldapAsync = key;
             key.resultObject = state2;
             asyncResultTable.Add(key, messageID);
             this.fd.BeginInvoke(messageID, ldapSearch, ResultAll.LDAP_MSG_ALL, requestTimeout, true, new AsyncCallback(this.ResponseCallback), state2);
             return key;
         }
         bool partialCallback = false;
         if (partialMode == PartialResultProcessing.ReturnPartialResultsAndNotifyCallback)
         {
             partialCallback = true;
         }
         LdapPartialAsyncResult asyncResult = new LdapPartialAsyncResult(messageID, callback, state, true, this, partialCallback, requestTimeout);
         partialResultsProcessor.Add(asyncResult);
         return asyncResult;
     }
     if (error == 0)
     {
         error = Wldap32.LdapGetLastError();
     }
     throw this.ConstructException(error, ldapSearch);
 }
Exemplo n.º 35
0
        public void RetrievingSearchResults()
        {
            LdapPartialAsyncResult asyncResult = null;
            AsyncCallback          tmpCallback = null;

            lock (this)
            {
                int count = _resultList.Count;

                if (count == 0)
                {
                    // No asynchronous operation pending, begin to wait.
                    _workThreadWaitHandle.Reset();
                    _workToDo = false;
                    return;
                }

                // Might have work to do.
                int i = 0;
                while (true)
                {
                    if (_currentIndex >= count)
                    {
                        // Some element is moved after last iteration.
                        _currentIndex = 0;
                    }

                    asyncResult = (LdapPartialAsyncResult)_resultList[_currentIndex];
                    i++;
                    _currentIndex++;

                    // Have work to do.
                    if (asyncResult._resultStatus != ResultsStatus.Done)
                    {
                        break;
                    }

                    if (i >= count)
                    {
                        // All the operations are done just waiting for the user to pick up the results.
                        _workToDo = false;
                        _workThreadWaitHandle.Reset();
                        return;
                    }
                }

                // Try to get the results available for this asynchronous operation  .
                GetResultsHelper(asyncResult);

                // If we are done with the asynchronous search, we need to fire callback and signal the waitable object.
                if (asyncResult._resultStatus == ResultsStatus.Done)
                {
                    asyncResult._manualResetEvent.Set();
                    asyncResult._completed = true;
                    if (asyncResult._callback != null)
                    {
                        tmpCallback = asyncResult._callback;
                    }
                }
                else if (asyncResult._callback != null && asyncResult._partialCallback)
                {
                    // The user specified a callback to be called even when partial results become available.
                    if (asyncResult._response != null && (asyncResult._response.Entries.Count > 0 || asyncResult._response.References.Count > 0))
                    {
                        tmpCallback = asyncResult._callback;
                    }
                }
            }

            tmpCallback?.Invoke(asyncResult);
        }
Exemplo n.º 36
0
		private void GetResultsHelper(LdapPartialAsyncResult asyncResult)
		{
			LdapConnection ldapConnection = asyncResult.con;
			ResultAll resultAll = ResultAll.LDAP_MSG_RECEIVED;
			if (asyncResult.resultStatus == ResultsStatus.CompleteResult)
			{
				resultAll = ResultAll.LDAP_MSG_POLLINGALL;
			}
			try
			{
				SearchResponse searchResponse = (SearchResponse)ldapConnection.ConstructResponse(asyncResult.messageID, LdapOperation.LdapSearch, resultAll, asyncResult.requestTimeout, false);
				if (searchResponse != null)
				{
					if (asyncResult.response == null)
					{
						asyncResult.response = searchResponse;
					}
					else
					{
						this.AddResult(asyncResult.response, searchResponse);
					}
					if (searchResponse.searchDone)
					{
						asyncResult.resultStatus = ResultsStatus.Done;
					}
				}
				else
				{
					DateTime now = DateTime.Now;
					if (asyncResult.startTime.Ticks + asyncResult.requestTimeout.Ticks <= now.Ticks)
					{
						throw new LdapException(85, LdapErrorMappings.MapResultCode(85));
					}
				}
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				if (exception as DirectoryOperationException == null)
				{
					if (exception as LdapException != null)
					{
						LdapException ldapException = (LdapException)exception;
						//TODO: Review: ldapException.ErrorCode;
						if (asyncResult.response != null)
						{
							if (asyncResult.response.Entries != null)
							{
								for (int i = 0; i < asyncResult.response.Entries.Count; i++)
								{
									ldapException.results.Add(asyncResult.response.Entries[i]);
								}
							}
							if (asyncResult.response.References != null)
							{
								for (int j = 0; j < asyncResult.response.References.Count; j++)
								{
									ldapException.results.Add(asyncResult.response.References[j]);
								}
							}
						}
					}
				}
				else
				{
					SearchResponse response = (SearchResponse)((DirectoryOperationException)exception).Response;
					if (asyncResult.response == null)
					{
						asyncResult.response = response;
					}
					else
					{
						this.AddResult(asyncResult.response, response);
					}
					((DirectoryOperationException)exception).response = asyncResult.response;
				}
				asyncResult.exception = exception;
				asyncResult.resultStatus = ResultsStatus.Done;
				Wldap32.ldap_abandon(ldapConnection.ldapHandle, asyncResult.messageID);
			}
		}