Esempio n. 1
0
        /// <inheritdoc />
        public RetryingHttpClientHandler([NotNull] IRetryStrategy retryStrategy)
        {
            if (retryStrategy == null)
            {
                throw new ArgumentNullException(nameof(retryStrategy));
            }

            var retryAttemptsCount = retryStrategy.RetryAttemptsCount;

            _retryPolicy = Policy
                           .Handle <HttpRequestException>()
                           .WaitAndRetryAsync(retryAttemptsCount,
                                              (retryAttempt, context) => retryStrategy.GetRetrySleepDuration(retryAttempt, context.OperationKey),
                                              (exception, timeSpan, retryAttempt, context) =>
                                              context["RetriesLeft"] = retryAttemptsCount - retryAttempt);
        }