예제 #1
0
        void DoRunDTP(RunDTP_SO stateObj)
        {
            //now, run the DTP
            try
            {
                stateObj.UpdateContext();
                //----------------------------------------
                //prepare for abortion
                _aborted           = false;
                _client.CurrentDTP = this;

                //----------------------------------------
                //Unlock control connection, now the command
                //like abort, stat, quit could be issued
                UnlockCC(stateObj);

                _currentDC.DataTransfered += new FtpDataConnection.DataTransferedEventHandler(OnDataTransfered);
                _currentDC.Completed      += new FtpDataConnection.CompletedEventHandler(OnCompleted);

                _currentDC.BeginRunDTPStream(stateObj.Timeout,
                                             stateObj.UserStream,
                                             new AsyncCallback(RunDTP_End),
                                             stateObj);
            }
            catch
            {
                _currentDC.DataTransfered -= new FtpDataConnection.DataTransferedEventHandler(OnDataTransfered);
                _currentDC.Completed      -= new FtpDataConnection.CompletedEventHandler(OnCompleted);
                throw;
            }
        }
예제 #2
0
        void TypeCmd_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                FtpResponse response = _cc.EndSendCommandEx(ar);
                FtpClient.CheckCompletionResponse(response);

                _client.IsDataTypeWasCached = true;
                _client.CachedDataType      = stateObj.DataType;

                stateObj.GetDC_Cmd = new Cmd_GetDataConnection(_client);

                //Initialize data connection
                stateObj.GetDC_Cmd.BeginExecute(stateObj.Timeout,
                                                new AsyncCallback(GetDC_End),
                                                stateObj);
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #3
0
        void LockLast_End(object state, bool timedout)
        {
            RunDTP_SO stateObj = (RunDTP_SO)state;

            try
            {
                stateObj.UpdateContext();
                //----------------------------------------
                //CC is locked again
                stateObj.CCLocked = true;

                //read all preliminary results, till completion
                _cc.BeginReadResponse(stateObj.Timeout,
                                      new AsyncCallback(this.ReadLastResponse_End),
                                      stateObj);
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #4
0
        internal void ReadAbortResponse_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                FtpResponse response = _cc.EndReadResponse(ar);
                if (_quited)
                {
                    //----------------------------------------
                    // If quited read one more response
                    _cc.BeginReadResponse(stateObj.Timeout,
                                          new AsyncCallback(ReadQuitResponse_End),
                                          stateObj);
                }
                else
                {
                    ClearAtEnd(stateObj);
                }
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #5
0
 void UnlockCC(RunDTP_SO stateObj)
 {
     if (true == stateObj.CCLocked)
     {
         _cc.Unlock();
         stateObj.CCLocked = false;
     }
 }
예제 #6
0
        void GetDC_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                lock (this)
                {
                    if (!_disposed)
                    {
                        _currentDC = stateObj.GetDC_Cmd.EndExecute(ar);
                    }
                }
                CheckDisposed();

                //send restart position, if needed
                if (stateObj.Restart > 0)
                {
                    string restCmd = "REST " + stateObj.Restart.ToString();
                    _cc.BeginSendCommandEx(stateObj.Timeout,
                                           restCmd,
                                           new AsyncCallback(this.Restart_End),
                                           stateObj);
                }
                else
                {
                    //establish connection now, if it is outbound
                    if (FtpDataConnectionType.Outbound == _currentDC.Type)
                    {
                        _currentDC.BeginEstablish(stateObj.Timeout,
                                                  new AsyncCallback(this.OutboundEstablish_End),
                                                  stateObj);
                    }
                    else
                    {
                        _cc.BeginSendCommandEx(stateObj.Timeout,
                                               stateObj.Command,
                                               new AsyncCallback(this.SendCommandEx_End),
                                               stateObj);
                    }
                }
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #7
0
        void ClearAtEnd(RunDTP_SO stateObj)
        {
            stateObj.SetCompleted();

            //----------------------------------------
            //Clear context
            _client.CurrentDTP = null;
            _currentDC         = null;

            //----------------------------------------
            //Unlock control connection, now the command
            //like abort, stat, quit could be issued
            UnlockCC(stateObj);
        }
예제 #8
0
        internal IAsyncResult BeginExecute(int timeout,
                                           string command,
                                           FtpDataType dataType,
                                           long restart,
                                           DTPStream userStream,
                                           AsyncCallback cb,
                                           object state)
        {
            RunDTP_SO stateObj = new RunDTP_SO(timeout,
                                               command,
                                               dataType,
                                               restart,
                                               userStream,
                                               cb,
                                               state);

            SetProgress(true);
            _currentDC = null;
            try
            {
                //----------------------------------------
                //Lock Control connection to prevent
                //run the command like abort, quit, stat
                //during configuring of data connection
                _cc.BeginLock(Timeout.Infinite,
                              new WaitOrTimerCallback(LockFirst_End),
                              stateObj);
            }
            catch (Exception e)
            {
                SetProgress(false);
                CheckDisposed();

                NSTrace.WriteLineError(_errMsg + e.ToString());
                throw;
            }
            catch
            {
                SetProgress(false);
                CheckDisposed();

                NSTrace.WriteLineError(_errMsgNonCls + Environment.StackTrace.ToString());
                throw;
            }
            return(stateObj);
        }
예제 #9
0
        void HandleCatch(Exception e,
                         RunDTP_SO stateObj)
        {
            //----------------------------------------
            //Clear context before unlocking
            _client.CurrentDTP = null;

            //----------------------------------------
            //Unlock control connection, now the command
            //like abort, stat, quit could be issued
            try
            {
                UnlockCC(stateObj);
            }
            catch (Exception ex)
            {
                NSTrace.WriteLineError("UnlockCC exception: " + ex.ToString());
            }
            catch
            {
                NSTrace.WriteLineError("UnlockCC non-cls exception: " + Environment.StackTrace);
            }

            if (_disposed)
            {
                stateObj.Exception = GetDisposedException();
            }
            else if (null != e)
            {
                NSTrace.WriteLineError("DTP exception: " + e.ToString());
                stateObj.Exception = e;
            }
            else
            {
                NSTrace.WriteLineError("DTP non cls exception: " + Environment.StackTrace);
            }

            //Do not set completed in case we
            //have non-cls exception
            if (null != stateObj.Exception)
            {
                stateObj.SetCompleted();
            }
        }
예제 #10
0
        internal void ReadQuitResponse_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                FtpResponse response = _cc.EndReadResponse(ar);
                ClearAtEnd(stateObj);
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #11
0
        void RunDTP_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDC.DataTransfered -= new FtpDataConnection.DataTransferedEventHandler(OnDataTransfered);
                _currentDC.Completed      -= new FtpDataConnection.CompletedEventHandler(OnCompleted);

                try
                {
                    //finish DTP...
                    _currentDC.EndRunDTPStream(ar);
                    stateObj.ManuallyClosed = _currentDC.ManuallyClosed;
                }
                catch (FtpAbortedException ex)
                {
                    stateObj.AbortEx = ex;
                }
                finally
                {
                    _currentDC.Dispose();
                    _currentDC = null;
                }

                //----------------------------------------
                //Lock control connection again - reading
                //responses
                _cc.BeginLock(Timeout.Infinite,
                              new WaitOrTimerCallback(LockLast_End),
                              stateObj);
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #12
0
        void InboundEstablish_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDC.EndEstablish(ar);

                DoRunDTP(stateObj);
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #13
0
        void LockFirst_End(object state, bool timedout)
        {
            RunDTP_SO stateObj = (RunDTP_SO)state;

            try
            {
                stateObj.UpdateContext();
                //----------------------------------------
                //Indicate that we lock CC
                stateObj.CCLocked = true;

                //----------------------------------------
                //send transfser type command
                if ((false == _client.IsDataTypeWasCached) ||
                    ((true == _client.IsDataTypeWasCached) && (_client.CachedDataType != stateObj.DataType)))
                {
                    string typeCmd = GetTypeCommand(stateObj.DataType);
                    _cc.BeginSendCommandEx(stateObj.Timeout,
                                           typeCmd,
                                           new AsyncCallback(TypeCmd_End),
                                           stateObj);
                }
                else
                {
                    stateObj.GetDC_Cmd = new Cmd_GetDataConnection(_client);

                    //Initialize data connection
                    stateObj.GetDC_Cmd.BeginExecute(stateObj.Timeout,
                                                    new AsyncCallback(GetDC_End),
                                                    stateObj);
                }
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #14
0
        void SendCommandEx_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                FtpResponse response = _cc.EndSendCommandEx(ar);
                if (response.IsCompletionReply)
                {
                    NSTrace.WriteLineWarning("Executing DTP: receive completion as first reply.");
                    UnlockCC(stateObj);
                    stateObj.SetCompleted();
                }
                else
                {
                    FtpClient.CheckPreliminaryResponse(response);

                    //establish connection now, if it is inbound
                    if (FtpDataConnectionType.Inbound == _currentDC.Type)
                    {
                        _currentDC.BeginEstablish(stateObj.Timeout,
                                                  new AsyncCallback(this.InboundEstablish_End),
                                                  stateObj);
                    }
                    else
                    {
                        DoRunDTP(stateObj);
                    }
                }
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #15
0
        void OutboundEstablish_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDC.EndEstablish(ar);

                _cc.BeginSendCommandEx(stateObj.Timeout,
                                       stateObj.Command,
                                       new AsyncCallback(this.SendCommandEx_End),
                                       stateObj);
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #16
0
        void Restart_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                FtpResponse res = _cc.EndSendCommandEx(ar);
                if (false == res.IsIntermediateReply)
                {
                    throw GetRestartNotSuppException(res);
                }

                //establish connection now, if it is outbound
                if (FtpDataConnectionType.Outbound == _currentDC.Type)
                {
                    _currentDC.BeginEstablish(stateObj.Timeout,
                                              new AsyncCallback(this.OutboundEstablish_End),
                                              stateObj);
                }
                else
                {
                    _cc.BeginSendCommandEx(stateObj.Timeout,
                                           stateObj.Command,
                                           new AsyncCallback(this.SendCommandEx_End),
                                           stateObj);
                }
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }
예제 #17
0
        void ReadLastResponse_End(IAsyncResult ar)
        {
            RunDTP_SO stateObj = (RunDTP_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                bool          needMore = true;
                AsyncCallback callBack = null;

                FtpResponse response = _cc.EndReadResponse(ar);
                if (!response.IsPreliminaryReply)
                {
                    needMore = false;

                    //----------------------------------------
                    // Dealing with Abort or Reset
                    //
                    if (!_aborted && (null == stateObj.AbortEx))
                    {
                        if (!stateObj.ManuallyClosed)
                        {
                            FtpClient.CheckCompletionResponse(response);
                        }
                        else
                        {
                            //----------------------------------------
                            //we DID close the data connection,
                            //so, in general, the response should be
                            //errorneous - therefore skip checking of it
                        }
                    }
                    else
                    {
                        if (null != stateObj.AbortEx)                       // &&
                        //!response.IsCompletionReply)
                        {
                            stateObj.AbortEx.SetResponse(response);
                        }

                        stateObj.Exception = stateObj.AbortEx;

                        //----------------------------------------
                        //If "ABOR" command was sent we need to
                        //read one more response ...
                        //
                        if (_aborted)
                        {
                            callBack = new AsyncCallback(this.ReadAbortResponse_End);
                            needMore = true;
                        }
                    }

                    if (!_aborted && _quited)
                    {
                        callBack = new AsyncCallback(this.ReadQuitResponse_End);
                        needMore = true;
                    }
                }
                else
                {
                    stateObj.PrelRespCount++;
                    if (stateObj.PrelRespCount > 10)
                    {
                        throw GetTooManyRespException();
                    }
                }

                if (true == needMore)
                {
                    if (null == callBack)
                    {
                        callBack = new AsyncCallback(this.ReadLastResponse_End);
                    }

                    //----------------------------------------
                    //read all preliminary results, till enough
                    _cc.BeginReadResponse(stateObj.Timeout,
                                          callBack,
                                          stateObj);
                }
                else
                {
                    ClearAtEnd(stateObj);
                }
            }
            catch (Exception e)
            {
                HandleCatch(e, stateObj);
            }
            catch
            {
                HandleCatch(null, stateObj);
            }
        }