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); } }
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; } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }