コード例 #1
0
ファイル: Cmd_PutFileUnique.cs プロジェクト: kineva1992/repos
        internal string Execute(int timeout,
                                Stream userStream,
                                long length)
        {
            SetProgress(true);
            _uniqueFileName = null;
            try
            {
                CreateDTP();
                string cmd = "STOU";

                _cc.ResponseReceived += new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived);
                _currentDTP.Execute(timeout,
                                    cmd,
                                    _client.DataType,
                                    -1,
                                    new DTPStreamCommon(userStream, DTPStreamType.ForReading, length));
            }
            finally
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                _cc.ResponseReceived -= new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived);
                SetProgress(false);
            }
            return(_uniqueFileName);
        }
コード例 #2
0
        internal void Execute(int timeout,
                              Stream userStream,
                              string file,
                              long length)
        {
            SetProgress(true);
            try
            {
                CreateDTP();
                string cmd = "STOR " + file;

                _currentDTP.Execute(timeout,
                                    cmd,
                                    _client.DataType,
                                    -1,
                                    new DTPStreamCommon(userStream, DTPStreamType.ForReading, length));
            }
            finally
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                SetProgress(false);
            }
        }
コード例 #3
0
 void CreateDTP()
 {
     _currentDTP = null;
     lock (this)
     {
         if (!_disposed)
         {
             _currentDTP = new Cmd_RunDTP(_client);
         }
     }
     CheckDisposed();
 }
コード例 #4
0
        internal IAsyncResult BeginExecute(int timeout, string path, AsyncCallback cb, object state)
        {
            List_SO stateObj = null;

            SetProgress(true);
            try
            {
                CreateDTP();
                stateObj = new List_SO(new DTPStreamCommon(Stream.Null, DTPStreamType.ForWriting),
                                       cb,
                                       state);

                _linesBuilder.NewLineEvent += new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent);
                _items.Clear();
                _linesBuilder.Reset();

                string cmd = "LIST";
                if (null != path)
                {
                    cmd += " " + path;
                }

                _currentDTP.DataTransfered += new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                try
                {
                    _currentDTP.BeginExecute(timeout,
                                             cmd,
                                             FtpDataType.Ascii,
                                             -1,
                                             stateObj.UserStream,
                                             new AsyncCallback(RunCmd_End),
                                             stateObj);
                }
                catch (Exception e)
                {
                    _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                    throw e;
                }
            }
            catch (Exception e)
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                SetProgress(false);
                throw e;
            }
            return(stateObj);
        }
コード例 #5
0
 void CreateDTP()
 {
     _currentDTP = null;
     lock (this)
     {
         if (!_disposed)
         {
             _currentDTP = new Cmd_RunDTP(_client);
         }
     }
     if (_disposed)
     {
         throw new ObjectDisposedException("Cmd_PutFile");
     }
 }
コード例 #6
0
        internal FtpItem[] Execute(int timeout, string dir)
        {
            FtpItem[] items = null;
            SetProgress(true);
            try
            {
                CreateDTP();
                _linesBuilder.NewLineEvent += new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent);
                _items.Clear();
                _linesBuilder.Reset();

                string cmd = "LIST";
                if (null != dir)
                {
                    cmd += " " + dir;
                }

                _currentDTP.DataTransfered += new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                try
                {
                    _currentDTP.Execute(timeout,
                                        cmd,
                                        FtpDataType.Ascii,
                                        -1,
                                        new DTPStreamCommon(Stream.Null, DTPStreamType.ForWriting));
                }
                finally
                {
                    _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                }

                items = new FtpItem[_items.Count];
                _items.CopyTo(items);
            }
            finally
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                _linesBuilder.NewLineEvent -= new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent);
                SetProgress(false);
            }
            return(items);
        }
