Example #1
0
        /// <summary>
        /// Builds a <see cref="Policy"/> that will retry <paramref name="retryCount"/> times
        /// calling <paramref name="onRetry"/> on each retry with the raised exception and retry count.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="retryCount">The retry count.</param>
        /// <param name="onRetry">The action to call on each retry.</param>
        /// <returns>The policy instance.</returns>
        /// <exception cref="System.ArgumentOutOfRangeException">retryCount;Value must be greater than or equal to zero.</exception>
        /// <exception cref="System.ArgumentNullException">onRetry</exception>
        public static RetryPolicy Retry(this PolicyBuilder policyBuilder, int retryCount, Action <Exception, int> onRetry)
        {
            if (retryCount < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(retryCount), "Value must be greater than or equal to zero.");
            }
            if (onRetry == null)
            {
                throw new ArgumentNullException(nameof(onRetry));
            }

            return(policyBuilder.Retry(retryCount, (outcome, i, ctx) => onRetry(outcome, i)));
        }
Example #2
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will retry once
 /// calling <paramref name="onRetry"/> on retry with the handled exception or result and retry count.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <param name="onRetry">The action to call on each retry.</param>
 /// <returns>The policy instance.</returns>
 /// <exception cref="System.ArgumentNullException">onRetry</exception>
 public static RetryPolicy <TResult> Retry <TResult>(this PolicyBuilder <TResult> policyBuilder, Action <DelegateResult <TResult>, int> onRetry)
 {
     return(policyBuilder.Retry(1, onRetry));
 }
Example #3
0
        /// <summary>
        /// Builds a <see cref="Policy"/> that will retry <paramref name="retryCount"/> times.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="retryCount">The retry count.</param>
        /// <returns>The policy instance.</returns>
        public static RetryPolicy <TResult> Retry <TResult>(this PolicyBuilder <TResult> policyBuilder, int retryCount)
        {
            Action <DelegateResult <TResult>, int> doNothing = (_, __) => { };

            return(policyBuilder.Retry(retryCount, doNothing));
        }
Example #4
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will retry once.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <returns>The policy instance.</returns>
 public static RetryPolicy <TResult> Retry <TResult>(this PolicyBuilder <TResult> policyBuilder)
 {
     return(policyBuilder.Retry(1));
 }
Example #5
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will retry once
 /// calling <paramref name="onRetry"/> on retry with the raised exception and retry count.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <param name="onRetry">The action to call on each retry.</param>
 /// <returns>The policy instance.</returns>
 /// <exception cref="System.ArgumentOutOfRangeException">retryCount;Value must be greater than zero.</exception>
 /// <exception cref="System.ArgumentNullException">onRetry</exception>
 public static Policy Retry(this PolicyBuilder policyBuilder, Action <Exception, int> onRetry)
 {
     return(policyBuilder.Retry(1, onRetry));
 }
Example #6
0
        /// <summary>
        /// Builds a <see cref="Policy"/> that will retry <paramref name="retryCount"/> times.
        /// </summary>
        /// <param name="policyBuilder">The policy builder.</param>
        /// <param name="retryCount">The retry count.</param>
        /// <returns>The policy instance.</returns>
        public static Policy Retry(this PolicyBuilder policyBuilder, int retryCount)
        {
            Action <Exception, int> doNothing = (_, __) => { };

            return(policyBuilder.Retry(retryCount, doNothing));
        }
Example #7
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will retry once.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <returns>The policy instance.</returns>
 public static Policy Retry(this PolicyBuilder policyBuilder)
 {
     return(policyBuilder.Retry(1));
 }
Example #8
0
 /// <summary>
 /// Builds a <see cref="Policy{TResult}"/> that will retry once
 /// calling <paramref name="onRetry"/> on retry with the handled exception or result, retry count and context data.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <param name="onRetry">The action to call on each retry.</param>
 /// <returns>The policy instance.</returns>
 /// <exception cref="System.ArgumentNullException">onRetry</exception>
 public static RetryPolicy <TResult> Retry <TResult>(this PolicyBuilder <TResult> policyBuilder, Action <DelegateResult <TResult>, int, Context> onRetry)
 => policyBuilder.Retry(1, onRetry);
Example #9
0
 /// <summary>
 /// Builds a <see cref="Policy{TResult}"/> that will retry once.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <returns>The policy instance.</returns>
 public static RetryPolicy <TResult> Retry <TResult>(this PolicyBuilder <TResult> policyBuilder)
 => policyBuilder.Retry(1);
Example #10
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will retry once
 /// calling <paramref name="onRetry"/> on retry with the raised exception, retry count and context data.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <param name="onRetry">The action to call on each retry.</param>
 /// <returns>The policy instance.</returns>
 /// <exception cref="System.ArgumentNullException">onRetry</exception>
 public static RetryPolicy Retry(this PolicyBuilder policyBuilder, Action <Exception, int, Context> onRetry)
 => policyBuilder.Retry(1, onRetry);
Example #11
0
 /// <summary>
 /// Builds a <see cref="Policy"/> that will retry once.
 /// </summary>
 /// <param name="policyBuilder">The policy builder.</param>
 /// <returns>The policy instance.</returns>
 public static RetryPolicy Retry(this PolicyBuilder policyBuilder)
 => policyBuilder.Retry(1);