public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state) { if (method != WebRequestMethods.Ftp.UploadFile && method != WebRequestMethods.Ftp.UploadFileWithUniqueName && method != WebRequestMethods.Ftp.AppendFile) { throw new ProtocolViolationException(); } lock (locker) { CheckIfAborted(); if (State != RequestState.Before) { throw new InvalidOperationException("Cannot re-call BeginGetRequestStream/BeginGetResponse while a previous call is still in progress"); } State = RequestState.Scheduled; } asyncResult = new FtpAsyncResult(callback, state); Thread thread = new Thread(ProcessRequest); thread.Start(); return(asyncResult); }
public override WebResponse EndGetResponse(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException("AsyncResult cannot be null!"); } if (!(asyncResult is FtpAsyncResult) || asyncResult != this.asyncResult) { throw new ArgumentException("AsyncResult is from another request!"); } FtpAsyncResult asyncFtpResult = (FtpAsyncResult)asyncResult; if (!asyncFtpResult.WaitUntilComplete(timeout, false)) { Abort(); throw new WebException("Transfer timed out.", WebExceptionStatus.Timeout); } CheckIfAborted(); asyncResult = null; if (asyncFtpResult.GotException) { throw asyncFtpResult.Exception; } return(asyncFtpResult.Response); }
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state) { if (asyncResult != null && !asyncResult.IsCompleted) { throw new InvalidOperationException("Cannot re-call BeginGetRequestStream/BeginGetResponse while a previous call is still in progress"); } CheckIfAborted(); asyncResult = new FtpAsyncResult(callback, state); lock (locker) { if (InFinalState()) { asyncResult.SetCompleted(true, ftpResponse); } else { if (State == RequestState.Before) { State = RequestState.Scheduled; } Thread thread = new Thread(ProcessRequest); thread.Start(); } } return(asyncResult); }
public override Stream EndGetRequestStream(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } if (!(asyncResult is FtpAsyncResult)) { throw new ArgumentException("asyncResult"); } if (State == RequestState.Aborted) { throw new WebException("Request aborted", WebExceptionStatus.RequestCanceled); } if (asyncResult != this.asyncResult) { throw new ArgumentException("AsyncResult is from another request!"); } FtpAsyncResult res = (FtpAsyncResult)asyncResult; if (!res.WaitUntilComplete(timeout, false)) { Abort(); throw new WebException("Request timed out"); } if (res.GotException) { throw res.Exception; } return(res.Stream); }
public override IAsyncResult BeginGetRequestStream (AsyncCallback callback, object state) { if (method != WebRequestMethods.Ftp.UploadFile && method != WebRequestMethods.Ftp.UploadFileWithUniqueName && method != WebRequestMethods.Ftp.AppendFile) throw new ProtocolViolationException (); lock (locker) { CheckIfAborted (); if (State != RequestState.Before) throw new InvalidOperationException ("Cannot re-call BeginGetRequestStream/BeginGetResponse while a previous call is still in progress"); State = RequestState.Scheduled; } asyncResult = new FtpAsyncResult (callback, state); Thread thread = new Thread (ProcessRequest); thread.Start (); return asyncResult; }
public override WebResponse EndGetResponse (IAsyncResult asyncResult) { if (asyncResult == null) throw new ArgumentNullException ("AsyncResult cannot be null!"); if (!(asyncResult is FtpAsyncResult) || asyncResult != this.asyncResult) throw new ArgumentException ("AsyncResult is from another request!"); FtpAsyncResult asyncFtpResult = (FtpAsyncResult) asyncResult; if (!asyncFtpResult.WaitUntilComplete (timeout, false)) { Abort (); throw new WebException ("Transfer timed out.", WebExceptionStatus.Timeout); } CheckIfAborted (); asyncResult = null; if (asyncFtpResult.GotException) throw asyncFtpResult.Exception; return asyncFtpResult.Response; }
public override IAsyncResult BeginGetResponse (AsyncCallback callback, object state) { if (asyncResult != null && !asyncResult.IsCompleted) { throw new InvalidOperationException ("Cannot re-call BeginGetRequestStream/BeginGetResponse while a previous call is still in progress"); } CheckIfAborted (); asyncResult = new FtpAsyncResult (callback, state); lock (locker) { if (InFinalState ()) asyncResult.SetCompleted (true, ftpResponse); else { if (State == RequestState.Before) State = RequestState.Scheduled; Thread thread = new Thread (ProcessRequest); thread.Start (); } } return asyncResult; }