ExecutionStrategy ExecutionStrategy Class

Definition

The base class for IExecutionStrategy implementations.

public abstract class ExecutionStrategy : IExecutionStrategy
Public MustInherit Class ExecutionStrategy
    Implements IExecutionStrategy
Inheritance
System.ObjectSystem.Object
ExecutionStrategyExecutionStrategy
Implements

Constructors

ExecutionStrategy(ExecutionStrategyContext, Int32, TimeSpan) ExecutionStrategy(ExecutionStrategyContext, Int32, TimeSpan)

Creates a new instance of ExecutionStrategy.

protected ExecutionStrategy(ExecutionStrategyContext context, int maxRetryCount, TimeSpan maxRetryDelay)
Protected Sub New(context As ExecutionStrategyContext, maxRetryCount As Integer, maxRetryDelay As TimeSpan)
Parameters
context
ExecutionStrategyContext ExecutionStrategyContext

The required dependencies.

maxRetryCount
System.Int32 System.Int32

The maximum number of retry attempts.

maxRetryDelay
System.TimeSpan System.TimeSpan

The maximum delay in milliseconds between retries.

Fields

DefaultMaxDelay DefaultMaxDelay

The default maximum time delay between retries, must be nonnegative.

protected static readonly TimeSpan DefaultMaxDelay
Protected Shared ReadOnly DefaultMaxDelay As TimeSpan

DefaultMaxRetryCount DefaultMaxRetryCount

The default number of retry attempts.

protected static readonly int DefaultMaxRetryCount
Protected Shared ReadOnly DefaultMaxRetryCount As Integer

Properties

Context Context

The context on which the operations will be invoked.

protected virtual DbContext Context { get; }
Protected Overridable ReadOnly Property Context As DbContext

ExceptionsEncountered ExceptionsEncountered

The list of exceptions that caused the operation to be retried so far.

protected virtual List<Exception> ExceptionsEncountered { get; }
Protected Overridable ReadOnly Property ExceptionsEncountered As List(Of Exception)
Value
System.Collections.Generic.List<System.Exception> System.Collections.Generic.List(Of System.Exception)

Logger Logger

The logger for this ExecutionStrategy.

protected virtual ILogger<IExecutionStrategy> Logger { get; }
Protected Overridable ReadOnly Property Logger As ILogger(Of IExecutionStrategy)
Value
ILogger<IExecutionStrategy> ILogger(Of IExecutionStrategy)

MaxRetryCount MaxRetryCount

The maximum number of retry attempts.

protected virtual int MaxRetryCount { get; }
Protected Overridable ReadOnly Property MaxRetryCount As Integer
Value
System.Int32 System.Int32

MaxRetryDelay MaxRetryDelay

The maximum delay in milliseconds between retries.

protected virtual TimeSpan MaxRetryDelay { get; }
Protected Overridable ReadOnly Property MaxRetryDelay As TimeSpan
Value
System.TimeSpan System.TimeSpan

Random Random

A pseudo-random number generater that can be used to vary the delay between retries.

protected virtual Random Random { get; }
Protected Overridable ReadOnly Property Random As Random
Value
System.Random System.Random

RetriesOnFailure RetriesOnFailure

Indicates whether this IExecutionStrategy might retry the execution after a failure.

public virtual bool RetriesOnFailure { get; }
Public Overridable ReadOnly Property RetriesOnFailure As Boolean
Value
System.Boolean System.Boolean

Suspended Suspended

Indicates whether the strategy is suspended. The strategy is typically suspending while executing to avoid recursive execution from nested operations.

protected static bool Suspended { get; set; }
Protected Shared Property Suspended As Boolean
Value
System.Boolean System.Boolean

Methods

Equals(Object) Equals(Object)

Inherited from System.Object

Equals(Object, Object) Equals(Object, Object)

Inherited from System.Object

Execute(Func, TState) Execute(Of TState, TResult)(Func(Of TState, TResult), TState)

Executes the specified operation and returns the result.

public virtual TResult Execute<TState, TResult>(Func<TState, TResult> operation, TState state)
Public Overridable Function Execute(Of TState, TResult)(operation As Func(Of TState, TResult), state As TState) As TResult
Type Parameters
TState

The type of the state.