コード例 #7
0
ファイル: Cmd_Reset.cs プロジェクト: kineva1992/repos
        void Lock_End(object state, bool timedout)
        {
            Reset_SO stateObj = (Reset_SO)state;

            try
            {
                stateObj.UpdateContext();
                if (timedout)
                {
                    string msg = string.Format("Unable to lock CC within {0} time: ", stateObj.Timeout);
                    NSTrace.WriteLineError(msg + Environment.StackTrace);
                    stateObj.Exception = GetTimeoutException(stateObj.Timeout);
                    stateObj.SetCompleted();
                }
                else
                {
                    try
                    {
                        Cmd_RunDTP curDTP = _client.CurrentDTP;
                        if (null != curDTP)
                        {
                            curDTP.Reset();
                        }
                    }
                    finally
                    {
                        _cc.Unlock();
                    }

                    //----------------------------------------
                    //Wait till DTP finishes
                    _client.BeginWaitForDTPFinished(stateObj.Timeout,
                                                    new WaitOrTimerCallback(DTPFinishedWait_End),
                                                    stateObj);
                }
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
コード例 #8
0
        void RunDTP_End(IAsyncResult ar)
        {
            PutFile_SO stateObj = (PutFile_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDTP.EndExecute(ar);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            finally
            {
                _currentDTP.Dispose();
                _currentDTP = null;
                stateObj.SetCompleted();
            }
        }
コード例 #9
0
ファイル: Cmd_PutFileUnique.cs プロジェクト: kineva1992/repos
        internal IAsyncResult BeginExecute(int timeout,
                                           Stream userStream,
                                           long length,
                                           AsyncCallback cb,
                                           object state)
        {
            PutFileUnique_SO stateObj = null;

            SetProgress(true);
            _uniqueFileName = null;
            try
            {
                CreateDTP();
                stateObj = new PutFileUnique_SO(userStream,
                                                cb,
                                                state);

                _cc.ResponseReceived += new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived);

                string cmd = "STOU";
                _currentDTP.BeginExecute(timeout,
                                         cmd,
                                         _client.DataType,
                                         -1,
                                         new DTPStreamCommon(userStream, DTPStreamType.ForReading, length),
                                         new AsyncCallback(this.RunDTP_End),
                                         stateObj);
            }
            catch (Exception e)
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                _cc.ResponseReceived -= new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived);
                SetProgress(false);
                throw e;
            }
            return(stateObj);
        }
コード例 #10
0
ファイル: Cmd_PutFileUnique.cs プロジェクト: kineva1992/repos
        void RunDTP_End(IAsyncResult ar)
        {
            PutFileUnique_SO stateObj = (PutFileUnique_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDTP.EndExecute(ar);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            finally
            {
                _currentDTP.Dispose();
                _currentDTP           = null;
                _cc.ResponseReceived -= new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived);
                stateObj.SetCompleted();
            }
        }
コード例 #11
0
ファイル: Cmd_Reset.cs プロジェクト: kineva1992/repos
        internal void Execute(int timeout)
        {
            bool finished = false;

            //---------------------------------
            //Lock CC
            if (_cc.Lock(timeout))
            {
                //------------------------------------------
                //Reset DTP
                try
                {
                    Cmd_RunDTP curDTP = _client.CurrentDTP;
                    if (null != curDTP)
                    {
                        curDTP.Reset();
                    }
                }
                finally
                {
                    _cc.Unlock();
                }

                //------------------------------------------
                //Wait till DTP exits
                finished = _client.WaitForDTPFinish(timeout);
                if (!finished)
                {
                    string msg = string.Format("DTP is not finished withing {0} time: ", timeout);
                    NSTrace.WriteLineError(msg + Environment.StackTrace);
                    throw GetTimeoutException(timeout);
                }
            }
            else
            {
                string msg = string.Format("Unable to lock CC within {0} time: ", timeout);
                NSTrace.WriteLineError(msg + Environment.StackTrace);
                throw GetTimeoutException(timeout);
            }
        }
コード例 #12
0
        void RunCmd_End(IAsyncResult ar)
        {
            List_SO stateObj = (List_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                _currentDTP.EndExecute(ar);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
            }
            finally
            {
                _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered);
                _currentDTP.Dispose();
                _currentDTP = null;
                _linesBuilder.NewLineEvent -= new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent);
                stateObj.SetCompleted();
            }
        }
コード例 #13
0
        internal IAsyncResult BeginExecute(int timeout,
                                           Stream userStream,
                                           string fileName,
                                           long length,
                                           AsyncCallback cb,
                                           object state)
        {
            PutFile_SO stateObj = null;

            SetProgress(true);
            try
            {
                CreateDTP();
                stateObj = new PutFile_SO(userStream,
                                          cb,
                                          state);

                string cmd = "STOR " + fileName;
                _currentDTP.BeginExecute(timeout,
                                         cmd,
                                         _client.DataType,
                                         -1,
                                         new DTPStreamCommon(userStream, DTPStreamType.ForReading, length),
                                         new AsyncCallback(this.RunDTP_End),
                                         stateObj);
            }
            catch (Exception e)
            {
                if (null != _currentDTP)
                {
                    _currentDTP.Dispose();
                    _currentDTP = null;
                }
                SetProgress(false);
                throw e;
            }
            return(stateObj);
        }