Class EnumerableRunnerBase<TItem>
- Namespace
- MVVrus.AspNetCore.ActiveSession
- Assembly
- MVVrus.AspNetCore.ActiveSession.dll
This class is a base class for sequence-oriented runner classes (see Remarks section). It is an abstract class intended to be a base for specific sequence-oriented runner classes. It implements a common logic for those runners.
public abstract class EnumerableRunnerBase<TItem> : RunnerBase, IDisposable, IRunner<IEnumerable<TItem>>, IRunner, IAsyncDisposable
Type Parameters
TItem
Type of items of a sequence (IEnumerable<TItem> interface) that a background process of the runner returns.
- Inheritance
-
EnumerableRunnerBase<TItem>
- Implements
-
IRunner<IEnumerable<TItem>>
- Derived
- Inherited Members
- Extension Methods
Remarks
Sequence-oriented runners are ones that return a sequence of data records as a result. These runners implements IRunner<TResult> interface, with TResult type being an implementation of IEnumerable<TItem> interface.
Sequence-oriented runners returns parts of a sequence produced in a background by some process. The parts are returned via calls of GetRequiredAsync and/or GetAvailable methods. These parts may be obtained during processing of different HTTP requests belonging to one Active Session. All calls to these methods must be made in order and calls of these methods must not be made in parallel.
The common logic implemented in this class uses a queue that allows storing in it data fetched in background. Methods defined by IRunner<TResult> interface that returns results (namely GetAvailable and GetRequiredAsync) returns parts of the queue contents in the same order as those items have been placed into the queue.
Methods that returns results (namely GetAvailable and GetRequiredAsync) can start fetching data only from the current Position of the runner overwise InvalidOperationException exception will be thrown.
Constructors
- EnumerableRunnerBase(CancellationTokenSource?, bool, RunnerId, ILogger?, IOptionsSnapshot<ActiveSessionOptions>, int?, int?)
Constructor for a runner object to be used in descendent classes
- EnumerableRunnerBase(CancellationTokenSource?, bool, RunnerId, ILogger?, int, int)
Constructor for a runner object to be used in descendent classes
Properties
- IsBackgroundExecutionCompleted
Indicate whether the background operation is completed.
- Position
Current position of the runner object. It is a part of IRunner interface implementation.
Overrides RunnerBase.Position.
- QueueCount
Protected. Returns a number of itmes left in the queue.
- QueueIsAddingCompleted
Protected. Returns a boolean value indicating whether a background execution (that adds items to the queue) is completed.
- Status
Current status of the runner object. It is a part of IRunner interface implementation. Overrides RunnerBase.Status.
Methods
- Dispose(bool)
Protected, overrides RunnerBase.Dispose(bool), sealed.
This method performs a real work of disposing the object instance (synchronously).
- DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously. This method is a part of implementation of IAsyncDisposable interface.
- DisposeAsyncCore()
Protected virtual.
This method performs a real work of disposing the object instance asynchronously.
- DoAbort(string)
Protected, overrides RunnerBase.DoAbort(string). This method performs and additional work for implementing the Abort(string?) method.
- FetchRequiredAsync(int, List<TItem>, CancellationToken, string)
Protected abstract.
Creates a task representing an asynchronous fetch of results of the background processing to be returned by GetRequiredAsync method.
- GetAvailable(int, int, string?)
Returns a result of the runner available at the moment of the method call. This is a part of IRunner<IEnumerable<TItem>> implementation.
- GetProgress()
Returns information about progress of background operation of a runner.
- GetRequiredAsync(int, CancellationToken, int, string?)
Asynchronously fetch result from the runner up to the specified point. This is a part of IRunner<IEnumerable<TItem>> implementation.
- PreDispose()
Protected, overrides RunnerBase.PreDispose(). Performs preliminary tasks before beginning of disposing any members of any descendent class.
- QueueCompleteAdding()
Protected. Marks the end of the background execution. That means that no more items will be added to the queue.
- QueueTryAdd(TItem)
Protected. Adds an item to the queue.
- QueueTryTake(out TItem)
Protected. Tries to remove the first item from the queue and return it if such an item exists.