TResult

The return type of operation.

Parameters
operation
System.Func<TState, TResult> System.Func(Of TState, TResult)

A delegate representing an executable operation that returns the result of type TResult.

state
TState TState

The state that will be passed to the operation.

Returns
TResult TResult

The result from the operation.

ExecuteAsync(Func>, TState, CancellationToken) ExecuteAsync(Of TState, TResult)(Func(Of TState, CancellationToken, Task(Of TResult)), TState, CancellationToken)

Executes the specified asynchronous operation and returns the result.

public virtual Task<TResult> ExecuteAsync<TState, TResult>(Func<TState, CancellationToken, Task<TResult>> operation, TState state, CancellationToken cancellationToken = null)
Public Overridable Function ExecuteAsync(Of TState, TResult)(operation As Func(Of TState, CancellationToken, Task(Of TResult)), state As TState, cancellationToken As CancellationToken = Nothing) As Task(Of TResult)
Type Parameters
TState

The type of the state.

TResult

The result type of the System.Threading.Tasks.Task<TResult> returned by operation.

Parameters
operation
System.Func<TState, System.Threading.CancellationToken, System.Threading.Tasks.Task<TResult>> System.Func(Of TState, System.Threading.CancellationToken, System.Threading.Tasks.Task(Of TResult))

A function that returns a started task of type TResult.

state
TState TState

The state that will be passed to the operation.

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

A cancellation token used to cancel the retry operation, but not operations that are already in flight or that already completed successfully.

Returns
System.Threading.Tasks.Task<TResult> System.Threading.Tasks.Task(Of TResult)

A task that will run to completion if the original task completes successfully (either the first time or after retrying transient failures). If the task fails with a non-transient error or the retry limit is reached, the returned task will become faulted and the exception must be observed.

GetHashCode() GetHashCode()

Inherited from System.Object

GetNextDelay(Exception) GetNextDelay(Exception)

Determines whether the operation should be retried and the delay before the next attempt.

protected virtual TimeSpan? GetNextDelay(Exception lastException)
Protected Overridable Function GetNextDelay(lastException As Exception) As TimeSpan?
Parameters
lastException
System.Exception System.Exception

The exception thrown during the last execution attempt.

Returns
System.Nullable<System.TimeSpan> System.Nullable(Of System.TimeSpan)

Returns the delay indicating how long to wait for before the next execution attempt if the operation should be retried; null otherwise

GetType() GetType()

Inherited from System.Object

MemberwiseClone() MemberwiseClone()

Inherited from System.Object

OnFirstExecution() OnFirstExecution()

Method called before the first operation execution

protected virtual void OnFirstExecution()
Protected Overridable Sub OnFirstExecution

OnRetry() OnRetry()

Method called before retrying the operation execution

protected virtual void OnRetry()
Protected Overridable Sub OnRetry

ReferenceEquals(Object, Object) ReferenceEquals(Object, Object)

Inherited from System.Object

ShouldRetryOn(Exception) ShouldRetryOn(Exception)

Determines whether the specified exception represents a transient failure that can be compensated by a retry.

protected abstract bool ShouldRetryOn(Exception exception)
Protected MustOverride Function ShouldRetryOn(exception As Exception) As Boolean
Parameters
exception
System.Exception System.Exception

The exception object to be verified.

Returns
System.Boolean System.Boolean

true if the specified exception is considered as transient, otherwise false.

ToString() ToString()

Inherited from System.Object

UnwrapAndHandleException(Exception, Func) UnwrapAndHandleException(Of T)(Exception, Func(Of Exception, T))

Recursively gets InnerException from exception as long as it's an exception created by Entity Framework and passes it to exceptionHandler

public static T UnwrapAndHandleException<T>(Exception exception, Func<Exception, T> exceptionHandler)
Public Shared Function UnwrapAndHandleException(Of T)(exception As Exception, exceptionHandler As Func(Of Exception, T)) As T
Type Parameters
T

The type of the unwrapped exception.

Parameters
exception
System.Exception System.Exception

The exception to be unwrapped.

exceptionHandler
System.Func<System.Exception, T> System.Func(Of System.Exception, T)

A delegate that will be called with the unwrapped exception.

Returns
T T

The result from exceptionHandler.