示例#1
0
        private async Task StartReceivingMessagesAsync(CancellationToken ct)
        {
            // Receive messages
            while (!ct.IsCancellationRequested)
            {
                try
                {
                    var str = await _transport.ReceiveAsync().ConfigureAwait(false);

                    var respCmd = ResponseCommand.FromString(str);

                    if (LogRawCommands)
                    {
                        _logger?.LogInformation(str);
                    }

                    if (!_commandsToActions.TryGetValue(respCmd.Command, out var actionCommand))
                    {
                        _logger?.LogInformation($"Command '{respCmd.RawCommand}' is not a response command, skipping it");
                        continue;
                    }

                    actionCommand(respCmd);
                }
                catch (Exception e)
                {
                    _logger?.LogError(e, "Unexpected error");
                }
            }
        }
示例#2
0
        private async Task <Message> ReceiveMessageAsync(CancellationToken ct)
        {
            var sb = new StringBuilder();

            string json;

            try {
                json = await _transport.ReceiveAsync(ct);
            } catch (MessageTransportException ex) when(ct.IsCancellationRequested)
            {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            }

            _log.Response(json, _rLoopDepth);

            var token = JToken.Parse(json);

            var value = token as JValue;

            if (value != null && value.Value == null)
            {
                return(null);
            }

            return(new Message(token));
        }
示例#3
0
        private async Task <Message> ReceiveMessageAsync(CancellationToken ct)
        {
            Message message;

            try {
                message = await _transport.ReceiveAsync(ct);
            } catch (MessageTransportException ex) when(ct.IsCancellationRequested)
            {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            }

            _log.Response(message.ToString(), _rLoopDepth);
            return(message);
        }