/// <summary>
 /// put resilient as an asynchronous operation.
 /// </summary>
 /// <param name="httpClient">The HTTP client.</param>
 /// <param name="url">The URL of the host to send the request to.</param>
 /// <param name="httpContentFunc">The HTTP content function.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <param name="maxRetries">The maximum retries.</param>
 /// <param name="retryStatusCodes"></param>
 /// <returns>Task&lt;HttpResponseMessage&gt;.</returns>
 /// <exception cref="ResilientHttpRequestException">There is no HTTP response.</exception>
 public static async Task <HttpResponseMessage> PutResilientAsync(this System.Net.Http.HttpClient httpClient, string url, Func <HttpContent> httpContentFunc, CancellationToken cancellationToken, int?maxRetries = null, List <HttpStatusCode> retryStatusCodes = null)
 {
     return(await HttpClientExtensions.SendResilientAsync(httpClient, url, httpContentFunc, HttpMethod.Put, cancellationToken, maxRetries, retryStatusCodes));
 }
        /// <summary>
        /// put resilient as an asynchronous operation.
        /// </summary>
        /// <typeparam name="TResponseType">The type to deserialize the JSON response.</typeparam>
        /// <typeparam name="TContentType">The content type of the object to be JSON serialized and sent.</typeparam>
        /// <param name="httpClient">The HTTP client.</param>
        /// <param name="url">The URL of the host to send the request to.</param>
        /// <param name="contentObject">The content object to be sent.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="httpContentType"></param>
        /// <param name="encoding"></param>
        /// <param name="maxRetries">The maximum retries.</param>
        /// <param name="retryStatusCodes"></param>
        /// <returns>Task&lt;T&gt;.</returns>
        /// <exception cref="ResilientHttpRequestException">There is no HTTP response or the response was not sccessful.</exception>
        public static async Task <TResponseType> PutResilientAsync <TResponseType, TContentType>(this System.Net.Http.HttpClient httpClient, string url, TContentType contentObject, CancellationToken cancellationToken, string httpContentType = HttpMediaType.Json, Encoding encoding = null, int?maxRetries = null, List <HttpStatusCode> retryStatusCodes = null) where TResponseType : class where TContentType : class
        {
            var response = await PutResilientAsync(httpClient, url, contentObject, cancellationToken, httpContentType, encoding, maxRetries, retryStatusCodes);

            return(await HttpClientExtensions.ProcessResponse <TResponseType>(response, maxRetries));
        }
        /// <summary>
        /// put resilient as an asynchronous operation.
        /// </summary>
        /// <typeparam name="TContentType">The content type of the object to be JSON serialized and sent.</typeparam>
        /// <param name="httpClient">The HTTP client.</param>
        /// <param name="url">The URL of the host to send the request to.</param>
        /// <param name="contentObject">The content object to be sent.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="httpContentType"></param>
        /// <param name="encoding"></param>
        /// <param name="maxRetries">The maximum retries.</param>
        /// <param name="retryStatusCodes"></param>
        /// <returns>Task&lt;HttpResponseMessage&gt;.</returns>
        /// <exception cref="ResilientHttpRequestException">There is no HTTP response.</exception>
        public static async Task <HttpResponseMessage> PutResilientAsync <TContentType>(this System.Net.Http.HttpClient httpClient, string url, TContentType contentObject, CancellationToken cancellationToken, string httpContentType = HttpMediaType.Json, Encoding encoding = null, int?maxRetries = null, List <HttpStatusCode> retryStatusCodes = null) where TContentType : class
        {
            var stringContentFunction = HttpClientExtensions.CreateStringContentFunction(contentObject, httpContentType, encoding);

            return(await PutResilientAsync(httpClient, url, stringContentFunction, cancellationToken, maxRetries, retryStatusCodes));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// get resilient as an asynchronous operation.
        /// </summary>
        /// <typeparam name="TResponseType">The type to deserialize the JSON response.</typeparam>
        /// <param name="httpClient">The HTTP client.</param>
        /// <param name="url">The URL of the host to send the request to.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <param name="maxRetries">The maximum retries.</param>
        /// <param name="retryStatusCodes">The retry status codes.</param>
        /// <returns>Task&lt;TResponseType&gt;.</returns>
        public static async Task <TResponseType> GetResilientAsync <TResponseType>(this System.Net.Http.HttpClient httpClient, string url, CancellationToken cancellationToken, int?maxRetries = null, List <HttpStatusCode> retryStatusCodes = null) where TResponseType : class
        {
            var response = await GetResilientAsync(httpClient, url, cancellationToken, maxRetries, retryStatusCodes);

            return(await HttpClientExtensions.ProcessResponse <TResponseType>(response, maxRetries));
        }