Esempio n. 1
0
        public JsonResponseDetails Post(string url, object contentObject, TimeSpan timeout, string contentType = "application/json")
        {
            string message = null;

            try
            {
                message = serializer.Serialize(contentObject);

                CancellationTokenSource    cts      = new CancellationTokenSource();
                Task <JsonResponseDetails> postTask = DoPostJsonAsync(url, message, cts.Token, contentType);
                if (postTask.Wait(timeout))
                {
                    JsonResponseDetails responseDetails = postTask.Result;
                    LogResponseDetails(responseDetails);
                    return(responseDetails);
                }

                cts.Cancel();
                throw new HttpClientExException(url, message, timeout);
            }
            catch (AggregateException ex)
            {
                throw new HttpClientExException(url, message, ex.Flatten());
            }
            catch (Exception ex)
            {
                throw new HttpClientExException(url, message, ex);
            }
        }
Esempio n. 2
0
        public JsonResponseDetails Get(string url, TimeSpan timeout, string contentType = "application/json")
        {
            try
            {
                CancellationTokenSource    cts     = new CancellationTokenSource();
                Task <JsonResponseDetails> getTask = DoGetJsonAsync(url, cts.Token, contentType);
                if (getTask.Wait(timeout))
                {
                    JsonResponseDetails responseDetails = getTask.Result;
                    LogResponseDetails(responseDetails);
                    return(responseDetails);
                }

                cts.Cancel();
                throw new HttpClientExException(url, string.Empty, timeout);
            }
            catch (AggregateException ex)
            {
                throw new HttpClientExException(url, string.Empty, ex.Flatten());
            }
            catch (Exception ex)
            {
                throw new HttpClientExException(url, string.Empty, ex);
            }
        }
Esempio n. 3
0
        public static void WriteStandardLog(JsonResponseDetails responseDetails)
        {
            HttpResponseMessage response = responseDetails.Response;

            if (response.IsSuccessStatusCode)
            {
                logger.Debug($"Request has been sent. {responseDetails}");
            }
            else
            {
                logger.Warn($"Something went wrong during request posting. {responseDetails}");
            }
        }
Esempio n. 4
0
 private static JsonResponseDetails LogResponseDetails(JsonResponseDetails responseDetails)
 {
     logger.Trace("Got response on request. {0}", responseDetails);
     return(responseDetails);
 }