internal void RunDTPStream(int timeout, DTPStream stream) { CheckDisposed(); //------------------------------------------ //Validate input DTPStreamType dtpType = ValidateInputStream(stream); //------------------------------------------- //Allocate data buffer _wholeTransfered = 0; if (null == _workBuffer) { _workBuffer = new byte[_bufferSize]; } //-------------------------------------------- //Prevent simultaneous usage SetProgress(true); _manuallyClosed = false; try { SetTimeout(timeout); if (DTPStreamType.ForWriting == dtpType) { RunDownloadingStream(stream); } else //if(DTPStreamType.ForReading == dtpType) { RunUploadingStream(stream); } } catch (SocketException e) { if (_aborted) { throw new FtpAbortedException(); } CheckDisposed(); CheckTimeoutException(e); throw; } catch { if (_aborted) { throw new FtpAbortedException(); } CheckDisposed(); throw; //string msg = "Data transfering was unexpectedly interrupted."; //throw new FtpIOException(msg, e); } finally { Dispose(); SetProgress(false); } }
internal DTPStreamCommon(Stream stream, DTPStreamType type, long maxData) { _stream = stream; _type = type; if (maxData > 0) { _available = maxData; } }
DTPStreamType ValidateInputStream(DTPStream stream) { //------------------------------------------ //Validate input if (null == stream) { throw new ArgumentNullException("steam", "The value cannot be null."); } DTPStreamType dtpType = stream.Type; if ((DTPStreamType.ForWriting != dtpType) && (DTPStreamType.ForReading != dtpType)) { string msg = string.Format("Unknown DTP type ({0})", stream.Type.ToString()); NSTrace.WriteLineError(msg); throw new ArgumentException(msg, "type"); } return(dtpType); }
internal DTPStreamCommon(Stream stream, DTPStreamType type) { _stream = stream; _type = type; }
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); }