Example #1
0
        private void AddClientConnection(ClientConnectionContext connection, OpenConnectionMessage message)
        {
            var instanceId = GetInstanceId(message.Headers);

            _clientConnectionManager.TryAddClientConnection(connection);
            _connectionIds.TryAdd(connection.ConnectionId, instanceId);
        }
Example #2
0
        protected override Task OnClientConnectedAsync(OpenConnectionMessage openConnectionMessage)
        {
            // Create empty transport with only channel for async processing messages
            var connectionId  = openConnectionMessage.ConnectionId;
            var clientContext = new ClientConnectionContext(this, connectionId, GetInstanceId(openConnectionMessage.Headers));

            bool isDiagnosticClient = false;

            openConnectionMessage.Headers.TryGetValue(Constants.AsrsIsDiagnosticClient, out var isDiagnosticClientValue);
            if (!StringValues.IsNullOrEmpty(isDiagnosticClientValue))
            {
                isDiagnosticClient = Convert.ToBoolean(isDiagnosticClientValue.FirstOrDefault());
            }

            // todo: ignore asp.net for now
            using (new ClientConnectionScope(outboundConnection: this, isDiagnosticClient: isDiagnosticClient))
            {
                if (_clientConnectionManager.TryAddClientConnection(clientContext))
                {
                    _clientConnections.TryAdd(connectionId, clientContext);
                    clientContext.ApplicationTask = ProcessMessageAsync(clientContext, clientContext.CancellationToken);
                    return(ForwardMessageToApplication(connectionId, openConnectionMessage));
                }
                else
                {
                    // the manager still contains this connectionId, probably this connection is not yet cleaned up
                    Log.DuplicateConnectionId(Logger, connectionId, null);
                    return(SafeWriteAsync(
                               new CloseConnectionMessage(connectionId, $"Duplicate connection ID {connectionId}")));
                }
            }
        }