From 08cecb06c93a866e2c5371457359c991163aa508 Mon Sep 17 00:00:00 2001 From: iamdmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:14:06 +0300 Subject: [PATCH 1/6] Fix CA1068 for public classes --- .../AsyncPolicy.GenericImplementation.cs | 2 ++ .../AsyncPolicy.NonGenericImplementation.cs | 4 ++++ src/Polly/Caching/IAsyncCacheProvider.cs | 10 +++++++- src/Polly/IAsyncPolicy.TResult.cs | 11 +++++++++ src/Polly/IAsyncPolicy.cs | 24 +++++++++++++++++++ src/Polly/Polly.csproj | 2 +- 6 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/Polly/AsyncPolicy.GenericImplementation.cs b/src/Polly/AsyncPolicy.GenericImplementation.cs index 809e7781c70..a15b93879e5 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 . /// @@ -11,6 +12,7 @@ public abstract partial class AsyncPolicy /// Whether async continuations should continue on a captured context. /// A representing the result of the execution. protected abstract Task ImplementationAsync( +#pragma warning restore CA1068 Func> action, Context context, CancellationToken cancellationToken, diff --git a/src/Polly/AsyncPolicy.NonGenericImplementation.cs b/src/Polly/AsyncPolicy.NonGenericImplementation.cs index f54acfcdda3..f1052b5f760 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. /// @@ -11,6 +12,7 @@ public abstract partial class AsyncPolicy /// Whether async continuations should continue on a captured context. /// A representing the result of the execution. protected virtual Task ImplementationAsync( +#pragma warning restore CA1068 Func action, Context context, CancellationToken cancellationToken, @@ -21,6 +23,7 @@ protected virtual Task ImplementationAsync( return EmptyStruct.Instance; }, context, cancellationToken, continueOnCapturedContext); +#pragma warning disable CA1068 /// /// Defines the implementation of a policy for async executions returning . /// @@ -31,6 +34,7 @@ protected virtual Task ImplementationAsync( /// Whether async continuations should continue on a captured context. /// A representing the result of the execution. protected abstract Task ImplementationAsync( +#pragma warning restore CA1068 Func> action, Context context, CancellationToken cancellationToken, diff --git a/src/Polly/Caching/IAsyncCacheProvider.cs b/src/Polly/Caching/IAsyncCacheProvider.cs index e64d2bc09ad..401abccee71 100644 --- a/src/Polly/Caching/IAsyncCacheProvider.cs +++ b/src/Polly/Caching/IAsyncCacheProvider.cs @@ -7,6 +7,7 @@ namespace Polly.Caching; public interface IAsyncCacheProvider { #pragma warning disable SA1414 +#pragma warning disable CA1068 /// /// 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/IAsyncPolicy.TResult.cs b/src/Polly/IAsyncPolicy.TResult.cs index 3ac40611abc..692eba1d0bf 100644 --- a/src/Polly/IAsyncPolicy.TResult.cs +++ b/src/Polly/IAsyncPolicy.TResult.cs @@ -63,6 +63,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. /// @@ -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. /// @@ -156,6 +163,7 @@ public interface IAsyncPolicy : IsPolicy /// Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods. Task> ExecuteAndCaptureAsync(Func> action, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning disable CA1068 /// /// Executes the specified asynchronous action within the policy and returns the result. /// @@ -166,7 +174,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 +187,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; From 477317fb24074c72037fa606469765423299cd31 Mon Sep 17 00:00:00 2001 From: iamdmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:27:23 +0300 Subject: [PATCH 2/6] Fix CA1068 for internal methods --- src/Polly/Bulkhead/AsyncBulkheadEngine.cs | 4 +- src/Polly/Bulkhead/AsyncBulkheadPolicy.cs | 4 +- src/Polly/Caching/AsyncCacheEngine.cs | 7 ++- src/Polly/Caching/AsyncCachePolicy.cs | 6 +-- src/Polly/Caching/CacheEngine.cs | 7 ++- src/Polly/Caching/CachePolicy.cs | 6 +-- .../AsyncCircuitBreakerEngine.cs | 4 +- .../AsyncCircuitBreakerPolicy.cs | 6 +-- .../CircuitBreaker/CircuitBreakerEngine.cs | 7 ++- .../CircuitBreaker/CircuitBreakerPolicy.cs | 6 +-- src/Polly/Fallback/AsyncFallbackEngine.cs | 4 +- src/Polly/Fallback/AsyncFallbackPolicy.cs | 6 +-- src/Polly/Fallback/FallbackEngine.cs | 7 ++- src/Polly/Fallback/FallbackPolicy.cs | 6 +-- src/Polly/RateLimit/AsyncRateLimitEngine.cs | 7 ++- src/Polly/RateLimit/AsyncRateLimitPolicy.cs | 4 +- src/Polly/Retry/AsyncRetryEngine.cs | 2 +- src/Polly/Retry/AsyncRetryPolicy.cs | 10 ++-- src/Polly/Retry/RetryEngine.cs | 5 +- src/Polly/Retry/RetryPolicy.cs | 10 ++-- src/Polly/Timeout/AsyncTimeoutEngine.cs | 4 +- src/Polly/Timeout/AsyncTimeoutPolicy.cs | 6 +-- src/Polly/Timeout/TimeoutEngine.cs | 7 ++- src/Polly/Timeout/TimeoutPolicy.cs | 6 +-- .../Wrappers/ResilienceContextFactory.cs | 7 ++- .../ResiliencePipelineAsyncPolicy.TResult.cs | 3 +- .../Wrappers/ResiliencePipelineAsyncPolicy.cs | 6 +-- .../ResiliencePipelineSyncPolicy.TResult.cs | 3 +- .../Wrappers/ResiliencePipelineSyncPolicy.cs | 6 +-- src/Polly/Wrap/AsyncPolicyWrap.cs | 18 +++---- src/Polly/Wrap/AsyncPolicyWrapEngine.cs | 41 +++++++-------- src/Polly/Wrap/PolicyWrap.cs | 18 +++---- src/Polly/Wrap/PolicyWrapEngine.cs | 51 +++++++++---------- 33 files changed, 119 insertions(+), 175 deletions(-) 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..ed4ea46624a 100644 --- a/src/Polly/Caching/AsyncCacheEngine.cs +++ b/src/Polly/Caching/AsyncCacheEngine.cs @@ -3,19 +3,18 @@ namespace Polly.Caching; internal static class AsyncCacheEngine { - internal static async Task ImplementationAsync( - IAsyncCacheProvider cacheProvider, + internal static async Task ImplementationAsync(IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, 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..64f3748bb4e 100644 --- a/src/Polly/Caching/AsyncCachePolicy.cs +++ b/src/Polly/Caching/AsyncCachePolicy.cs @@ -54,13 +54,12 @@ protected override Task ImplementationAsync(Func @@ -111,12 +110,11 @@ protected override Task ImplementationAsync(Func( - ISyncCacheProvider cacheProvider, + internal static TResult Implementation(ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, 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..36523f0e465 100644 --- a/src/Polly/Caching/CachePolicy.cs +++ b/src/Polly/Caching/CachePolicy.cs @@ -51,12 +51,11 @@ protected override TResult Implementation(Func @@ -105,10 +104,9 @@ protected override TResult Implementation(Func 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..c53135def68 100644 --- a/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/AsyncCircuitBreakerPolicy.cs @@ -44,11 +44,10 @@ 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 +102,8 @@ protected override Task ImplementationAsync(Func( - Func action, + internal static TResult Implementation(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..8b605974c66 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs @@ -44,10 +44,9 @@ 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 +100,7 @@ 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..cdce4072998 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,7 @@ 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 +76,9 @@ protected override Task ImplementationAsync(Func( - Func action, + internal static TResult Implementation(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..b8bf16f72b0 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,7 @@ 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 +72,8 @@ protected override TResult Implementation(Func ImplementationAsync( - IRateLimiter rateLimiter, + internal static async Task ImplementationAsync(IRateLimiter rateLimiter, 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..154dc1bf126 100644 --- a/src/Polly/Retry/AsyncRetryPolicy.cs +++ b/src/Polly/Retry/AsyncRetryPolicy.cs @@ -40,14 +40,13 @@ 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, - continueOnCapturedContext); + sleepDurationProvider, continueOnCapturedContext); } } @@ -83,13 +82,12 @@ protected override Task ImplementationAsync(Func( - Func action, + internal static TResult Implementation(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..3b304611e02 100644 --- a/src/Polly/Retry/RetryPolicy.cs +++ b/src/Polly/Retry/RetryPolicy.cs @@ -34,13 +34,12 @@ protected override TResult Implementation(Func.None, (outcome, timespan, retryCount, ctx) => _onRetry(outcome.Exception, timespan, retryCount, ctx), + cancellationToken, _permittedRetryCount, - _sleepDurationsEnumerable, - sleepDurationProvider); + _sleepDurationsEnumerable, sleepDurationProvider); } } @@ -75,11 +74,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..bacd39e351b 100644 --- a/src/Polly/Timeout/AsyncTimeoutPolicy.cs +++ b/src/Polly/Timeout/AsyncTimeoutPolicy.cs @@ -29,11 +29,10 @@ protected override Task ImplementationAsync( AsyncTimeoutEngine.ImplementationAsync( action, context, - cancellationToken, _timeoutProvider, _timeoutStrategy, _onTimeoutAsync, - continueOnCapturedContext); + continueOnCapturedContext, cancellationToken); } /// @@ -66,9 +65,8 @@ 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..ddd6b5fd6cc 100644 --- a/src/Polly/Timeout/TimeoutEngine.cs +++ b/src/Polly/Timeout/TimeoutEngine.cs @@ -4,13 +4,12 @@ namespace Polly.Timeout; internal static class TimeoutEngine { - internal static TResult Implementation( - Func action, + 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..ac8c8532c79 100644 --- a/src/Polly/Timeout/TimeoutPolicy.cs +++ b/src/Polly/Timeout/TimeoutPolicy.cs @@ -25,10 +25,9 @@ protected override TResult Implementation(Func @@ -56,8 +55,7 @@ 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..e1c0aabc7c5 100644 --- a/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs +++ b/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs @@ -10,9 +10,8 @@ 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..069658c9dfd 100644 --- a/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs +++ b/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs @@ -10,9 +10,8 @@ protected override TResult Implementation(Func action { var resilienceContext = ResilienceContextFactory.Create( context, - cancellationToken, true, - out var oldProperties); + out var oldProperties, cancellationToken); try { @@ -34,9 +33,8 @@ protected override TResult Implementation(Func [DebuggerStepThrough] @@ -47,10 +46,9 @@ protected override Task ImplementationAsync(Func( action, context, - cancellationToken, continueOnCapturedContext, _outer, - _inner); + _inner, cancellationToken); } /// @@ -107,20 +105,18 @@ 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 +131,9 @@ protected override Task ImplementationAsync(Func( action, context, - cancellationToken, continueOnCapturedContext, _outerGeneric, - _innerNonGeneric); + _innerNonGeneric, cancellationToken); } else if (_innerGeneric != null) @@ -146,10 +141,9 @@ 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..3a6cb0b0097 100644 --- a/src/Polly/Wrap/AsyncPolicyWrapEngine.cs +++ b/src/Polly/Wrap/AsyncPolicyWrapEngine.cs @@ -2,13 +2,12 @@ internal static class AsyncPolicyWrapEngine { - internal static Task ImplementationAsync( - Func> func, + 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, @@ -19,13 +18,12 @@ internal static Task ImplementationAsync( cancellationToken, continueOnCapturedContext); - internal static Task ImplementationAsync( - Func> func, + 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, @@ -36,13 +34,12 @@ internal static Task ImplementationAsync( cancellationToken, continueOnCapturedContext); - internal static Task ImplementationAsync( - Func> func, + 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, @@ -53,13 +50,12 @@ internal static Task ImplementationAsync( cancellationToken, continueOnCapturedContext); - internal static Task ImplementationAsync( - Func> func, - Context context, - CancellationToken cancellationToken, - bool continueOnCapturedContext, - IAsyncPolicy outerPolicy, - IAsyncPolicy innerPolicy) => + internal static Task ImplementationAsync(Func> func, + Context context, + bool continueOnCapturedContext, + IAsyncPolicy outerPolicy, + IAsyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.ExecuteAsync( (ctx, ct) => innerPolicy.ExecuteAsync( func, @@ -70,13 +66,12 @@ internal static Task ImplementationAsync( cancellationToken, continueOnCapturedContext); - internal static Task ImplementationAsync( - Func action, + 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..08249a24003 100644 --- a/src/Polly/Wrap/PolicyWrap.cs +++ b/src/Polly/Wrap/PolicyWrap.cs @@ -31,9 +31,8 @@ protected override void Implementation(Action action PolicyWrapEngine.Implementation( action, context, - cancellationToken, _outer, - _inner); + _inner, cancellationToken); /// [DebuggerStepThrough] @@ -41,9 +40,8 @@ protected override TResult Implementation(Func( action, context, - cancellationToken, _outer, - _inner); + _inner, cancellationToken); } /// @@ -99,18 +97,16 @@ 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 +120,8 @@ protected override TResult Implementation(Func( action, context, - cancellationToken, _outerGeneric, - _innerNonGeneric); + _innerNonGeneric, cancellationToken); } else if (_innerGeneric != null) @@ -134,9 +129,8 @@ 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..4bcedde56b7 100644 --- a/src/Polly/Wrap/PolicyWrapEngine.cs +++ b/src/Polly/Wrap/PolicyWrapEngine.cs @@ -2,43 +2,38 @@ internal static class PolicyWrapEngine { - internal static TResult Implementation( - Func func, + 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) => + internal static TResult Implementation(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) => + internal static TResult Implementation(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) => + internal static TResult Implementation(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) => + internal static void Implementation(Action action, + Context context, + ISyncPolicy outerPolicy, + ISyncPolicy innerPolicy, + CancellationToken cancellationToken) => outerPolicy.Execute((ctx, ct) => innerPolicy.Execute(action, ctx, ct), context, cancellationToken); } From d96a22595ea983d19a6720395321a2cecbe12745 Mon Sep 17 00:00:00 2001 From: iamdmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:35:59 +0300 Subject: [PATCH 3/6] Fix pragma placing To avoid SA1114 --- src/Polly/AsyncPolicy.GenericImplementation.cs | 2 +- src/Polly/AsyncPolicy.NonGenericImplementation.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Polly/AsyncPolicy.GenericImplementation.cs b/src/Polly/AsyncPolicy.GenericImplementation.cs index a15b93879e5..38a18fdd371 100644 --- a/src/Polly/AsyncPolicy.GenericImplementation.cs +++ b/src/Polly/AsyncPolicy.GenericImplementation.cs @@ -12,8 +12,8 @@ public abstract partial class AsyncPolicy /// Whether async continuations should continue on a captured context. /// A representing the result of the execution. protected abstract Task ImplementationAsync( -#pragma warning restore CA1068 Func> action, +#pragma warning restore CA1068 Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); diff --git a/src/Polly/AsyncPolicy.NonGenericImplementation.cs b/src/Polly/AsyncPolicy.NonGenericImplementation.cs index f1052b5f760..2c212c773f5 100644 --- a/src/Polly/AsyncPolicy.NonGenericImplementation.cs +++ b/src/Polly/AsyncPolicy.NonGenericImplementation.cs @@ -12,8 +12,8 @@ public abstract partial class AsyncPolicy /// Whether async continuations should continue on a captured context. /// A representing the result of the execution. protected virtual Task ImplementationAsync( -#pragma warning restore CA1068 Func action, +#pragma warning restore CA1068 Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => @@ -34,8 +34,8 @@ protected virtual Task ImplementationAsync( /// Whether async continuations should continue on a captured context. /// A representing the result of the execution. protected abstract Task ImplementationAsync( -#pragma warning restore CA1068 Func> action, +#pragma warning restore CA1068 Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); From 9a45e4b24ee9668588be0ae04cd443476b98d885 Mon Sep 17 00:00:00 2001 From: iamdmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:44:33 +0300 Subject: [PATCH 4/6] Fix ReSharper leftovers --- src/Polly/Caching/AsyncCacheEngine.cs | 3 ++- src/Polly/Caching/AsyncCachePolicy.cs | 6 ++++-- src/Polly/Caching/CacheEngine.cs | 3 ++- src/Polly/Caching/CachePolicy.cs | 6 ++++-- .../AsyncCircuitBreakerPolicy.cs | 6 ++++-- .../CircuitBreaker/CircuitBreakerEngine.cs | 3 ++- .../CircuitBreaker/CircuitBreakerPolicy.cs | 6 ++++-- src/Polly/Fallback/AsyncFallbackPolicy.cs | 6 ++++-- src/Polly/Fallback/FallbackEngine.cs | 3 ++- src/Polly/Fallback/FallbackPolicy.cs | 6 ++++-- src/Polly/RateLimit/AsyncRateLimitEngine.cs | 3 ++- src/Polly/Retry/AsyncRetryPolicy.cs | 6 ++++-- src/Polly/Retry/RetryEngine.cs | 3 ++- src/Polly/Retry/RetryPolicy.cs | 6 ++++-- src/Polly/Timeout/AsyncTimeoutPolicy.cs | 6 ++++-- src/Polly/Timeout/TimeoutEngine.cs | 3 ++- src/Polly/Timeout/TimeoutPolicy.cs | 6 ++++-- .../Wrappers/ResilienceContextFactory.cs | 3 ++- .../ResiliencePipelineAsyncPolicy.TResult.cs | 3 ++- .../Wrappers/ResiliencePipelineAsyncPolicy.cs | 6 ++++-- .../ResiliencePipelineSyncPolicy.TResult.cs | 3 ++- .../Wrappers/ResiliencePipelineSyncPolicy.cs | 6 ++++-- src/Polly/Wrap/AsyncPolicyWrap.cs | 18 ++++++++++++------ src/Polly/Wrap/AsyncPolicyWrapEngine.cs | 15 ++++++++++----- src/Polly/Wrap/PolicyWrap.cs | 18 ++++++++++++------ src/Polly/Wrap/PolicyWrapEngine.cs | 15 ++++++++++----- 26 files changed, 112 insertions(+), 56 deletions(-) diff --git a/src/Polly/Caching/AsyncCacheEngine.cs b/src/Polly/Caching/AsyncCacheEngine.cs index ed4ea46624a..ccf9c2b195a 100644 --- a/src/Polly/Caching/AsyncCacheEngine.cs +++ b/src/Polly/Caching/AsyncCacheEngine.cs @@ -3,7 +3,8 @@ namespace Polly.Caching; internal static class AsyncCacheEngine { - internal static async Task ImplementationAsync(IAsyncCacheProvider cacheProvider, + internal static async Task ImplementationAsync( + IAsyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Func> action, diff --git a/src/Polly/Caching/AsyncCachePolicy.cs b/src/Polly/Caching/AsyncCachePolicy.cs index 64f3748bb4e..07f6f3ff8b9 100644 --- a/src/Polly/Caching/AsyncCachePolicy.cs +++ b/src/Polly/Caching/AsyncCachePolicy.cs @@ -59,7 +59,8 @@ protected override Task ImplementationAsync(Func @@ -115,6 +116,7 @@ protected override Task ImplementationAsync(Func(ISyncCacheProvider cacheProvider, + internal static TResult Implementation( + ISyncCacheProvider cacheProvider, ITtlStrategy ttlStrategy, Func cacheKeyStrategy, Func action, diff --git a/src/Polly/Caching/CachePolicy.cs b/src/Polly/Caching/CachePolicy.cs index 36523f0e465..7d9df28e3a4 100644 --- a/src/Polly/Caching/CachePolicy.cs +++ b/src/Polly/Caching/CachePolicy.cs @@ -55,7 +55,8 @@ protected override TResult Implementation(Func @@ -108,5 +109,6 @@ protected override TResult Implementation(Func( continueOnCapturedContext, ExceptionPredicates, ResultPredicates.None, - BreakerController, cancellationToken).ConfigureAwait(continueOnCapturedContext); + BreakerController, + cancellationToken).ConfigureAwait(continueOnCapturedContext); return result; } } @@ -105,5 +106,6 @@ protected override Task ImplementationAsync(Func(Func action, + internal static TResult Implementation( + Func action, Context context, ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, diff --git a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs index 8b605974c66..f4954804cc8 100644 --- a/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs +++ b/src/Polly/CircuitBreaker/CircuitBreakerPolicy.cs @@ -46,7 +46,8 @@ protected override TResult Implementation(Func.None, - BreakerController, cancellationToken); + BreakerController, + cancellationToken); return result; } } @@ -102,5 +103,6 @@ protected override TResult Implementation(Func protected override Task ImplementationAsync(Func> action, Context context, CancellationToken cancellationToken, @@ -80,5 +81,6 @@ protected override Task ImplementationAsync(Func(Func action, + internal static TResult Implementation( + Func action, Context context, ExceptionPredicates shouldHandleExceptionPredicates, ResultPredicates shouldHandleResultPredicates, diff --git a/src/Polly/Fallback/FallbackPolicy.cs b/src/Polly/Fallback/FallbackPolicy.cs index b8bf16f72b0..da2fb119e84 100644 --- a/src/Polly/Fallback/FallbackPolicy.cs +++ b/src/Polly/Fallback/FallbackPolicy.cs @@ -37,7 +37,8 @@ protected override void Implementation(Action action { _fallbackAction(outcome.Exception, ctx, ct); return EmptyStruct.Instance; - }, cancellationToken); + }, + cancellationToken); /// protected override TResult Implementation(Func action, Context context, CancellationToken cancellationToken) => @@ -75,5 +76,6 @@ protected override TResult Implementation(Func ImplementationAsync(IRateLimiter rateLimiter, + internal static async Task ImplementationAsync( + IRateLimiter rateLimiter, Func? retryAfterFactory, Func> action, Context context, diff --git a/src/Polly/Retry/AsyncRetryPolicy.cs b/src/Polly/Retry/AsyncRetryPolicy.cs index 154dc1bf126..195b5a4767b 100644 --- a/src/Polly/Retry/AsyncRetryPolicy.cs +++ b/src/Polly/Retry/AsyncRetryPolicy.cs @@ -46,7 +46,8 @@ protected override Task ImplementationAsync( cancellationToken, _permittedRetryCount, _sleepDurationsEnumerable, - sleepDurationProvider, continueOnCapturedContext); + sleepDurationProvider, + continueOnCapturedContext); } } @@ -88,6 +89,7 @@ protected override Task ImplementationAsync(Func(Func action, + internal static TResult Implementation( + Func action, Context context, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates shouldRetryResultPredicates, diff --git a/src/Polly/Retry/RetryPolicy.cs b/src/Polly/Retry/RetryPolicy.cs index 3b304611e02..d85258b3ed4 100644 --- a/src/Polly/Retry/RetryPolicy.cs +++ b/src/Polly/Retry/RetryPolicy.cs @@ -39,7 +39,8 @@ protected override TResult Implementation(Func _onRetry(outcome.Exception, timespan, retryCount, ctx), cancellationToken, _permittedRetryCount, - _sleepDurationsEnumerable, sleepDurationProvider); + _sleepDurationsEnumerable, + sleepDurationProvider); } } @@ -79,5 +80,6 @@ protected override TResult Implementation(Func ImplementationAsync( _timeoutProvider, _timeoutStrategy, _onTimeoutAsync, - continueOnCapturedContext, cancellationToken); + continueOnCapturedContext, + cancellationToken); } /// @@ -68,5 +69,6 @@ protected override Task ImplementationAsync( _timeoutProvider, _timeoutStrategy, _onTimeoutAsync, - continueOnCapturedContext, cancellationToken); + continueOnCapturedContext, + cancellationToken); } diff --git a/src/Polly/Timeout/TimeoutEngine.cs b/src/Polly/Timeout/TimeoutEngine.cs index ddd6b5fd6cc..2afbfd0685c 100644 --- a/src/Polly/Timeout/TimeoutEngine.cs +++ b/src/Polly/Timeout/TimeoutEngine.cs @@ -4,7 +4,8 @@ namespace Polly.Timeout; internal static class TimeoutEngine { - internal static TResult Implementation(Func action, + internal static TResult Implementation( + Func action, Context context, Func timeoutProvider, TimeoutStrategy timeoutStrategy, diff --git a/src/Polly/Timeout/TimeoutPolicy.cs b/src/Polly/Timeout/TimeoutPolicy.cs index ac8c8532c79..52bcfc875b9 100644 --- a/src/Polly/Timeout/TimeoutPolicy.cs +++ b/src/Polly/Timeout/TimeoutPolicy.cs @@ -27,7 +27,8 @@ protected override TResult Implementation(Func @@ -57,5 +58,6 @@ protected override TResult Implementation(Func oldProperties, CancellationToken cancellationToken) diff --git a/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs b/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs index e1c0aabc7c5..9a32cb3df32 100644 --- a/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs +++ b/src/Polly/Utilities/Wrappers/ResiliencePipelineAsyncPolicy.TResult.cs @@ -11,7 +11,8 @@ protected override async Task ImplementationAsync(Func ImplementationAsync( var resilienceContext = ResilienceContextFactory.Create( context, continueOnCapturedContext, - out var oldProperties, cancellationToken); + out var oldProperties, + cancellationToken); try { diff --git a/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs b/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs index 069658c9dfd..4ebce11e4b1 100644 --- a/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs +++ b/src/Polly/Utilities/Wrappers/ResiliencePipelineSyncPolicy.TResult.cs @@ -11,7 +11,8 @@ protected override TResult Implementation(Func action var resilienceContext = ResilienceContextFactory.Create( context, true, - out var oldProperties, cancellationToken); + out var oldProperties, + cancellationToken); try { @@ -34,7 +35,8 @@ protected override TResult Implementation(Func [DebuggerStepThrough] @@ -48,7 +49,8 @@ protected override Task ImplementationAsync(Func @@ -107,7 +109,8 @@ protected override Task ImplementationAsync(Func ImplementationAsync(Func ImplementationAsync(Func ImplementationAsync(Func ImplementationAsync(Func> func, + internal static Task ImplementationAsync( + Func> func, Context context, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, @@ -18,7 +19,8 @@ internal static Task ImplementationAsync(Func ImplementationAsync(Func> func, + internal static Task ImplementationAsync( + Func> func, Context context, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, @@ -34,7 +36,8 @@ internal static Task ImplementationAsync(Func ImplementationAsync(Func> func, + internal static Task ImplementationAsync( + Func> func, Context context, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, @@ -50,7 +53,8 @@ internal static Task ImplementationAsync(Func ImplementationAsync(Func> func, + internal static Task ImplementationAsync( + Func> func, Context context, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, @@ -66,7 +70,8 @@ internal static Task ImplementationAsync(Func action, + internal static Task ImplementationAsync( + Func action, Context context, bool continueOnCapturedContext, IAsyncPolicy outerPolicy, diff --git a/src/Polly/Wrap/PolicyWrap.cs b/src/Polly/Wrap/PolicyWrap.cs index 08249a24003..5c2dea29414 100644 --- a/src/Polly/Wrap/PolicyWrap.cs +++ b/src/Polly/Wrap/PolicyWrap.cs @@ -32,7 +32,8 @@ protected override void Implementation(Action action action, context, _outer, - _inner, cancellationToken); + _inner, + cancellationToken); /// [DebuggerStepThrough] @@ -41,7 +42,8 @@ protected override TResult Implementation(Func @@ -98,7 +100,8 @@ protected override TResult Implementation(Func(Func func, + internal static TResult Implementation( + 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, + internal static TResult Implementation( + 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, + internal static TResult Implementation( + 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, + internal static TResult Implementation( + 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, + internal static void Implementation( + Action action, Context context, ISyncPolicy outerPolicy, ISyncPolicy innerPolicy, From 6bca8a17acfe54e8b9b6855c6ad6cc5077faf452 Mon Sep 17 00:00:00 2001 From: iamdmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:14:53 +0300 Subject: [PATCH 5/6] Add missing pragma restore --- src/Polly/IAsyncPolicy.TResult.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Polly/IAsyncPolicy.TResult.cs b/src/Polly/IAsyncPolicy.TResult.cs index 692eba1d0bf..340f63975f4 100644 --- a/src/Polly/IAsyncPolicy.TResult.cs +++ b/src/Polly/IAsyncPolicy.TResult.cs @@ -162,6 +162,7 @@ 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 /// From 7f88f8f52dfe0f998c3dae657ea7516cf1a03c08 Mon Sep 17 00:00:00 2001 From: iamdmitrij <3024338+iamdmitrij@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:35:46 +0300 Subject: [PATCH 6/6] Reorder pragmas --- src/Polly/AsyncPolicy.GenericImplementation.cs | 2 +- src/Polly/AsyncPolicy.NonGenericImplementation.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Polly/AsyncPolicy.GenericImplementation.cs b/src/Polly/AsyncPolicy.GenericImplementation.cs index 38a18fdd371..152e9900857 100644 --- a/src/Polly/AsyncPolicy.GenericImplementation.cs +++ b/src/Polly/AsyncPolicy.GenericImplementation.cs @@ -13,8 +13,8 @@ public abstract partial class AsyncPolicy /// A representing the result of the execution. protected abstract Task ImplementationAsync( Func> action, -#pragma warning restore CA1068 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 2c212c773f5..5d04568d03f 100644 --- a/src/Polly/AsyncPolicy.NonGenericImplementation.cs +++ b/src/Polly/AsyncPolicy.NonGenericImplementation.cs @@ -13,11 +13,11 @@ public abstract partial class AsyncPolicy /// A representing the result of the execution. protected virtual Task ImplementationAsync( Func action, -#pragma warning restore CA1068 Context context, CancellationToken cancellationToken, bool continueOnCapturedContext) => ImplementationAsync(async (ctx, token) => +#pragma warning restore CA1068 { await action(ctx, token).ConfigureAwait(continueOnCapturedContext); return EmptyStruct.Instance; @@ -35,8 +35,8 @@ protected virtual Task ImplementationAsync( /// A representing the result of the execution. protected abstract Task ImplementationAsync( Func> action, -#pragma warning restore CA1068 Context context, CancellationToken cancellationToken, bool continueOnCapturedContext); +#pragma warning restore CA1068 }