Exemple #1
0
        private void DataReceived(string data)
        {
            var request = Serialization.FromJson <RpcMessage>(data);

            if (request.Id != null && string.IsNullOrEmpty(request.Method))
            {
                // Response
                requestResponses.TryAdd(request.Id.Value, data);
            }
            else if (request.Id != null && !string.IsNullOrEmpty(request.Method))
            {
                // Request
                RequestReceived?.BeginInvoke(this, new JsonRpcRequestEventArgs()
                {
                    Request = Serialization.FromJson <JsonRpcRequest>(data)
                }, EventEndCallback <JsonRpcRequestEventArgs>, null);
            }
            else if (request.Id == null)
            {
                // Notification
                NotificationReceived?.BeginInvoke(this, new JsonRpcNotificationEventArgs()
                {
                    Notification = Serialization.FromJson <JsonRpcNotification>(data)
                }, EventEndCallback <JsonRpcNotificationEventArgs>, null);
            }
            else
            {
                logger.Error("Recevied invalid RPC message:");
                logger.Error(data);
            }
        }
Exemple #2
0
        public TResult SendRequest <TResult>(string method, object parameters) where TResult : class
        {
            var request     = new JsonRpcRequest(method, parameters);
            var strResponse = SendRpcRequest(request.Id.Value, Serialization.ToJson(request));
            var response    = Serialization.FromJson <JsonRpcResponse <TResult> >(strResponse);

            if (response.Error != null)
            {
                throw new JsonRpcException(response.Error.Code, response.Error.Message);
            }
            else
            {
                return(response.Result);
            }
        }
 public T FromJson <T>(string json) where T : class
 {
     return(Serialization.FromJson <T>(json));
 }
Exemple #4
0
 public TParams GetParams <TParams>() where TParams : class
 {
     return(Serialization.FromJson <TParams>(Params.ToString()));
 }