コード例 #1
0
        void DTPFinishedStream(IAsyncResult ar)
        {
            RunDTPStateObjectStream stateObj = (RunDTPStateObjectStream)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                if (true == stateObj.IsDownloading)
                {
                    EndRunDownloadingStream(ar);
                }
                else
                {
                    EndRunUploadingStream(ar);
                }
            }
            catch (SocketException e)
            {
                if (_aborted)
                {
                    stateObj.Exception = new FtpAbortedException();
                }
                else if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else if (e.ErrorCode == SockErrors.WSAETIMEDOUT)
                {
                    stateObj.Exception = GetTimeoutException(e);
                }
                else
                {
                    stateObj.Exception = e;
                }
            }
            catch (Exception e)
            {
                if (_aborted)
                {
                    stateObj.Exception = new FtpAbortedException();
                }
                else if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    stateObj.Exception = e;
                }
            }
            catch
            {
                if (_aborted)
                {
                    stateObj.Exception = new FtpAbortedException();
                }
                else if (_disposed)
                {
                    stateObj.Exception = GetDisposedException();
                }
                else
                {
                    NSTrace.WriteLineError("Non-CLS exception at: " + Environment.StackTrace);
                    throw;
                }
            }
            stateObj.SetCompleted();
        }
コード例 #2
0
        internal IAsyncResult BeginRunDTPStream(int timeout, DTPStream stream, AsyncCallback cb, object state)
        {
            CheckDisposed();

            //------------------------------------------
            //Validate input
            DTPStreamType dtpType = ValidateInputStream(stream);

            //-------------------------------------------
            //Allocate data buffer
            _wholeTransfered = 0;
            if (null == _workBuffer)
            {
                _workBuffer = new byte[_bufferSize];
            }

            //--------------------------------------------
            //Prevent simultaneous usage
            SetProgress(true);

            RunDTPStateObjectStream stateObj = null;

            _manuallyClosed = false;

            try
            {
                SetTimeout(timeout);
                if (DTPStreamType.ForWriting == dtpType)
                {
                    stateObj = new RunDTPStateObjectStream(true, cb, state);
                    BeginRunDownloadingStream(stream,
                                              new AsyncCallback(this.DTPFinishedStream),
                                              stateObj);
                }
                else                 //if(DTPStreamType.ForReading == stream.Type)
                {
                    stateObj = new RunDTPStateObjectStream(false, cb, state);
                    BeginRunUploadingStream(stream,
                                            new AsyncCallback(this.DTPFinishedStream),
                                            stateObj);
                }
            }
            catch (SocketException e)
            {
                SetProgress(false);
                if (_aborted)
                {
                    throw new FtpAbortedException();
                }
                CheckDisposed();
                CheckTimeoutException(e);
                throw;
            }
            catch
            {
                SetProgress(false);
                if (_aborted)
                {
                    throw new FtpAbortedException();
                }
                CheckDisposed();
                throw;
            }
            return(stateObj);
        }