Exemplo n.º 1
0
        private async Task RunHubAsync(HubConnectionContext connection)
        {
            try
            {
                await _dispatcher.OnConnectedAsync(connection);
            }
            catch (Exception ex)
            {
                Log.ErrorDispatchingHubEvent(_logger, "OnConnectedAsync", ex);

                // The client shouldn't try to reconnect given an error in OnConnected.
                await SendCloseAsync(connection, ex, allowReconnect : false);

                // return instead of throw to let close message send successfully
                return;
            }

            try
            {
                await DispatchMessagesAsync(connection);
            }
            catch (OperationCanceledException)
            {
                // Don't treat OperationCanceledException as an error, it's basically a "control flow"
                // exception to stop things from running
            }
            catch (Exception ex)
            {
                Log.ErrorProcessingRequest(_logger, ex);

                await HubOnDisconnectedAsync(connection, ex);

                // return instead of throw to let close message send successfully
                return;
            }

            await HubOnDisconnectedAsync(connection, connection.CloseException);
        }
Exemplo n.º 2
0
 public override async Task OnConnectedAsync(HubConnectionContext connection)
 {
     using (BeginScope()) await decorated.OnConnectedAsync(connection);
 }