From 4f02c66afc00db2ac9acfa61650c99ae0b935846 Mon Sep 17 00:00:00 2001 From: Dmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Tue, 9 Jul 2024 00:11:10 +0300 Subject: [PATCH] Fix CA1068 warnings (#2182) * Fix CA1068 for public classes * Fix CA1068 for internal methods --- .../AsyncPolicy.GenericImplementation.cs | 2 + .../AsyncPolicy.NonGenericImplementation.cs | 4 ++ src/Polly/Bulkhead/AsyncBulkheadEngine.cs | 4 +- src/Polly/Bulkhead/AsyncBulkheadPolicy.cs | 4 +- src/Polly/Caching/AsyncCacheEngine.cs | 4 +- src/Polly/Caching/AsyncCachePolicy.cs | 8 ++-- src/Polly/Caching/CacheEngine.cs | 4 +- src/Polly/Caching/CachePolicy.cs | 8 ++-- src/Polly/Caching/IAsyncCacheProvider.cs | 10 ++++- .../AsyncCircuitBreakerEngine.cs | 4 +- .../AsyncCircuitBreakerPolicy.cs | 8 ++-- .../CircuitBreaker/CircuitBreakerEngine.cs | 4 +- .../CircuitBreaker/CircuitBreakerPolicy.cs | 8 ++-- src/Polly/Fallback/AsyncFallbackEngine.cs | 4 +- src/Polly/Fallback/AsyncFallbackPolicy.cs | 8 ++-- src/Polly/Fallback/FallbackEngine.cs | 4 +- src/Polly/Fallback/FallbackPolicy.cs | 8 ++-- src/Polly/IAsyncPolicy.TResult.cs | 12 +++++ src/Polly/IAsyncPolicy.cs | 24 ++++++++++ src/Polly/Polly.csproj | 2 +- src/Polly/RateLimit/AsyncRateLimitEngine.cs | 4 +- src/Polly/RateLimit/AsyncRateLimitPolicy.cs | 4 +- src/Polly/Retry/AsyncRetryEngine.cs | 2 +- src/Polly/Retry/AsyncRetryPolicy.cs | 4 +- src/Polly/Retry/RetryEngine.cs | 2 +- src/Polly/Retry/RetryPolicy.cs | 4 +- src/Polly/Timeout/AsyncTimeoutEngine.cs | 4 +- src/Polly/Timeout/AsyncTimeoutPolicy.cs | 8 ++-- src/Polly/Timeout/TimeoutEngine.cs | 4 +- src/Polly/Timeout/TimeoutPolicy.cs | 8 ++-- .../Wrappers/ResilienceContextFactory.cs | 4 +- .../ResiliencePipelineAsyncPolicy.TResult.cs | 4 +- .../Wrappers/ResiliencePipelineAsyncPolicy.cs | 8 ++-- .../ResiliencePipelineSyncPolicy.TResult.cs | 4 +- .../Wrappers/ResiliencePipelineSyncPolicy.cs | 8 ++-- src/Polly/Wrap/AsyncPolicyWrap.cs | 24 +++++----- src/Polly/Wrap/AsyncPolicyWrapEngine.cs | 32 +++++++------- src/Polly/Wrap/PolicyWrap.cs | 24 +++++----- src/Polly/Wrap/PolicyWrapEngine.cs | 44 +++++++++---------- 39 files changed, 190 insertions(+), 140 deletions(-) diff --git a/src/Polly/AsyncPolicy.GenericImplementation.cs b/src/Polly/AsyncPolicy.GenericImplementation.cs index 809e7781c70..152e9900857 100644 --- a/src/Polly/AsyncPolicy.GenericImplementation.cs +++ b/src/Polly/AsyncPolicy.GenericImplementation.cs @@ -2,6 +2,7 @@ public abstract partial class AsyncPolicy { +#pragma warning disable CA1068 /// /// Defines the implementation of a policy for async executions returning . /// @@ -15,4 +16,5 @@ protected abstract Task ImplementationAsync( Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 } diff --git a/src/Polly/AsyncPolicy.NonGenericImplementation.cs b/src/Polly/AsyncPolicy.NonGenericImplementation.cs index f54acfcdda3..5d04568d03f 100644 --- a/src/Polly/AsyncPolicy.NonGenericImplementation.cs +++ b/src/Polly/AsyncPolicy.NonGenericImplementation.cs @@ -2,6 +2,7 @@ public abstract partial class AsyncPolicy { +#pragma warning disable CA1068 /// /// Defines the implementation of a policy for async executions with no return value. /// @@ -16,11 +17,13 @@ protected virtual Task ImplementationAsync( CancellationToken cancellationToken, bool continueOnCapturedContext) => ImplementationAsync(async (ctx, token) => +#pragma warning restore CA1068 { await action(ctx, token).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, cancellationToken, continueOnCapturedContext); +#pragma warning disable CA1068 /// /// Defines the implementation of a policy for async executions returning . /// @@ -35,4 +38,5 @@ protected abstract Task ImplementationAsync( Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 } diff --git a/src/Polly/Bulkhead/AsyncBulkheadEngine.cs b/src/Polly/Bulkhead/AsyncBulkheadEngine.cs index 7640dc5216d..9c1a95f47a3 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadEngine.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadEngine.cs @@ -9,8 +9,8 @@ internal static async Task ImplementationAsync( Func onBulkheadRejectedAsync, SemaphoreSlim maxParallelizationSemaphore, SemaphoreSlim maxQueuedActionsSemaphore, - CancellationToken cancellationToken, - bool continueOnCapturedContext) + bool continueOnCapturedContext, + CancellationToken cancellationToken) { if (!await maxQueuedActionsSemaphore.WaitAsync(TimeSpan.Zero, cancellationToken).ConfigureAwait(continueOnCapturedContext)) { diff --git a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs index f4f269580ff..426ad8d04ba 100644 --- a/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs +++ b/src/Polly/Bulkhead/AsyncBulkheadPolicy.cs @@ -36,7 +36,7 @@ internal AsyncBulkheadPolicy( [DebuggerStepThrough] protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => - AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, cancellationToken, continueOnCapturedContext); + AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, continueOnCapturedContext, cancellationToken); /// public void Dispose() @@ -71,7 +71,7 @@ internal AsyncBulkheadPolicy( /// [DebuggerStepThrough] protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => - AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, cancellationToken, continueOnCapturedContext); + AsyncBulkheadEngine.ImplementationAsync(action, context, _onBulkheadRejectedAsync, _maxParallelizationSemaphore, _maxQueuedActionsSemaphore, continueOnCapturedContext, cancellationToken); /// /// Gets the number of slots currently available for executing actions through the bulkhead. diff --git a/src/Polly/Caching/AsyncCacheEngine.cs b/src/Polly/Caching/AsyncCacheEngine.cs index 170b28c14f7..ccf9c2b195a 100644 --- a/src/Polly/Caching/AsyncCacheEngine.cs +++ b/src/Polly/Caching/AsyncCacheEngine.cs @@ -9,13 +9,13 @@ internal static async Task ImplementationAsync( Func cacheKeyStrategy, Func> action, Context context, - CancellationToken cancellationToken, bool continueOnCapturedContext, Action onCacheGet, Action onCacheMiss, Action onCachePut, Action? onCacheGetError, - Action? onCachePutError) + Action? onCachePutError, + CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Polly/Caching/AsyncCachePolicy.cs b/src/Polly/Caching/AsyncCachePolicy.cs index a4e0b925388..07f6f3ff8b9 100644 --- a/src/Polly/Caching/AsyncCachePolicy.cs +++ b/src/Polly/Caching/AsyncCachePolicy.cs @@ -54,13 +54,13 @@ protected override Task ImplementationAsync(Func @@ -111,12 +111,12 @@ protected override Task ImplementationAsync(Func( Func cacheKeyStrategy, Func action, Context context, - CancellationToken cancellationToken, Action onCacheGet, Action onCacheMiss, Action onCachePut, Action? onCacheGetError, - Action? onCachePutError) + Action? onCachePutError, + CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Polly/Caching/CachePolicy.cs b/src/Polly/Caching/CachePolicy.cs index efd576bc674..7d9df28e3a4 100644 --- a/src/Polly/Caching/CachePolicy.cs +++ b/src/Polly/Caching/CachePolicy.cs @@ -51,12 +51,12 @@ protected override TResult Implementation(Func @@ -105,10 +105,10 @@ protected override TResult Implementation(Func /// Gets a value from the cache asynchronously. /// @@ -18,8 +19,10 @@ public interface IAsyncCacheProvider /// the key was found in the cache, and whose second element is the value from the cache (null if not found). /// Task<(bool, object?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext); -#pragma warning restore SA1414 +#pragma warning restore CA1068 +#pragma warning restore SA1414 +#pragma warning disable CA1068 /// /// Puts the specified value in the cache asynchronously. /// @@ -30,6 +33,7 @@ public interface IAsyncCacheProvider /// Whether async calls should continue on a captured synchronization context.Note: if the underlying cache's async API does not support controlling whether to continue on a captured context, async Policy executions with continueOnCapturedContext == true cannot be guaranteed to remain on the captured context. /// A which completes when the value has been cached. Task PutAsync(string key, object? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 } /// @@ -39,6 +43,7 @@ public interface IAsyncCacheProvider public interface IAsyncCacheProvider { #pragma warning disable SA1414 +#pragma warning disable CA1068 /// /// Gets a value from the cache asynchronously. /// @@ -50,8 +55,10 @@ public interface IAsyncCacheProvider /// the key was found in the cache, and whose second element is the value from the cache (default(TResult) if not found). /// Task<(bool, TResult?)> TryGetAsync(string key, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 #pragma warning restore SA1414 +#pragma warning disable CA1068 /// /// Puts the specified value in the cache asynchronously. /// @@ -62,4 +69,5 @@ public interface IAsyncCacheProvider /// Whether async calls should continue on a captured synchronization context.Note: if the underlying cache's async API does not support controlling whether to continue on a captured context, async Policy executions with continueOnCapturedContext == true cannot be guaranteed to remain on the captured context. /// A which completes when the value has been cached. Task PutAsync(string key, TResult? value, Ttl ttl, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 } diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs index d0c2e479d81..89c6c31242c 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerEngine.cs @@ -5,11 +5,11 @@ internal class AsyncCircuitBreakerEngine internal static async Task ImplementationAsync( Func> action, Context context, - CancellationToken cancellationToken, bool continueOnCapturedContext, ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, - ICircuitController breakerController) + ICircuitController breakerController, + CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs index cbe97e8da28..4832735a061 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs @@ -44,11 +44,11 @@ protected override async Task ImplementationAsync(Func( async (ctx, ct) => { result = await action(ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, context, - cancellationToken, continueOnCapturedContext, ExceptionPredicates, ResultPredicates.None, - BreakerController).ConfigureAwait(continueOnCapturedContext); + BreakerController, + cancellationToken).ConfigureAwait(continueOnCapturedContext); return result; } } @@ -103,9 +103,9 @@ protected override Task ImplementationAsync(Func( Func action, Context context, - CancellationToken cancellationToken, ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, - ICircuitController breakerController) + ICircuitController breakerController, + CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs index c481848bb49..f4954804cc8 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs @@ -44,10 +44,10 @@ protected override TResult Implementation(Func( (ctx, ct) => { result = action(ctx, ct); return EmptyStruct.Instance; }, context, - cancellationToken, ExceptionPredicates, ResultPredicates.None, - BreakerController); + BreakerController, + cancellationToken); return result; } } @@ -101,8 +101,8 @@ protected override TResult Implementation(Func ImplementationAsync( Func> action, Context context, - CancellationToken cancellationToken, ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, Func, Context, Task> onFallbackAsync, Func, Context, CancellationToken, Task> fallbackAction, - bool continueOnCapturedContext) + bool continueOnCapturedContext, + CancellationToken cancellationToken) { DelegateResult delegateOutcome; diff --git a/src/Polly/Fallback/AsyncFallbackPolicy.cs b/src/Polly/Fallback/AsyncFallbackPolicy.cs index 5c42f6dc59a..085329d946b 100644 --- a/src/Polly/Fallback/AsyncFallbackPolicy.cs +++ b/src/Polly/Fallback/AsyncFallbackPolicy.cs @@ -31,7 +31,6 @@ protected override Task ImplementationAsync( return EmptyStruct.Instance; }, context, - cancellationToken, ExceptionPredicates, ResultPredicates.None, (outcome, ctx) => _onFallbackAsync(outcome.Exception, ctx), @@ -40,7 +39,8 @@ protected override Task ImplementationAsync( await _fallbackAction(outcome.Exception, ctx, ct).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; }, - continueOnCapturedContext); + continueOnCapturedContext, + cancellationToken); /// protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, @@ -77,10 +77,10 @@ protected override Task ImplementationAsync(Func( Func action, Context context, - CancellationToken cancellationToken, ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, Action, Context> onFallback, - Func, Context, CancellationToken, TResult> fallbackAction) + Func, Context, CancellationToken, TResult> fallbackAction, + CancellationToken cancellationToken) { DelegateResult delegateOutcome; diff --git a/src/Polly/Fallback/FallbackPolicy.cs b/src/Polly/Fallback/FallbackPolicy.cs index 808f535263e..da2fb119e84 100644 --- a/src/Polly/Fallback/FallbackPolicy.cs +++ b/src/Polly/Fallback/FallbackPolicy.cs @@ -30,7 +30,6 @@ protected override void Implementation(Action action return EmptyStruct.Instance; }, context, - cancellationToken, ExceptionPredicates, ResultPredicates.None, (outcome, ctx) => _onFallback(outcome.Exception, ctx), @@ -38,7 +37,8 @@ protected override void Implementation(Action action { _fallbackAction(outcome.Exception, ctx, ct); return EmptyStruct.Instance; - }); + }, + cancellationToken); /// protected override TResult Implementation(Func action, Context context, CancellationToken cancellationToken) => @@ -73,9 +73,9 @@ protected override TResult Implementation(Func : IsPolicy /// The value returned by the action. Task ExecuteAsync(Func> action, Context context, CancellationToken cancellationToken); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -72,7 +73,9 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task ExecuteAsync(Func> action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -83,7 +86,9 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. /// Thrown when is . Task ExecuteAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -94,6 +99,7 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task ExecuteAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -146,6 +152,7 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. Task> ExecuteAndCaptureAsync(Func> action, Context context, CancellationToken cancellationToken); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -155,7 +162,9 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task> ExecuteAndCaptureAsync(Func> action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -166,7 +175,9 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. /// Thrown when is . Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -177,4 +188,5 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task> ExecuteAndCaptureAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 } diff --git a/src/Polly/IAsyncPolicy.cs b/src/Polly/IAsyncPolicy.cs index 205770a5892..0d2cfba8d5b 100644 --- a/src/Polly/IAsyncPolicy.cs +++ b/src/Polly/IAsyncPolicy.cs @@ -62,6 +62,7 @@ public interface IAsyncPolicy : IsPolicy /// A which completes when is registered. Task ExecuteAsync(Func action, Context context, CancellationToken cancellationToken); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy. /// @@ -71,7 +72,9 @@ public interface IAsyncPolicy : IsPolicy /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. /// A which completes when is registered. Task ExecuteAsync(Func action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy. /// @@ -82,7 +85,9 @@ public interface IAsyncPolicy : IsPolicy /// Thrown when is . /// A which completes when is registered. Task ExecuteAsync(Func action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy. /// @@ -93,6 +98,7 @@ public interface IAsyncPolicy : IsPolicy /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. /// A which completes when is registered. Task ExecuteAsync(Func action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -149,6 +155,7 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. Task ExecuteAsync(Func> action, Context context, CancellationToken cancellationToken); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -159,7 +166,9 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task ExecuteAsync(Func> action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -171,7 +180,9 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. /// Thrown when is . Task ExecuteAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -183,6 +194,7 @@ public interface IAsyncPolicy : IsPolicy /// The value returned by the action. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task ExecuteAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 /// /// Executes the specified asynchronous action within the policy and returns the captured result. @@ -235,6 +247,7 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. Task ExecuteAndCaptureAsync(Func action, Context context, CancellationToken cancellationToken); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the captured result. /// @@ -244,7 +257,9 @@ public interface IAsyncPolicy : IsPolicy /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. /// An instance of . Task ExecuteAndCaptureAsync(Func action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the captured result. /// @@ -255,7 +270,9 @@ public interface IAsyncPolicy : IsPolicy /// Thrown when is . /// The captured result. Task ExecuteAndCaptureAsync(Func action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the captured result. /// @@ -266,6 +283,7 @@ public interface IAsyncPolicy : IsPolicy /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. /// The captured result. Task ExecuteAndCaptureAsync(Func action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. @@ -324,6 +342,7 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. Task> ExecuteAndCaptureAsync(Func> action, Context context, CancellationToken cancellationToken); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -334,7 +353,9 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task> ExecuteAndCaptureAsync(Func> action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -346,7 +367,9 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. /// Thrown when is . Task> ExecuteAndCaptureAsync(Func> action, IDictionary contextData, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -358,4 +381,5 @@ public interface IAsyncPolicy : IsPolicy /// The captured result. /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task> ExecuteAndCaptureAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 } diff --git a/src/Polly/Polly.csproj b/src/Polly/Polly.csproj index 3f228b6c829..8e4e61f41c4 100644 --- a/src/Polly/Polly.csproj +++ b/src/Polly/Polly.csproj @@ -7,7 +7,7 @@ Library 70 true - $(NoWarn);CA1010;CA1031;CA1032;CA1033;CA1051;CA1062;CA1063;CA1064;CA1068;CA1710;CA1716;CA1724;CA1805;CA1815;CA1816;CA2211 + $(NoWarn);CA1010;CA1031;CA1032;CA1033;CA1051;CA1062;CA1063;CA1064;CA1710;CA1716;CA1724;CA1805;CA1815;CA1816;CA2211 $(NoWarn);S2223;S3215;S3246;S3971;S4039;S4049;S4457 $(NoWarn);RS0037; diff --git a/src/Polly/RateLimit/AsyncRateLimitEngine.cs b/src/Polly/RateLimit/AsyncRateLimitEngine.cs index 0c31e6fcda7..c380335da2f 100644 --- a/src/Polly/RateLimit/AsyncRateLimitEngine.cs +++ b/src/Polly/RateLimit/AsyncRateLimitEngine.cs @@ -9,8 +9,8 @@ internal static async Task ImplementationAsync( Func? retryAfterFactory, Func> action, Context context, - CancellationToken cancellationToken, - bool continueOnCapturedContext) + bool continueOnCapturedContext, + CancellationToken cancellationToken) { (bool permit, TimeSpan retryAfter) = rateLimiter.PermitExecution(); diff --git a/src/Polly/RateLimit/AsyncRateLimitPolicy.cs b/src/Polly/RateLimit/AsyncRateLimitPolicy.cs index 0acec910a53..cb643e83be9 100644 --- a/src/Polly/RateLimit/AsyncRateLimitPolicy.cs +++ b/src/Polly/RateLimit/AsyncRateLimitPolicy.cs @@ -16,7 +16,7 @@ internal AsyncRateLimitPolicy(IRateLimiter rateLimiter) => [DebuggerStepThrough] protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => - AsyncRateLimitEngine.ImplementationAsync(_rateLimiter, null, action, context, cancellationToken, continueOnCapturedContext); + AsyncRateLimitEngine.ImplementationAsync(_rateLimiter, null, action, context, continueOnCapturedContext, cancellationToken); } /// @@ -40,5 +40,5 @@ internal AsyncRateLimitPolicy( [DebuggerStepThrough] protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => - AsyncRateLimitEngine.ImplementationAsync(_rateLimiter, _retryAfterFactory, action, context, cancellationToken, continueOnCapturedContext); + AsyncRateLimitEngine.ImplementationAsync(_rateLimiter, _retryAfterFactory, action, context, continueOnCapturedContext, cancellationToken); } diff --git a/src/Polly/Retry/AsyncRetryEngine.cs b/src/Polly/Retry/AsyncRetryEngine.cs index 6580a49c169..7237366b8f2 100644 --- a/src/Polly/Retry/AsyncRetryEngine.cs +++ b/src/Polly/Retry/AsyncRetryEngine.cs @@ -6,10 +6,10 @@ internal static class AsyncRetryEngine internal static async Task ImplementationAsync( Func> action, Context context, - CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates shouldRetryResultPredicates, Func, TimeSpan, int, Context, Task> onRetryAsync, + CancellationToken cancellationToken, int permittedRetryCount = int.MaxValue, IEnumerable? sleepDurationsEnumerable = null, Func, Context, TimeSpan>? sleepDurationProvider = null, diff --git a/src/Polly/Retry/AsyncRetryPolicy.cs b/src/Polly/Retry/AsyncRetryPolicy.cs index bd8b6b4b0f5..195b5a4767b 100644 --- a/src/Polly/Retry/AsyncRetryPolicy.cs +++ b/src/Polly/Retry/AsyncRetryPolicy.cs @@ -40,10 +40,10 @@ protected override Task ImplementationAsync( return AsyncRetryEngine.ImplementationAsync( action, context, - cancellationToken, ExceptionPredicates, ResultPredicates.None, (outcome, timespan, retryCount, ctx) => _onRetryAsync(outcome.Exception, timespan, retryCount, ctx), + cancellationToken, _permittedRetryCount, _sleepDurationsEnumerable, sleepDurationProvider, @@ -83,10 +83,10 @@ protected override Task ImplementationAsync(Func( Func action, Context context, - CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates shouldRetryResultPredicates, Action, TimeSpan, int, Context> onRetry, + CancellationToken cancellationToken, int permittedRetryCount = int.MaxValue, IEnumerable? sleepDurationsEnumerable = null, Func, Context, TimeSpan>? sleepDurationProvider = null) diff --git a/src/Polly/Retry/RetryPolicy.cs b/src/Polly/Retry/RetryPolicy.cs index 8662c5869bf..d85258b3ed4 100644 --- a/src/Polly/Retry/RetryPolicy.cs +++ b/src/Polly/Retry/RetryPolicy.cs @@ -34,10 +34,10 @@ protected override TResult Implementation(Func.None, (outcome, timespan, retryCount, ctx) => _onRetry(outcome.Exception, timespan, retryCount, ctx), + cancellationToken, _permittedRetryCount, _sleepDurationsEnumerable, sleepDurationProvider); @@ -75,10 +75,10 @@ protected override TResult Implementation(Func ImplementationAsync( Func> action, Context context, - CancellationToken cancellationToken, Func timeoutProvider, TimeoutStrategy timeoutStrategy, Func onTimeoutAsync, - bool continueOnCapturedContext) + bool continueOnCapturedContext, + CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); TimeSpan timeout = timeoutProvider(context); diff --git a/src/Polly/Timeout/AsyncTimeoutPolicy.cs b/src/Polly/Timeout/AsyncTimeoutPolicy.cs index bccd01e82c5..ff7f6370a1b 100644 --- a/src/Polly/Timeout/AsyncTimeoutPolicy.cs +++ b/src/Polly/Timeout/AsyncTimeoutPolicy.cs @@ -29,11 +29,11 @@ protected override Task ImplementationAsync( AsyncTimeoutEngine.ImplementationAsync( action, context, - cancellationToken, _timeoutProvider, _timeoutStrategy, _onTimeoutAsync, - continueOnCapturedContext); + continueOnCapturedContext, + cancellationToken); } /// @@ -66,9 +66,9 @@ protected override Task ImplementationAsync( AsyncTimeoutEngine.ImplementationAsync( action, context, - cancellationToken, _timeoutProvider, _timeoutStrategy, _onTimeoutAsync, - continueOnCapturedContext); + continueOnCapturedContext, + cancellationToken); } diff --git a/src/Polly/Timeout/TimeoutEngine.cs b/src/Polly/Timeout/TimeoutEngine.cs index 199da1b4fab..2afbfd0685c 100644 --- a/src/Polly/Timeout/TimeoutEngine.cs +++ b/src/Polly/Timeout/TimeoutEngine.cs @@ -7,10 +7,10 @@ internal static class TimeoutEngine internal static TResult Implementation( Func action, Context context, - CancellationToken cancellationToken, Func timeoutProvider, TimeoutStrategy timeoutStrategy, - Action onTimeout) + Action onTimeout, + CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); TimeSpan timeout = timeoutProvider(context); diff --git a/src/Polly/Timeout/TimeoutPolicy.cs b/src/Polly/Timeout/TimeoutPolicy.cs index 179b37301db..52bcfc875b9 100644 --- a/src/Polly/Timeout/TimeoutPolicy.cs +++ b/src/Polly/Timeout/TimeoutPolicy.cs @@ -25,10 +25,10 @@ protected override TResult Implementation(Func @@ -56,8 +56,8 @@ protected override TResult Implementation(Func oldProperties) + out IDictionary oldProperties, + CancellationToken cancellationToken) { var resilienceContext = ResilienceContextPool.Shared.Get(context.OperationKey, continueOnCapturedContext, cancellationToken); resilienceContext.Properties.SetProperties(context, out oldProperties); diff --git a/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs b/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs index cec45a858a2..9a32cb3df32 100644 --- a/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs +++ b/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs @@ -10,9 +10,9 @@ protected override async Task ImplementationAsync(Func ImplementationAsync( { var resilienceContext = ResilienceContextFactory.Create( context, - cancellationToken, continueOnCapturedContext, - out var oldProperties); + out var oldProperties, + cancellationToken); try { diff --git a/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs b/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs index d4fca1c3e37..4ebce11e4b1 100644 --- a/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs +++ b/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs @@ -10,9 +10,9 @@ protected override TResult Implementation(Func action { var resilienceContext = ResilienceContextFactory.Create( context, - cancellationToken, true, - out var oldProperties); + out var oldProperties, + cancellationToken); try { @@ -34,9 +34,9 @@ protected override TResult Implementation(Func [DebuggerStepThrough] @@ -47,10 +47,10 @@ protected override Task ImplementationAsync(Func( action, context, - cancellationToken, continueOnCapturedContext, _outer, - _inner); + _inner, + cancellationToken); } /// @@ -107,20 +107,20 @@ protected override Task ImplementationAsync(Func( action, context, - cancellationToken, continueOnCapturedContext, _outerNonGeneric, - _innerNonGeneric); + _innerNonGeneric, + cancellationToken); } else if (_innerGeneric != null) { return AsyncPolicyWrapEngine.ImplementationAsync( action, context, - cancellationToken, continueOnCapturedContext, _outerNonGeneric, - _innerGeneric); + _innerGeneric, + cancellationToken); } else @@ -135,10 +135,10 @@ protected override Task ImplementationAsync(Func( action, context, - cancellationToken, continueOnCapturedContext, _outerGeneric, - _innerNonGeneric); + _innerNonGeneric, + cancellationToken); } else if (_innerGeneric != null) @@ -146,10 +146,10 @@ protected override Task ImplementationAsync(Func( action, context, - cancellationToken, continueOnCapturedContext, _outerGeneric, - _innerGeneric); + _innerGeneric, + cancellationToken); } else diff --git a/src/Polly/Wrap/AsyncPolicyWrapEngine.cs b/src/Polly/Wrap/AsyncPolicyWrapEngine.cs index 280aae85cab..6f7b2d78fd1 100644 --- a/src/Polly/Wrap/AsyncPolicyWrapEngine.cs +++ b/src/Polly/Wrap/AsyncPolicyWrapEngine.cs @@ -3,12 +3,12 @@ internal static class AsyncPolicyWrapEngine { internal static Task ImplementationAsync( - Func> func, + Func> func, Context context, - CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, - IAsyncPolicy innerPolicy) => + IAsyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.ExecuteAsync( (ctx, ct) => innerPolicy.ExecuteAsync( func, @@ -20,12 +20,12 @@ internal static Task ImplementationAsync( continueOnCapturedContext); internal static Task ImplementationAsync( - Func> func, + Func> func, Context context, - CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, - IAsyncPolicy innerPolicy) => + IAsyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.ExecuteAsync( (ctx, ct) => innerPolicy.ExecuteAsync( func, @@ -39,10 +39,10 @@ internal static Task ImplementationAsync( internal static Task ImplementationAsync( Func> func, Context context, - CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, - IAsyncPolicy innerPolicy) => + IAsyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.ExecuteAsync( (ctx, ct) => innerPolicy.ExecuteAsync( func, @@ -54,12 +54,12 @@ internal static Task ImplementationAsync( continueOnCapturedContext); internal static Task ImplementationAsync( - Func> func, - Context context, - CancellationToken cancellationToken, - bool continueOnCapturedContext, - IAsyncPolicy outerPolicy, - IAsyncPolicy innerPolicy) => + Func> func, + Context context, + bool continueOnCapturedContext, + IAsyncPolicy outerPolicy, + IAsyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.ExecuteAsync( (ctx, ct) => innerPolicy.ExecuteAsync( func, @@ -73,10 +73,10 @@ internal static Task ImplementationAsync( internal static Task ImplementationAsync( Func action, Context context, - CancellationToken cancellationToken, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, - IAsyncPolicy innerPolicy) => + IAsyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.ExecuteAsync( (ctx, ct) => innerPolicy.ExecuteAsync( action, diff --git a/src/Polly/Wrap/PolicyWrap.cs b/src/Polly/Wrap/PolicyWrap.cs index f6bde0b768a..5c2dea29414 100644 --- a/src/Polly/Wrap/PolicyWrap.cs +++ b/src/Polly/Wrap/PolicyWrap.cs @@ -31,9 +31,9 @@ protected override void Implementation(Action action PolicyWrapEngine.Implementation( action, context, - cancellationToken, _outer, - _inner); + _inner, + cancellationToken); /// [DebuggerStepThrough] @@ -41,9 +41,9 @@ protected override TResult Implementation(Func( action, context, - cancellationToken, _outer, - _inner); + _inner, + cancellationToken); } /// @@ -99,18 +99,18 @@ protected override TResult Implementation(Func( action, context, - cancellationToken, _outerNonGeneric, - _innerNonGeneric); + _innerNonGeneric, + cancellationToken); } else if (_innerGeneric != null) { return PolicyWrapEngine.Implementation( action, context, - cancellationToken, _outerNonGeneric, - _innerGeneric); + _innerGeneric, + cancellationToken); } else { @@ -124,9 +124,9 @@ protected override TResult Implementation(Func( action, context, - cancellationToken, _outerGeneric, - _innerNonGeneric); + _innerNonGeneric, + cancellationToken); } else if (_innerGeneric != null) @@ -134,9 +134,9 @@ protected override TResult Implementation(Func( action, context, - cancellationToken, _outerGeneric, - _innerGeneric); + _innerGeneric, + cancellationToken); } else { diff --git a/src/Polly/Wrap/PolicyWrapEngine.cs b/src/Polly/Wrap/PolicyWrapEngine.cs index 87409c84dbf..e88d06b2ce9 100644 --- a/src/Polly/Wrap/PolicyWrapEngine.cs +++ b/src/Polly/Wrap/PolicyWrapEngine.cs @@ -5,40 +5,40 @@ internal static class PolicyWrapEngine internal static TResult Implementation( Func func, Context context, - CancellationToken cancellationToken, ISyncPolicy outerPolicy, - ISyncPolicy innerPolicy) => + ISyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(func, ctx, ct), context, cancellationToken); internal static TResult Implementation( - Func func, - Context context, - CancellationToken cancellationToken, - ISyncPolicy outerPolicy, - ISyncPolicy innerPolicy) => + Func func, + Context context, + ISyncPolicy outerPolicy, + ISyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(func, ctx, ct), context, cancellationToken); internal static TResult Implementation( - Func func, - Context context, - CancellationToken cancellationToken, - ISyncPolicy outerPolicy, - ISyncPolicy innerPolicy) => + Func func, + Context context, + ISyncPolicy outerPolicy, + ISyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(func, ctx, ct), context, cancellationToken); internal static TResult Implementation( - Func func, - Context context, - CancellationToken cancellationToken, - ISyncPolicy outerPolicy, - ISyncPolicy innerPolicy) => + Func func, + Context context, + ISyncPolicy outerPolicy, + ISyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(func, ctx, ct), context, cancellationToken); internal static void Implementation( - Action action, - Context context, - CancellationToken cancellationToken, - ISyncPolicy outerPolicy, - ISyncPolicy innerPolicy) => + Action action, + Context context, + ISyncPolicy outerPolicy, + ISyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(action, ctx, ct), context, cancellationToken); }