Exemplo n.º 1
0
        public async Task <TRPCResponseMessage> Invoke(TRPCRequestMessage requestMessage)
        {
            using (var httpClient = new HttpClient())
            {
                string message = JsonConvert.SerializeObject(requestMessage, _settings);
                using (var result = await httpClient.PostAsync(
                           URL,
                           new StringContent(
                               message,
                               Encoding.UTF8,
                               "application/json"
                               )
                           ))
                {
                    string resultContent = await result.Content.ReadAsStringAsync();

                    var responseMessage = JsonConvert.DeserializeObject <TRPCResponseMessage>(resultContent, _settings);
                    if (!responseMessage.IsSuccess)
                    {
                        throw RPCException.Create(responseMessage.Error.Code, responseMessage.Error.Message);
                    }
                    return(responseMessage);
                }
            }
        }
Exemplo n.º 2
0
        public static RPCException Create(int code, string message)
        {
            if (_exceptionTypes.TryGetValue(code, out Type type))
            {
                RPCException exception = (RPCException)Activator.CreateInstance(type, code, message);
                return(exception);
            }

            return(new RPCException(code, message));
        }