private void Transport_OnStateChanged(TransportStates oldState, TransportStates newState) { HTTPManager.Logger.Verbose("HubConnection", string.Format("Transport_OnStateChanged - oldState: {0} newState: {1}", oldState.ToString(), newState.ToString())); switch (newState) { case TransportStates.Connected: this.State = ConnectionStates.Connected; if (this.OnConnected != null) { this.OnConnected(this); } break; case TransportStates.Failed: this.State = ConnectionStates.Closed; if (this.OnError != null) { this.OnError(this, this.Transport.ErrorReason); } break; case TransportStates.Closed: this.State = ConnectionStates.Closed; if (this.OnClosed != null) { this.OnClosed(this); } break; } }
private void Transport_OnStateChanged(TransportStates oldState, TransportStates newState) { HTTPManager.Logger.Verbose("HubConnection", string.Format("Transport_OnStateChanged - oldState: {0} newState: {1}", oldState.ToString(), newState.ToString())); if (this.State == ConnectionStates.Closed) { HTTPManager.Logger.Verbose("HubConnection", "Transport_OnStateChanged - already closed!"); return; } switch (newState) { case TransportStates.Connected: try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.Connected); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } SetState(ConnectionStates.Connected); break; case TransportStates.Failed: if (this.State == ConnectionStates.Negotiating) { try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.FailedToConnect); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } this.triedoutTransports.Add(this.Transport.TransportType); var nextTransport = GetNextTransportToTry(); if (nextTransport == null) { SetState(ConnectionStates.Closed, this.Transport.ErrorReason); } else { ConnectImpl(nextTransport.Value); } } else { try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.ClosedWithError); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } SetState(ConnectionStates.Closed, this.Transport.ErrorReason); } break; case TransportStates.Closed: { try { if (this.OnTransportEvent != null) { this.OnTransportEvent(this, this.Transport, TransportEvents.Closed); } } catch (Exception ex) { HTTPManager.Logger.Exception("HubConnection", "Exception in OnTransportEvent user code!", ex); } SetState(ConnectionStates.Closed); } break; } }
private void Transport_OnStateChanged(TransportStates oldState, TransportStates newState) { HTTPManager.Logger.Verbose("HubConnection", string.Format("Transport_OnStateChanged - oldState: {0} newState: {1}", oldState.ToString(), newState.ToString())); switch (newState) { case TransportStates.Connected: SetState(ConnectionStates.Connected); break; case TransportStates.Failed: SetState(ConnectionStates.Closed, this.Transport.ErrorReason); break; case TransportStates.Closed: SetState(ConnectionStates.Closed); break; } }