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); } }
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); } }
internal DirectoryResponse ConstructResponse(int messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, bool exceptionOnTimeOut) { int error; LDAP_TIMEVAL timeout = new LDAP_TIMEVAL(); timeout.tv_sec = (int)(requestTimeOut.Ticks / TimeSpan.TicksPerSecond); IntPtr ldapResult = (IntPtr)0; DirectoryResponse response = null; IntPtr requestName = (IntPtr)0; IntPtr requestValue = (IntPtr)0; IntPtr entryMessage = (IntPtr)0; bool needAbandon = true; // processing for the partial results retrieval if (resultType != ResultAll.LDAP_MSG_ALL) { // we need to have 0 timeout as we are polling for the results and don't want to wait timeout.tv_sec = 0; timeout.tv_usec = 0; if (resultType == ResultAll.LDAP_MSG_POLLINGALL) resultType = ResultAll.LDAP_MSG_ALL; // when doing partial results retrieving, if ldap_result failed, we don't do ldap_abandon here. needAbandon = false; } error = Wldap32.ldap_result(ldapHandle, messageId, (int)resultType, timeout, ref ldapResult); if (error != -1 && error != 0) { // parsing the result int serverError = 0; try { int resulterror = 0; string responseDn = null; string responseMessage = null; Uri[] responseReferral = null; DirectoryControl[] responseControl = null; // ldap_parse_result skips over messages of type LDAP_RES_SEARCH_ENTRY and LDAP_RES_SEARCH_REFERRAL if (error != (int)LdapResult.LDAP_RES_SEARCH_ENTRY && error != (int)LdapResult.LDAP_RES_REFERRAL) resulterror = ConstructParsedResult(ldapResult, ref serverError, ref responseDn, ref responseMessage, ref responseReferral, ref responseControl); if (resulterror == 0) { resulterror = serverError; if (error == (int)LdapResult.LDAP_RES_ADD) response = new AddResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); else if (error == (int)LdapResult.LDAP_RES_MODIFY) response = new ModifyResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); else if (error == (int)LdapResult.LDAP_RES_DELETE) response = new DeleteResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); else if (error == (int)LdapResult.LDAP_RES_MODRDN) response = new ModifyDNResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); else if (error == (int)LdapResult.LDAP_RES_COMPARE) response = new CompareResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); else if (error == (int)LdapResult.LDAP_RES_EXTENDED) { response = new ExtendedResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); if (resulterror == (int)ResultCode.Success) { resulterror = Wldap32.ldap_parse_extended_result(ldapHandle, ldapResult, ref requestName, ref requestValue, 0 /*not free it*/); if (resulterror == 0) { string name = null; if (requestName != (IntPtr)0) { name = Marshal.PtrToStringUni(requestName); } berval val = null; byte[] requestValueArray = null; if (requestValue != (IntPtr)0) { val = new berval(); Marshal.PtrToStructure(requestValue, val); if (val.bv_len != 0 && val.bv_val != (IntPtr)0) { requestValueArray = new byte[val.bv_len]; Marshal.Copy(val.bv_val, requestValueArray, 0, val.bv_len); } } ((ExtendedResponse)response).name = name; ((ExtendedResponse)response).value = requestValueArray; } } } else if (error == (int)LdapResult.LDAP_RES_SEARCH_RESULT || error == (int)LdapResult.LDAP_RES_SEARCH_ENTRY || error == (int)LdapResult.LDAP_RES_REFERRAL) { response = new SearchResponse(responseDn, responseControl, (ResultCode)resulterror, responseMessage, responseReferral); //set the flag here so our partial result processor knows whether the search is done or not if (error == (int)LdapResult.LDAP_RES_SEARCH_RESULT) { ((SearchResponse)response).searchDone = true; } SearchResultEntryCollection searchResultEntries = new SearchResultEntryCollection(); SearchResultReferenceCollection searchResultReferences = new SearchResultReferenceCollection(); // parsing the resultentry entryMessage = Wldap32.ldap_first_entry(ldapHandle, ldapResult); int entrycount = 0; while (entryMessage != (IntPtr)0) { SearchResultEntry entry = ConstructEntry(entryMessage); if (entry != null) searchResultEntries.Add(entry); entrycount++; entryMessage = Wldap32.ldap_next_entry(ldapHandle, entryMessage); } // parsing the reference IntPtr referenceMessage = Wldap32.ldap_first_reference(ldapHandle, ldapResult); while (referenceMessage != (IntPtr)0) { SearchResultReference reference = ConstructReference(referenceMessage); if (reference != null) searchResultReferences.Add(reference); referenceMessage = Wldap32.ldap_next_reference(ldapHandle, referenceMessage); } ((SearchResponse)response).SetEntries(searchResultEntries); ((SearchResponse)response).SetReferences(searchResultReferences); } if (resulterror != (int)ResultCode.Success && resulterror != (int)ResultCode.CompareFalse && resulterror != (int)ResultCode.CompareTrue && resulterror != (int)ResultCode.Referral && resulterror != (int)ResultCode.ReferralV2) { // throw operation exception if (Utility.IsResultCode((ResultCode)resulterror)) { throw new DirectoryOperationException(response, OperationErrorMappings.MapResultCode(resulterror)); } else // should not occur throw new DirectoryOperationException(response); } return response; } else { // fall over, throw the exception beow error = resulterror; } } finally { if (requestName != (IntPtr)0) Wldap32.ldap_memfree(requestName); if (requestValue != (IntPtr)0) Wldap32.ldap_memfree(requestValue); if (ldapResult != (IntPtr)0) { Wldap32.ldap_msgfree(ldapResult); } } } else { // ldap_result failed if (error == 0) { if (exceptionOnTimeOut) { // client side timeout error = (int)LdapError.TimeOut; } else { // if we don't throw exception on time out (notification search for example), we just return empty resposne return null; } } else { error = Wldap32.LdapGetLastError(); } // abandon the request if (needAbandon) Wldap32.ldap_abandon(ldapHandle, messageId); } // throw proper exception here throw ConstructException(error, operation); }
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); } }
private async Task <string> GenerateEmailBodyAsync() { await GetResults(); var retString = $"<html><body><h1>Results for {CurrentTastingName}</h1>"; retString += "<table style=\"width: 100 %\">"; retString += " <tr>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">#</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Beername</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">BreweryName</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">ABV</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Taste</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Appearance</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Overall</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">FINAL</th>"; retString += " </tr>"; for (int i = 0; i < ResultAll.Count; i++) { retString += " <tr>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{i+1}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].BeerName}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].BreweryName}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].Abv}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].ScoreTaste}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].ScoreAppearance}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].ScoreOverall}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{ResultAll[i].ScoreFinal}</td>"; retString += " </tr>"; } retString += "</table><br><br>"; var myVotes = await _context.Vote.Where(x => x.TastingId == CurrentTastingId && x.TasterId == CurrentTaster.TasterId).OrderByDescending(x => x.Taste).ThenByDescending(x => x.Overall).ThenByDescending(x => x.Appearance).ToListAsync(); var beers = await _context.Beer.Where(x => ResultAll.Any(y => y.BeerId == x.BeerId)).ToListAsync(); var breweries = await _context.Brewery.Where(x => beers.Any(y => y.BreweryId == x.BreweryId)).ToListAsync(); if (!myVotes.Any()) { retString += $"<h3>No votes found for {CurrentTaster.DisplayName}"; return(retString); } retString += $"<h1>Results for {CurrentTaster.DisplayName}</h1>"; retString += "<table style=\"width: 100 %\">"; retString += " <tr>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">#</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Beername</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">BreweryName</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">ABV</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Taste</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Appearance</th>"; retString += " <th style=\"border-bottom: 1px solid #ddd;\">Overall</th>"; retString += " </tr>"; for (int j = 0; j < myVotes.Count; j++) { var beer = beers.FirstOrDefault(x => x.BeerId == myVotes[j].BeerId); var brewery = breweries.FirstOrDefault(x => x.BreweryId == beer.BreweryId); retString += " <tr>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{j + 1}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{beer.Name}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{brewery.Name}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{beer.ABV}</td>"; var taste = myVotes[j].Taste; var appearance = myVotes[j].Appearance; var overall = myVotes[j].Overall; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{Math.Round(taste, 2)}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{Math.Round(appearance, 2)}</td>"; retString += $" <td style=\"border-bottom: 1px solid #ddd;\">{Math.Round(overall, 2)}</td>"; retString += " </tr>"; } retString += "</table></body></html>"; return(retString); }
internal DirectoryResponse ConstructResponse(int messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, bool exceptionOnTimeOut) { DirectoryResponse directoryResponse; LDAP_TIMEVAL lDAPTIMEVAL = new LDAP_TIMEVAL(); lDAPTIMEVAL.tv_sec = (int)(requestTimeOut.Ticks / (long)0x989680); IntPtr intPtr = (IntPtr)0; DirectoryResponse searchResponse = null; IntPtr intPtr1 = (IntPtr)0; IntPtr intPtr2 = (IntPtr)0; bool flag = true; if (resultType != ResultAll.LDAP_MSG_ALL) { lDAPTIMEVAL.tv_sec = 0; lDAPTIMEVAL.tv_usec = 0; if (resultType == ResultAll.LDAP_MSG_POLLINGALL) { resultType = ResultAll.LDAP_MSG_ALL; } flag = false; } int num = Wldap32.ldap_result(this.ldapHandle, messageId, (int)resultType, lDAPTIMEVAL, ref intPtr); if (num == -1 || num == 0) { if (num != 0) { num = Wldap32.LdapGetLastError(); } else { if (!exceptionOnTimeOut) { return null; } else { num = 85; } } if (flag) { Wldap32.ldap_abandon(this.ldapHandle, messageId); } } else { int num1 = 0; try { int num2 = 0; string str = null; string str1 = null; Uri[] uriArray = null; DirectoryControl[] directoryControlArray = null; if (num != 100 && num != 115) { num2 = this.ConstructParsedResult(intPtr, ref num1, ref str, ref str1, ref uriArray, ref directoryControlArray); } if (num2 != 0) { num = num2; throw this.ConstructException(num, operation); } else { num2 = num1; if (num != 105) { if (num != 103) { if (num != 107) { if (num != 109) { if (num != 111) { if (num != 120) { if (num == 101 || num == 100 || num == 115) { searchResponse = new SearchResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); if (num == 101) { ((SearchResponse)searchResponse).searchDone = true; } SearchResultEntryCollection searchResultEntryCollection = new SearchResultEntryCollection(); SearchResultReferenceCollection searchResultReferenceCollection = new SearchResultReferenceCollection(); IntPtr intPtr3 = Wldap32.ldap_first_entry(this.ldapHandle, intPtr); int num3 = 0; while (intPtr3 != (IntPtr)0) { SearchResultEntry searchResultEntry = this.ConstructEntry(intPtr3); if (searchResultEntry != null) { searchResultEntryCollection.Add(searchResultEntry); } num3++; intPtr3 = Wldap32.ldap_next_entry(this.ldapHandle, intPtr3); } IntPtr intPtr4 = Wldap32.ldap_first_reference(this.ldapHandle, intPtr); while (intPtr4 != (IntPtr)0) { SearchResultReference searchResultReference = this.ConstructReference(intPtr4); if (searchResultReference != null) { searchResultReferenceCollection.Add(searchResultReference); } intPtr4 = Wldap32.ldap_next_reference(this.ldapHandle, intPtr4); } ((SearchResponse)searchResponse).SetEntries(searchResultEntryCollection); ((SearchResponse)searchResponse).SetReferences(searchResultReferenceCollection); } } else { searchResponse = new ExtendedResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); if (num2 == 0) { num2 = Wldap32.ldap_parse_extended_result(this.ldapHandle, intPtr, ref intPtr1, ref intPtr2, 0); if (num2 == 0) { string stringUni = null; if (intPtr1 != (IntPtr)0) { stringUni = Marshal.PtrToStringUni(intPtr1); } byte[] numArray = null; if (intPtr2 != (IntPtr)0) { berval _berval = new berval(); Marshal.PtrToStructure(intPtr2, _berval); if (_berval.bv_len != 0 && _berval.bv_val != (IntPtr)0) { numArray = new byte[_berval.bv_len]; Marshal.Copy(_berval.bv_val, numArray, 0, _berval.bv_len); } } ((ExtendedResponse)searchResponse).name = stringUni; ((ExtendedResponse)searchResponse).@value = numArray; } } } } else { searchResponse = new CompareResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); } } else { searchResponse = new ModifyDNResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); } } else { searchResponse = new DeleteResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); } } else { searchResponse = new ModifyResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); } } else { searchResponse = new AddResponse(str, directoryControlArray, (ResultCode)num2, str1, uriArray); } if (num2 == 0 || num2 == 5 || num2 == 6 || num2 == 10 || num2 == 9) { directoryResponse = searchResponse; } else { if (!Utility.IsResultCode((ResultCode)num2)) { throw new DirectoryOperationException(searchResponse); } else { throw new DirectoryOperationException(searchResponse, OperationErrorMappings.MapResultCode(num2)); } } } } finally { if (intPtr1 != (IntPtr)0) { Wldap32.ldap_memfree(intPtr1); } if (intPtr2 != (IntPtr)0) { Wldap32.ldap_memfree(intPtr2); } if (intPtr != (IntPtr)0) { Wldap32.ldap_msgfree(intPtr); } } return directoryResponse; } throw this.ConstructException(num, operation); }
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); } }
internal DirectoryResponse ConstructResponse(int messageId, LdapOperation operation, ResultAll resultType, TimeSpan requestTimeOut, bool exceptionOnTimeOut) { LDAP_TIMEVAL timeout = new LDAP_TIMEVAL { tv_sec = (int) (requestTimeOut.Ticks / 0x989680L) }; IntPtr zero = IntPtr.Zero; DirectoryResponse response = null; IntPtr oid = IntPtr.Zero; IntPtr data = IntPtr.Zero; IntPtr entryMessage = IntPtr.Zero; bool flag = true; if (resultType != ResultAll.LDAP_MSG_ALL) { timeout.tv_sec = 0; timeout.tv_usec = 0; if (resultType == ResultAll.LDAP_MSG_POLLINGALL) { resultType = ResultAll.LDAP_MSG_ALL; } flag = false; } int error = Wldap32.ldap_result(this.ldapHandle, messageId, (int) resultType, timeout, ref zero); switch (error) { case -1: case 0: break; default: { int serverError = 0; try { int errorCode = 0; string responseDn = null; string responseMessage = null; Uri[] responseReferral = null; DirectoryControl[] responseControl = null; if ((error != 100) && (error != 0x73)) { errorCode = this.ConstructParsedResult(zero, ref serverError, ref responseDn, ref responseMessage, ref responseReferral, ref responseControl); } if (errorCode == 0) { errorCode = serverError; switch (error) { case 0x69: response = new AddResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); break; case 0x67: response = new ModifyResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); break; case 0x6b: response = new DeleteResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); break; case 0x6d: response = new ModifyDNResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); break; case 0x6f: response = new CompareResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); break; case 120: response = new ExtendedResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); if (errorCode == 0) { errorCode = Wldap32.ldap_parse_extended_result(this.ldapHandle, zero, ref oid, ref data, 0); if (errorCode == 0) { string str3 = null; if (oid != IntPtr.Zero) { str3 = Marshal.PtrToStringUni(oid); } berval structure = null; byte[] destination = null; if (data != IntPtr.Zero) { structure = new berval(); Marshal.PtrToStructure(data, structure); if ((structure.bv_len != 0) && (structure.bv_val != IntPtr.Zero)) { destination = new byte[structure.bv_len]; Marshal.Copy(structure.bv_val, destination, 0, structure.bv_len); } } ((ExtendedResponse) response).name = str3; ((ExtendedResponse) response).value = destination; } } break; case 0x65: case 100: case 0x73: { response = new SearchResponse(responseDn, responseControl, (ResultCode) errorCode, responseMessage, responseReferral); if (error == 0x65) { ((SearchResponse) response).searchDone = true; } SearchResultEntryCollection col = new SearchResultEntryCollection(); SearchResultReferenceCollection references = new SearchResultReferenceCollection(); entryMessage = Wldap32.ldap_first_entry(this.ldapHandle, zero); int num4 = 0; while (entryMessage != IntPtr.Zero) { SearchResultEntry entry = this.ConstructEntry(entryMessage); if (entry != null) { col.Add(entry); } num4++; entryMessage = Wldap32.ldap_next_entry(this.ldapHandle, entryMessage); } for (IntPtr ptr5 = Wldap32.ldap_first_reference(this.ldapHandle, zero); ptr5 != IntPtr.Zero; ptr5 = Wldap32.ldap_next_reference(this.ldapHandle, ptr5)) { SearchResultReference reference = this.ConstructReference(ptr5); if (reference != null) { references.Add(reference); } } ((SearchResponse) response).SetEntries(col); ((SearchResponse) response).SetReferences(references); break; } } switch (errorCode) { case 0: case 5: case 6: case 10: case 9: return response; default: if (Utility.IsResultCode((ResultCode) errorCode)) { throw new DirectoryOperationException(response, OperationErrorMappings.MapResultCode(errorCode)); } throw new DirectoryOperationException(response); } } error = errorCode; goto Label_03A7; } finally { if (oid != IntPtr.Zero) { Wldap32.ldap_memfree(oid); } if (data != IntPtr.Zero) { Wldap32.ldap_memfree(data); } if (zero != IntPtr.Zero) { Wldap32.ldap_msgfree(zero); } } break; } } if (error == 0) { if (!exceptionOnTimeOut) { return null; } error = 0x55; } else { error = Wldap32.LdapGetLastError(); } if (flag) { Wldap32.ldap_abandon(this.ldapHandle, messageId); } Label_03A7: throw this.ConstructException(error, operation); }