示例#1
0
        public async Task<JsonRpcResponse> SendRequestAsync(JsonRpcRequest jsonRpcRequest)
        {
            Debug.Assert(jsonRpcRequest != null && jsonRpcRequest.Id != null && jsonRpcRequest.Id != String.Empty);

            JTokenStreamContent streamContent = new JTokenStreamContent(JToken.FromObject(jsonRpcRequest));
            TaskCompletionSource<JsonRpcResponse> sendJsonRpcRequestTask = new TaskCompletionSource<JsonRpcResponse>(jsonRpcRequest);
            _outgoingJsonRpcRequests.Enqueue(streamContent);
            _incompleteJsonRpcRequests.AddOrUpdate(jsonRpcRequest.Id, sendJsonRpcRequestTask, (k, v) =>
            {
                Debug.Assert(false, "Should not send requests with the same id.");
                return sendJsonRpcRequestTask;
            });
            return await sendJsonRpcRequestTask.Task;
        }
示例#2
0
        public void SendNotificationAsync(JsonRpcRequest jsonRpcRequest)
        {
            Debug.Assert(jsonRpcRequest != null && jsonRpcRequest.Id != null && jsonRpcRequest.Id != String.Empty);
            Debug.Assert(jsonRpcRequest.IsNotification == true);

            JTokenStreamContent streamContent = new JTokenStreamContent(JToken.FromObject(jsonRpcRequest));
            _outgoingJsonRpcRequests.Enqueue(streamContent);
        }