Beispiel #1
0
        private void WebSocketMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            Debug.WriteLine($"<<< {e.Message}");
            var prop = JsonRpcResponse.FromString(e.Message, _jsonSerializerSettings);

            lock (_manualResetEventDictionary)
            {
                if (!_manualResetEventDictionary.ContainsKey(prop.Id))
                {
                    return;
                }

                lock (_responseDictionary)
                {
                    if (_responseDictionary.ContainsKey(prop.Id))
                    {
                        _responseDictionary[prop.Id] = prop;
                    }
                    else
                    {
                        _responseDictionary.Add(prop.Id, prop);
                    }
                }
                _manualResetEventDictionary[prop.Id].Set();
            }
        }
        public JsonRpcResponse Execute(JsonRpcRequest jsonRpc, CancellationToken token)
        {
            SendData(Socket, jsonRpc.Message);
            var responce = ReceiveData(Socket);
            var prop     = JsonRpcResponse.FromString(responce, _jsonSerializerSettings);

            return(prop);
        }
Beispiel #3
0
        public JsonRpcResponse Execute(JsonRpcRequest jsonRpc, CancellationToken token)
        {
            if (string.IsNullOrEmpty(_url))
            {
                return(null);
            }

            var content  = new StringContent(jsonRpc.Message);
            var response = _client.PostAsync(_url, content, token).Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var stringResponse = response.Content.ReadAsStringAsync().Result;
                var prop           = JsonRpcResponse.FromString(stringResponse, _jsonSerializerSettings);
                return(prop);
            }

            return(new JsonRpcResponse {
                Error = new HttpResponseError((int)response.StatusCode, "Http Error")
            });
        }