private T DoSend <T>(RSharp.Method method, object body)
        {
            _request.AddParameter(
                "application/json",
                Newtonsoft.Json.JsonConvert.SerializeObject(body),
                ParameterType.RequestBody);

            _request.Timeout = 100000; // ms

            var response = _restClient.Execute(_request, method);

            if (response.IsSuccessful)
            {
                return(Deserialize <T>(response));
            }

            if (response.StatusCode == 0 && response.ErrorMessage.Contains("Section=ResponseStatusLine"))
            {
                return(Deserialize <T>(response));
            }

            if (response.ErrorException != null)
            {
                throw RestClientFactory.CreateErrorException(_restClient, response);
            }

            throw RestClientFactory.CreateFailedException(_restClient, response);
        }
 private T Deserialize <T>(IRestResponse response)
 {
     try
     {
         return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(response.Content));
     }
     catch (Exception ex)
     {
         throw RestClientFactory.CreateErrorException(_restClient, response, ex);
     }
 }
Exemple #3
0
 private T Deserialize <T>(HttpResponseMessage response)
 {
     try
     {
         var json = response.Content.ReadAsStringAsync().Result;
         return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(json));
     }
     catch (Exception ex)
     {
         //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " ERROR: " + _request.ToRestClientRequest(_restClient.BaseAddress).ToString(), FILE_LOG);
         //Logging.WriteToFileThreadSafe(DateTime.Now.ToString("o") + " EXCEP: " + ex.Message, FILE_LOG);
         throw RestClientFactory.CreateErrorException(_restClient, response, ex);
     }
 }
        private T DoSend <T>(RSharp.Method method)
        {
            var response = _restClient.Execute(_request, method);

            if (response.IsSuccessful)
            {
                return(Deserialize <T>(response));
            }

            if (response.ErrorException != null)
            {
                throw RestClientFactory.CreateErrorException(_restClient, response);
            }

            throw RestClientFactory.CreateFailedException(_restClient, response);
        }
        private void DoSend(RSharp.Method method, object body)
        {
            _request.AddParameter(
                "application/json",
                Newtonsoft.Json.JsonConvert.SerializeObject(body),
                ParameterType.RequestBody);

            var response = _restClient.Execute(_request, method);

            if (response.ErrorException != null)
            {
                throw RestClientFactory.CreateErrorException(_restClient, response);
            }

            if (!response.IsSuccessful)
            {
                throw RestClientFactory.CreateFailedException(_restClient, response);
            }
        }
        private T DoSend <T>(RSharp.Method method)
        {
            _request.Timeout = 100000; // ms

            var response = _restClient.Execute(_request, method);

            if (response.IsSuccessful)
            {
                return(Deserialize <T>(response));
            }

            if (response.StatusCode == 0 && response.ErrorMessage.Contains("Section=ResponseStatusLine"))
            {
                return(Deserialize <T>(response));
            }

            if (response.ErrorException != null)
            {
                throw RestClientFactory.CreateErrorException(_restClient, response);
            }

            throw RestClientFactory.CreateFailedException(_restClient, response);
        }
        private void DoSend(RSharp.Method method, object body)
        {
            _request.AddParameter(
                "application/json",
                Newtonsoft.Json.JsonConvert.SerializeObject(body),
                ParameterType.RequestBody);

            _request.Timeout = 100000; // ms


            //Console.WriteLine("body: " + Newtonsoft.Json.JsonConvert.SerializeObject(body));

            var response = _restClient.Execute(_request, method);

            //Console.WriteLine("Error messag: e" + response.ErrorMessage);
            //Console.WriteLine("ResponseStatus: " + response.ResponseStatus.ToString());

            //Console.WriteLine("StatusDescription: " + response.StatusDescription);

            //Console.WriteLine("StatusCode: " + response.StatusCode);


            if (response.StatusCode == 0 && response.ErrorMessage.Contains("Section=ResponseStatusLine"))
            {
                return;
            }

            if (response.ErrorException != null)
            {
                throw RestClientFactory.CreateErrorException(_restClient, response);
            }

            if (!response.IsSuccessful)
            {
                throw RestClientFactory.CreateFailedException(_restClient, response);
            }
        }