Exemplo n.º 1
0
        private async Task ProcessConnectionAsync(object state)
        {
            var transportConnection = (ITransportConnection)state;

            Log.Debug("Accepting new incoming connection {0}", transportConnection.Id);
            var appConnectionDescriptor = await _authenticationHandler.AuthenticateAsync(transportConnection).ConfigureAwait(false);

            Log.Debug("New connection authenticated: {0}", appConnectionDescriptor);
            var clientConnection = _appLifecycleManager.AcceptConnection(transportConnection, appConnectionDescriptor);

            try
            {
                Log.Info("New connection accepted: {0}", clientConnection);
                var clientConnectionProcessor = new AppConnectionProcessor(clientConnection, _clientRequestHandler);
                await clientConnectionProcessor.ProcessAsync(() => _appLifecycleManager.TryRemoveConnection(clientConnection)).ConfigureAwait(false);
            }
            finally
            {
                _appLifecycleManager.TryRemoveConnection(clientConnection);
            }
        }