public async Task ReceiveAsync(byte[] data)
        {
            JsonRpcResult result = await _jsonRpcProcessor.ProcessAsync(Encoding.UTF8.GetString(data));

            if (result.IsCollection)
            {
                await SendRawAsync(_jsonSerializer.Serialize(result.Responses));
            }
            else
            {
                await SendRawAsync(_jsonSerializer.Serialize(result.Response));
            }
        }
        public async Task ExecuteAsync(IWebSocketsClient client, byte[] data)
        {
            var result = await _jsonRpcProcessor.ProcessAsync(Encoding.UTF8.GetString(data));

            if (result.IsCollection)
            {
                await client.SendAsync(_jsonSerializer.Serialize(result.Responses));

                return;
            }

            await client.SendAsync(_jsonSerializer.Serialize(result.Responses.SingleOrDefault()));
        }
        public async Task ReceiveAsync(byte[] data)
        {
            var result = await _jsonRpcProcessor.ProcessAsync(Encoding.UTF8.GetString(data));

            if (result.IsCollection)
            {
                await SendRawAsync(_jsonSerializer.Serialize(result.Responses));

                return;
            }

            await SendRawAsync(_jsonSerializer.Serialize(result.Responses.SingleOrDefault()));
        }
Beispiel #4
0
        public async Task ReceiveAsync(Memory <byte> data)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            using JsonRpcResult result = await _jsonRpcProcessor.ProcessAsync(Encoding.UTF8.GetString(data.Span), _jsonRpcContext);

            await SendJsonRpcResult(result);

            if (result.IsCollection)
            {
                _jsonRpcLocalStats.ReportCalls(result.Reports);
                _jsonRpcLocalStats.ReportCall(new RpcReport("# collection serialization #", stopwatch.ElapsedMicroseconds(), true));
            }
            else
            {
                _jsonRpcLocalStats.ReportCall(result.Report, stopwatch.ElapsedMicroseconds());
            }
        }
Beispiel #5
0
        public async Task ReceiveAsync(Memory <byte> data)
        {
            string SerializeTimeoutException()
            {
                JsonRpcErrorResponse error = _jsonRpcService.GetErrorResponse(ErrorCodes.Timeout, "Request was canceled due to enabled timeout.");

                return(_jsonSerializer.Serialize(error));
            }

            Stopwatch stopwatch = Stopwatch.StartNew();

            using JsonRpcResult result = await _jsonRpcProcessor.ProcessAsync(Encoding.UTF8.GetString(data.ToArray()));

            string resultData;

            try
            {
                resultData = result.IsCollection ? _jsonSerializer.Serialize(result.Responses) : _jsonSerializer.Serialize(result.Response);
            }
            catch (Exception e) when(e.InnerException is OperationCanceledException)
            {
                resultData = SerializeTimeoutException();
            }
            catch (OperationCanceledException)
            {
                resultData = SerializeTimeoutException();
            }

            await SendRawAsync(resultData);

            if (result.IsCollection)
            {
                _jsonRpcLocalStats.ReportCalls(result.Reports);
                _jsonRpcLocalStats.ReportCall(new RpcReport("# collection serialization #", stopwatch.ElapsedMicroseconds(), true));
            }
            else
            {
                _jsonRpcLocalStats.ReportCall(result.Report, stopwatch.ElapsedMicroseconds());
            }
        }
Beispiel #6
0
        public async Task ReceiveAsync(Memory <byte> data)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();

            Interlocked.Add(ref Metrics.JsonRpcBytesReceivedWebSockets, data.Length);
            using JsonRpcResult result = await _jsonRpcProcessor.ProcessAsync(Encoding.UTF8.GetString(data.Span), _jsonRpcContext);

            var size = await SendJsonRpcResult(result);

            long handlingTimeMicroseconds = stopwatch.ElapsedMicroseconds();

            if (result.IsCollection)
            {
                _jsonRpcLocalStats.ReportCalls(result.Reports);
                _jsonRpcLocalStats.ReportCall(new RpcReport("# collection serialization #", handlingTimeMicroseconds, true), handlingTimeMicroseconds, size);
            }
            else
            {
                _jsonRpcLocalStats.ReportCall(result.Report, handlingTimeMicroseconds, size);
            }

            Interlocked.Add(ref Metrics.JsonRpcBytesSentWebSockets, data.Length);
        }
        public async Task Can_process_guid_ids()
        {
            JsonRpcResult result = await _jsonRpcProcessor.ProcessAsync("{\"id\":\"840b55c4-18b0-431c-be1d-6d22198b53f2\",\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionCount\",\"params\":[\"0x7f01d9b227593e033bf8d6fc86e634d27aa85568\",\"0x668c24\"]}");

            Assert.AreEqual("840b55c4-18b0-431c-be1d-6d22198b53f2", result.Response.Id);
        }
Beispiel #8
0
        public async Task DateTimeCall()
        {
            var request = @"{'jsonrpc': '2.0', 'method': 'dateTimeMethod', 'params': [], 'id': 1}";
            var resp    = await processor.ProcessAsync(request);

            var response = JObject.Parse(resp);
        }