private void _pusher_ConnectionStateChanged(object sender, ConnectionState state) { _loggingService.WriteInformation($"Pusher is {state}"); try { if (state == ConnectionState.WaitingToReconnect) { _connectionAttempts++; if (_connectionAttempts >= 5) { _connectionAttempts = 0; ConnectionFailedEvent?.Invoke(); } } else if (state == ConnectionState.Connected) { _connectionAttempts = 0; } } catch (Exception e) { _loggingService.WriteInformation($"Error handling the pusher '{state}' state. {e}"); } }
public async Task WhenKeyUnknown_ThenErrorIsShownAndWindowIsClosed( [LinuxInstance] ResourceTask <InstanceLocator> instanceLocatorTask) { var instanceLocator = await instanceLocatorTask; using (var key = new RsaSshKey(new RSACng())) { ConnectionFailedEvent deliveredEvent = null; this.eventService.BindHandler <ConnectionFailedEvent>(e => deliveredEvent = e); var broker = new SshTerminalConnectionBroker( this.serviceProvider); await broker.ConnectAsync( instanceLocator, new IPEndPoint(await PublicAddressFromLocator(instanceLocator), 22), AuthorizedKey.ForMetadata(key, "test", true, null)) .ConfigureAwait(true); Assert.IsNotNull(deliveredEvent, "Event fired"); Assert.IsInstanceOf(typeof(SshNativeException), this.ExceptionShown); Assert.AreEqual( LIBSSH2_ERROR.AUTHENTICATION_FAILED, ((SshNativeException)this.ExceptionShown).ErrorCode); } }
public async Task WhenWrongPort_ThenErrorIsShownAndWindowIsClosed() { using (var key = new RsaSshKey(new RSACng())) { ConnectionFailedEvent deliveredEvent = null; this.eventService.BindHandler <ConnectionFailedEvent>(e => deliveredEvent = e); var broker = new SshTerminalConnectionBroker( this.serviceProvider); await broker.ConnectAsync( new InstanceLocator("project-1", "zone-1", "instance-1"), NonSshEndpoint, AuthorizedKey.ForMetadata(key, "test", true, null)) .ConfigureAwait(true); Assert.IsNotNull(deliveredEvent, "Event fired"); Assert.IsInstanceOf(typeof(SocketException), this.ExceptionShown); Assert.AreEqual( SocketError.ConnectionRefused, ((SocketException)this.ExceptionShown).SocketErrorCode); } }
// Connections public override void ConnectionFailed(ConnectionFailedEvent @event) { Log(LogLevel.Error, "{0}: failed. Exception: {1}", Label(@event.ConnectionId), @event.Exception); }
public static void InvokeConnectionFailedEvent(ConnectionFailedEventArgs args) { ConnectionFailedEvent?.Invoke(args); }
private void Handle(ConnectionFailedEvent @event) { Error(TraceSourceEventHelper.ConnectionIdBase + 5, @event.Exception, "{0}: failed.", TraceSourceEventHelper.Label(@event.ConnectionId)); }
public void ConnectionFailed(ConnectionFailedEvent @event) { }