Exemple #1
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);
			}
		}
Exemple #2
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);
            }
        }
 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);
 }