Пример #1
0
 public async Task <TResult> Call <TResult>(JrpcClientCallParams clientCallParams)
 {
     return(await InvokeRequest <TResult>(clientCallParams).ConfigureAwait(false));
 }
Пример #2
0
        private async Task <T> InvokeRequest <T>(JrpcClientCallParams clientCallParams)
        {
            var id = Guid.NewGuid().ToString();

            var request = new JRpcRequest {
                Id     = id,
                Method = clientCallParams.MethodName,
                Params = clientCallParams.ParametersStr,
            };
            var serviceInfos       = JrpcRegistredServices.GetAllInfo();
            var currentServiceInfo = serviceInfos.FirstOrDefault();

            string clientServiceName      = currentServiceInfo.Key;
            string clientServiceProxyName = currentServiceInfo.Value?.FirstOrDefault();

            _logger.Log(new LogEventInfo {
                Level      = LogLevel.Trace,
                LoggerName = _logger.Name,
                Message    = "Request for {0}.{1} with ID {2} sent.",
                Parameters = new object[] { clientCallParams.ServiceName, clientCallParams.MethodName, id },
                Properties =
                {
                    { "service",            clientCallParams.ServiceName        },
                    { "method",             clientCallParams.MethodName         },
                    { "requestId",          id                                  },
                    { "process",            ProcessName                         },
                    { "currentIp",          CurrentIp                           },
                    { "proxyTypeName",      clientCallParams.ProxyType.FullName },
                    { "currentServiceName", clientServiceName                   },
                    { "currentProxyName",   clientServiceProxyName              }
                }
            });
            var watch        = Stopwatch.StartNew();
            var jsonresponse = await HttpAsyncRequest <T>(METHOD, "application/json",
                                                          GetEndPoint(clientCallParams.ServiceName), request,
                                                          _timeout, clientCallParams.Credentials, clientCallParams.ProxyType, clientServiceName, clientServiceProxyName).ConfigureAwait(false);

            var elaspedMs = watch.ElapsedMilliseconds;

            _logger.Log(new LogEventInfo {
                Level      = LogLevel.Debug,
                LoggerName = _logger.Name,
                Message    = "Response for {0}.{1} with ID {2} received.",
                Parameters = new[] { clientCallParams.ServiceName, clientCallParams.MethodName, jsonresponse.Id },
                Properties =
                {
                    { "service",            clientCallParams.ServiceName               },
                    { "method",             clientCallParams.MethodName                },
                    { "requestId",          jsonresponse.Id                            },
                    { "process",            ProcessName                                },
                    { "currentIp",          CurrentIp                                  },
                    { "proxyTypeName",      clientCallParams.ProxyType.FullName        },
                    { "status",             jsonresponse.Error != null ? "fail" : "ok" },
                    { "source",             "client"                                   },
                    { "currentServiceName", clientServiceName                          },
                    { "currentProxyName",   clientServiceProxyName                     },
                    { "clientRequestTime",  elaspedMs                                  }
                }
            });

            if (jsonresponse.Error != null)
            {
                throw jsonresponse.Error;
            }

            var result = jsonresponse.Result;

            if (result == null)
            {
                return(default(T));
            }

            return(result);
        }
Пример #3
0
 //NOTE: НЕ УДАЛЯТЬ, т.к. используется рефлексией
 public static object Invoke <TResult>(
     IJRpcClient client,
     JrpcClientCallParams clientCallParams)
 {
     return(client.Call <TResult>(clientCallParams));
 }