コード例 #1
0
        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}");
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
 // Connections
 public override void ConnectionFailed(ConnectionFailedEvent @event)
 {
     Log(LogLevel.Error, "{0}: failed. Exception: {1}", Label(@event.ConnectionId), @event.Exception);
 }
コード例 #5
0
 public static void InvokeConnectionFailedEvent(ConnectionFailedEventArgs args)
 {
     ConnectionFailedEvent?.Invoke(args);
 }
コード例 #6
0
 private void Handle(ConnectionFailedEvent @event)
 {
     Error(TraceSourceEventHelper.ConnectionIdBase + 5, @event.Exception, "{0}: failed.", TraceSourceEventHelper.Label(@event.ConnectionId));
 }
コード例 #7
0
 public void ConnectionFailed(ConnectionFailedEvent @event)
 {
 }