コード例 #1
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);
            }
        }
コード例 #2
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
            {
                SearchResponse response = (SearchResponse)connection.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 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.
                Wldap32.ldap_abandon(connection._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);
            }
        }