예제 #1
0
        /// <summary>
        /// Starts authentication.
        /// </summary>
        /// <param name="userName">User login name.</param>
        /// <param name="password">Password.</param>
        /// <param name="tryApop"> If true and POP3 server supports APOP, then APOP is used, otherwise normal login used.</param>
        /// <param name="callback">Callback to call when the asynchronous operation is complete.</param>
        /// <param name="state">User data.</param>
        /// <returns>An IAsyncResult that references the asynchronous operation.</returns>
        /// <exception cref="ObjectDisposedException">Is raised when this object is disposed and this method is accessed.</exception>
        /// <exception cref="InvalidOperationException">Is raised when POP3 client is not connected or is already authenticated.</exception>
        public IAsyncResult BeginAuthenticate(string userName,
                                              string password,
                                              bool tryApop,
                                              AsyncCallback callback,
                                              object state)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (!IsConnected)
            {
                throw new InvalidOperationException("You must connect first.");
            }
            if (IsAuthenticated)
            {
                throw new InvalidOperationException("Session is already authenticated.");
            }

            AuthenticateDelegate asyncMethod = Authenticate;
            AsyncResultState     asyncState  = new AsyncResultState(this, asyncMethod, callback, state);

            asyncState.SetAsyncResult(asyncMethod.BeginInvoke(userName,
                                                              password,
                                                              tryApop,
                                                              asyncState.CompletedCallback,
                                                              null));

            return(asyncState);
        }
예제 #2
0
        public void AuthenticateAsync(Func <string, string> userAuthCallback, Action <Action> completeCallback)
        {
            lock (authLock)
            {
                if (isAuthenticating)
                {
                    throw new InvalidOperationException("SportsClient is currently authenticating...");
                }
                isAuthenticating = true;

                AuthenticateDelegate dlgt = Authenticate;
                dlgt.BeginInvoke(userAuthCallback, ar => completeCallback(() =>
                {
                    ((AuthenticateDelegate)ar.AsyncState)
                    .EndInvoke(ar);
                    IsAuthenticated  = true;
                    isAuthenticating = false;
                }), dlgt);
            }
        }
예제 #3
0
파일: SMTP_Client.cs 프로젝트: dioptre/nkd
        public IAsyncResult BeginAuthenticate(string userName,string password,AsyncCallback callback,object state)
        {
            if(this.IsDisposed){
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if(!this.IsConnected){
				throw new InvalidOperationException("You must connect first.");
			}
			if(this.IsAuthenticated){
				throw new InvalidOperationException("Session is already authenticated.");
			}

            AuthenticateDelegate asyncMethod = new AuthenticateDelegate(this.Authenticate);
            AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state);
            asyncState.SetAsyncResult(asyncMethod.BeginInvoke(userName,password,new AsyncCallback(asyncState.CompletedCallback),null));

            return asyncState;
        }