internal void SendCommandAsync(string command, AsyncCallback readCallback, DataCommunicator.GetCommandResponseDelegate responseDelegate, object callerArguments) { if (this.dataStream == null) { return; } DataCommunicator.State state = new DataCommunicator.State(); state.ReadDataCallback = readCallback; state.ResponseDelegate = responseDelegate; state.CallerArguments = callerArguments; state.DataStream = this.dataStream; try { this.StartTimer(); byte[] bytes = Encoding.ASCII.GetBytes(command); this.dataStream.BeginWrite(bytes, 0, bytes.Length, new AsyncCallback(this.SendDataCallback), state); } catch (IOException exception) { this.HandleException(exception); } catch (InvalidOperationException exception2) { this.HandleException(exception2); } }
private void MultiLineResponseCallback(IAsyncResult asyncResult) { DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState; try { int num = state.DataStream.EndRead(asyncResult); if (num > 0) { state.AppendReceivedData(num); if (!this.LastLineReceived(state.Response)) { state.BeginRead(); return; } } } catch (InvalidOperationException exception) { if (base.Communicator.HasTimedOut) { base.Communicator.HandleException(DataCommunicator.CreateTimeoutException()); return; } base.Communicator.HandleException(exception); } catch (IOException exception2) { base.Communicator.HandleException(exception2); return; } base.Communicator.StopTimer(); state.LaunchResponseDelegate(); }
protected void SingleLineResponseCallback(IAsyncResult asyncResult) { DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState; try { int num = state.DataStream.EndRead(asyncResult); if (num > 0) { state.AppendReceivedData(num); if (!state.Response.EndsWith("\r\n", StringComparison.Ordinal)) { state.BeginRead(); } } this.Communicator.StopTimer(); state.LaunchResponseDelegate(); } catch (InvalidOperationException exception) { if (this.Communicator.HasTimedOut) { this.Communicator.HandleException(DataCommunicator.CreateTimeoutException()); } else { this.Communicator.HandleException(exception); } } catch (IOException exception2) { this.Communicator.HandleException(exception2); } }
private void InitializeSecureStreamAsyncCallback(IAsyncResult asyncResult) { DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState; try { SslStream sslStream = (SslStream)state.DataStream; sslStream.EndAuthenticateAsClient(asyncResult); if (this.connectionType == ProtocolConnectionType.Ssl) { state.BeginRead(); } else { state.LaunchResponseDelegate(); } } catch (IOException ex) { this.HandleException(new ProtocolException(Strings.ErrorAuthenticationFailed(ex.Message) + Strings.InitializeServerResponse(string.IsNullOrEmpty(state.Response) ? string.Empty : state.Response), ex)); } catch (InvalidOperationException innerException) { this.HandleException(new ProtocolException(Strings.ErrorAuthentication + Strings.InitializeServerResponse(string.IsNullOrEmpty(state.Response) ? string.Empty : state.Response), innerException)); } catch (AuthenticationException innerException2) { this.HandleException(new ProtocolException(Strings.ErrorAuthenticationFailed(this.certificateError) + Strings.InitializeServerResponse(string.IsNullOrEmpty(state.Response) ? string.Empty : state.Response), innerException2)); } }
private void InitializeSecureStreamAsync(DataCommunicator.State state) { if (this.dataStream == null) { return; } try { SslStream sslStream = new SslStream(this.dataStream, false, new RemoteCertificateValidationCallback(this.ValidateServerCertificate), null); state.DataStream = sslStream; this.dataStream = sslStream; this.StartTimer(); sslStream.BeginAuthenticateAsClient(this.serverName, new AsyncCallback(this.InitializeSecureStreamAsyncCallback), state); } catch (InvalidOperationException exception) { this.HandleException(exception); } catch (IOException ex) { this.HandleException(new ProtocolException(Strings.ErrorAuthenticationFailed(ex.Message) + Strings.InitializeServerResponse(string.IsNullOrEmpty(state.Response) ? string.Empty : state.Response), ex)); } catch (AuthenticationException innerException) { this.HandleException(new ProtocolException(Strings.ErrorAuthenticationFailed(this.certificateError) + Strings.InitializeServerResponse(string.IsNullOrEmpty(state.Response) ? string.Empty : state.Response), innerException)); } }
private void ConnectAsyncCallback(IAsyncResult asyncResult) { try { this.tcpClient.EndConnect(asyncResult); DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState; this.dataStream = this.tcpClient.GetStream(); state.DataStream = this.dataStream; if (this.connectionType == ProtocolConnectionType.Ssl) { this.InitializeSecureStreamAsync(state); } else { this.ReadResponseAsync(state); } } catch (InvalidOperationException exception) { this.HandleException(exception); } catch (SocketException exception2) { this.HandleException(exception2); } catch (IOException exception3) { this.HandleException(exception3); } }
internal void MultiLineResponseCallback(IAsyncResult asyncResult) { DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState; try { int num = state.DataStream.EndRead(asyncResult); if (num > 0) { state.AppendReceivedData(num); if (!PopClient.IsOkResponse(state.Response)) { if (!state.Response.EndsWith("\r\n", StringComparison.Ordinal)) { state.ReadDataCallback = new AsyncCallback(base.SingleLineResponseCallback); state.BeginRead(); return; } } else { bool flag = false; if (!state.Response.EndsWith("\r\n.\r\n", StringComparison.Ordinal)) { flag = true; } if (flag) { state.BeginRead(); return; } } } } catch (InvalidOperationException exception) { if (base.Communicator.HasTimedOut) { base.Communicator.HandleException(DataCommunicator.CreateTimeoutException()); return; } base.Communicator.HandleException(exception); } catch (IOException exception2) { base.Communicator.HandleException(exception2); return; } base.Communicator.StopTimer(); state.LaunchResponseDelegate(); }
internal void ReadResponseAsync(AsyncCallback readCallback, DataCommunicator.GetCommandResponseDelegate responseDelegate, object callerArguments) { if (this.dataStream == null) { return; } DataCommunicator.State state = new DataCommunicator.State(); state.ReadDataCallback = readCallback; state.ResponseDelegate = responseDelegate; state.CallerArguments = callerArguments; state.DataStream = this.dataStream; this.StartTimer(); this.ReadResponseAsync(state); }
private void ReadResponseAsync(DataCommunicator.State state) { try { state.BeginRead(); } catch (InvalidOperationException exception) { this.HandleException(exception); } catch (IOException exception2) { this.HandleException(exception2); } }
internal void ConnectAsync(AsyncCallback readCallback, DataCommunicator.GetCommandResponseDelegate responseDelegate, object callerArguments) { DataCommunicator.State state = new DataCommunicator.State(); state.ResponseDelegate = responseDelegate; state.ReadDataCallback = readCallback; state.CallerArguments = callerArguments; try { this.tcpClient = new TcpClient(); } catch (SocketException exception) { this.HandleException(exception); } this.StartTimer(); this.tcpClient.BeginConnect(this.serverName, this.port, new AsyncCallback(this.ConnectAsyncCallback), state); }
private void SendDataCallback(IAsyncResult asyncResult) { DataCommunicator.State state = (DataCommunicator.State)asyncResult.AsyncState; try { state.DataStream.EndWrite(asyncResult); if (this.dataStream != null) { this.ReadResponseAsync(state); } } catch (InvalidOperationException exception) { this.HandleException(exception); } catch (IOException exception2) { this.HandleException(exception2); } }