-
Notifications
You must be signed in to change notification settings - Fork 2
Base Classes
Welcome to the documentation page for the classes located in the main directory of this project. Below, you’ll find a summary of the key classes and their functionalities.
- Base classes
- Container
- Implementation
The IRequest interface defines the properties and methods necessary for the RequestHandler to process an IRequest implementation.
-
State: Type:
RequestState- Provides information about the state of the
IRequestimplementation.
- Provides information about the state of the
-
StateChanged: Type:
EventHandler<RequestState>- Should be called when the state of the
IRequestchanges.
- Should be called when the state of the
-
Priority: Type:
RequestPriority- Indicates the priority of the
IRequestimplementation.
- Indicates the priority of the
-
Task: Type:
Task- Should represents the asynchronous state of the implementation (finished, failed, or running).
-
Exception: Type:
Nullable<AggregateException>- Should provide details of any exceptions that occurred during the execution of the
IRequest.
- Should provide details of any exceptions that occurred during the execution of the
-
StartRequestAsync: Type:
Task- Initiates the execution of the
IRequestimplementation asynchronously.
- Initiates the execution of the
-
Start: Type:
void- Deploys the
IRequestimplementation into theRequestHandler.
- Deploys the
-
Cancel: Type:
void- Cancels all ongoing processes and disposes of the implementation.
-
Pause: Type:
void- Stops ongoing processes gracefully and saves their current state.
-
TrySetIdle: Type:
bool- Tries to set the State of the
IRequestimplementation to idle for manual processing by aRequestHandler.
- Tries to set the State of the
$\text{Request<\color{orange}TOptions\color{none},\color{green}TCompleated\color{none},\color{red}TFailed\color{none}>}$ Abstract Class
The abstract Request<> class implements fundamental functionalities
for managing requests within the RequestHandler. It implements
IRequest and is generic, allowing for three type parameters.
-
$\text{\color{orange}TOptions}$ : Type:RequestOptions<TCompleated, TFailed>- Specifies which
RequestOptionsshould be used by theRequest<>.
- Specifies which
-
$\text{\color{green}TCompleated}$ : Type: None- Represents the return type when the
Request<>completes successfully.
- Represents the return type when the
-
$\text{\color{red}TFailed}$ : Type: None- Represents the return type when the
Request<>fails to run successfully after all retries.
- Represents the return type when the
-
AttemptCounter: Type:
int- Keeps track of the number of retries for the
Request<>.
- Keeps track of the number of retries for the
-
SynchronizationContext: Type:
SynchronizationContext- Provides the synchronization context for syncing callback events.
-
StartOptions: Type:
TOptions- Holds the
Optionsobject passed during construction of theRequest<>.
- Holds the
-
Token: Type:
CancellationToken- Indicates whether a
Requestwas canceled.
- Indicates whether a
-
Task: Type:
Task- Represents the asynchronous state of the object (finished, failed, or running).
-
Exception: Type:
AggregateException- Stores any exceptions thrown by the
Request<>.
- Stores any exceptions thrown by the
-
DeployDelay: Type:
TimeSpan- Specifies the time the
Request<>waits before being deployed to theRequestHandler.
- Specifies the time the
-
State: Type:
RequestState- Provides information about the state of the
Request<>.
- Provides information about the state of the
-
StateChanged: Type:
EventHandler<RequestState>- Invoked when the state of the
Request<>changes.
- Invoked when the state of the
-
Priority: Type:
RequestPriority- Indicates the priority of the
Request<>within theRequestHandler.
- Indicates the priority of the
-
protectedOptions: Type:TOptions- Contains the modified
Optionsobject used by theRequest<>.
- Contains the modified
-
Constructor:
- Creates a
Request<>object. You can pass aTOptionsto customize its behavior.
- Creates a
-
Start: Type:
void- Deploys the request into the
RequestHandler.
- Deploys the request into the
-
Pause: Type:
void- Pauses the
RequestState.
- Pauses the
-
TrySetIdle: Type:
bool- Attempts to set the state of the
Request<>implementation to idle, either for manual addition to aRequestHandleror for manual execution using theIRequest.StartRequestAsyncmethod.
- Attempts to set the state of the
-
Cancel: Type:
void- Cancels the
Request<>, including theCancellationTokenSource, and sets the state to canceled.
- Cancels the
-
Wait: Type:
void- Waits for the
TaskCompletionSourceto finish.
- Waits for the
-
Dispose: Type:
void- Disposes of the
Request<>.
- Disposes of the
-
IRequest.StartRequestAsync: Type:
Task- Handles the initial part of the execution.
-
protected abstractRunRequestAsync: Type:Task<RequestReturn>- Must be implemented by the specific
Request<>implementation. - Executes the main request logic and returns a
RequestReturnobject with relevant information.
- Must be implemented by the specific
-
protectedAutoStart: Type:void- Automatically starts the
Request<>upon creation.
- Automatically starts the
-
privateTryRunRequestAsync: Type:Task- Runs the
RunRequestAsyncmethod within a try-catch block and captures unhandled exceptions.
- Runs the
-
privateEvaluateRequest: Type:void- Evaluates whether the task ran successfully or encountered errors.
-
privateSetTaskState: Type:void- Sets the task state based on the evaluation from
EvaluateRequest.
- Sets the task state based on the evaluation from
-
privateRegisterNewCTS: Type:void- Disposes the old
CancellationTokenSourceand registers a new one.
- Disposes the old
-
privateCreateNewCTS: Type:CancellationTokenSource- Creates a new
CancellationTokenSource.
- Creates a new
-
privateAddException: Type:void- Adds an exception to the
AggregateException.
- Adds an exception to the
-
privateWaitAndDeploy: Type:Task- Asynchronously waits for the deploy delay time.
The RequestReturn class is an anonymous class used within the Request<> to hold return and notification objects during a Request<> run.
-
CompleatedReturn: Type:
Nullable<TCompleated>- Description: Represents the object that will be returned by the
RequestOptions<TCompleated, TFailed>.RequestCompleteddelegate when the request completes successfully.
- Description: Represents the object that will be returned by the
-
FailedReturn: Type:
Nullable<TFailed>- Description: Represents the object that will be returned by the
RequestOptions<TCompleated, TFailed>.RequestFaileddelegate when the request fails to run successfully after all retries.
- Description: Represents the object that will be returned by the
-
Successful: Type:
bool- Description: Indicates whether the
Request<>was successful.
- Description: Indicates whether the
The RequestHandler class manages all IRequest objects in the priority channel. It starts and restarts them if they fail. Additionally, it handles the degree of parallelism and manages the main cancellation token.
-
IsRunning: Type:
bool- Indicates whether the
RequestHandleris currently running or not handling any requests.
- Indicates whether the
-
StaticDegreeOfParallelism: Type:
Nullable<int>- Gets or sets the static degree of parallelism. If set, it disables auto-parallelism. The default value is
null, which enables auto-parallelism.
- Gets or sets the static degree of parallelism. If set, it disables auto-parallelism. The default value is
-
AutoParallelism: Type:
Func<int>- A function to dynamically calculate the parallelism while the handler is running.
-
MaxParallelism: Type:
int- The value that represents the highest possible degree of parallelism.
-
CancellationToken: Type:
CancellationToken- The main cancellation token of a
Handlerinstance. It applies to all requests within the handler instance.
- The main cancellation token of a
-
MainRequestHandlers: Type:
static RequestHandler[]- Two preset main handlers that can be used to handle requests.
-
DefaultSynchronizationContext: Type:
SynchronizationContext- A default synchronization context that targets the ThreadPool. It can be used for all
IRequestimplementations if needed.
- A default synchronization context that targets the ThreadPool. It can be used for all
-
CountRequests: Type:
int- Counts all
IRequestobjects that have not yet been handled.
- Counts all
-
Constructor:
- Creates a
RequestHandlerobject. You can passIRequestobjects to start them.
- Creates a
-
AddRequest: Type:
void- Adds one or more
IRequestobjects to theRequestHandler.
- Adds one or more
-
UpdateAutoParallelism: Type:
void- Calculates the auto-parallelism manually again.
-
RunRequests: Type:
void- Starts the
RequestHandlerif it is not running yet and runs all unhandled requests.
- Starts the
-
Resume: Type:
void- Resumes the
RequestHandlerif it was paused.
- Resumes the
-
Pause: Type:
void- Pauses the
RequestHandler, allowing all running requests to complete, but prevents new requests from starting if they fail.
- Pauses the
-
CreateCTS: Type:
void- Creates a new
CancellationTokenSourceif the old one was canceled.
- Creates a new
-
CancelCTS: Type:
void- Cancels the
CancellationTokenSourceand allIRequestobjects in thisRequestHandler.
- Cancels the
-
privateRunChannel: Type:Task- Starts the asynchronous Priority Channel process.
-
privateHandleRequests: Type:Task- Handles an
IRequest.
- Handles an
-
staticCancelMainCTS: Type:void- Cancels the
CancellationTokenSourceof the MainRequestHandlers.
- Cancels the
-
staticCreateMainCTS: Type:void- Creates new
CancellationTokenSourcesfor the MainRequestHandlers.
- Creates new
-
staticResumeMain: Type:void- Resumes the Main
RequestHandlersif they were paused.
- Resumes the Main
-
staticPauseMain: Type:void- Pauses the Main
RequestHandlers.
- Pauses the Main
The RequestContainer<> class implements fundamental functionalities for grouping IRequest objects. It implements IEnumerable<TRequest> and IRequest. It is generic, allowing for one type of parameter.
-
$\text{\color{orange}TOptions}$ : Type:IRequest- Specifies which
IRequestimplementation should be used for grouping.
- Specifies which
-
Task: Type:
Task- Represents the asynchronous state of the object (finished, failed, or running).
-
Exception: Type:
AggregateException- Stores any exceptions thrown by the contained
IRequestobjects.
- Stores any exceptions thrown by the contained
-
State: Type:
RequestState- Provides information about the general state of the contained
IRequestobjects.
- Provides information about the general state of the contained
-
StateChanged: Type:
EventHandler<RequestState>- Invoked when the state of the
RequestContainer<>changes.
- Invoked when the state of the
-
Priority: Type:
RequestPriority- Not used. Always set to
RequestState.Normal.
- Not used. Always set to
-
SynchronizationContext: Type:
SynchronizationContext- Provides the synchronization context for syncing callback events.
-
Length: Type:
int- Returns the length of the
RequestContainer<>.
- Returns the length of the
-
Constructor:
- Creates a
RequestContainer<>object. You can passIRequestobjects to add them to the container.
- Creates a
-
Add: Type:
void- Adds one
IRequestobject to theRequestContainer<>and applies the state of theRequestContainer<>to theIRequestobject.
- Adds one
-
AddRange: Type:
void- Adds one or more
IRequestobjects to theRequestContainer<>and applies the state of theRequestContainer<>to all newIRequestobjects.
- Adds one or more
-
Remove: Type:
void- Removes one
IRequestobject from theRequestContainer<>.
- Removes one
-
IRequest.StartRequestAsync: Type:
Task- Runs all
IRequestobjects in theRequestContainer<>one after another.
- Runs all
-
Start: Type:
void- Starts all
IRequestobjects.
- Starts all
-
Pause: Type:
void- Pauses all
IRequestobjects.
- Pauses all
-
TrySetIdle: Type:
bool- Attempts to set the all states of the
Request<>objects to idle.
- Attempts to set the all states of the
-
Cancel: Type:
void- Cancels all
IRequestobjects.
- Cancels all
-
Dispose: Type:
void- Disposes of all
IRequestobjects.
- Disposes of all
-
privateNewTaskCompletion: Type:void- Creates a new
TaskCompletionSource.
- Creates a new
-
privateCreateArrayWithNewItems: Type:void- Allocates new space for new
IRequestobjects.
- Allocates new space for new
-
privateOnStateChanged: Type:void- Is called when one request changes its state and invokes
CalculateState.
- Is called when one request changes its state and invokes
-
privateCalculateState: Type:RequestState- Calculates the new state of the
RequestContainer<>.
- Calculates the new state of the
-
staticMergeContainers: Type:RequestContainer<TRequest>- Creates a new
RequestContainer<>object that contains allIRequestobjects. It does not contain the passedRequestContainerobjects; only theIRequestobjects are included.
- Creates a new
The ProgressableContainer<> combines IProgressableRequest objects and inherits from RequestContainer<>. It is a generic class, allowing for one type of parameter.
-
$\text{\color{orange}TOptions}$ : Type:IProgressableRequest- Specifies which
IProgressableRequestimplementation should be used for grouping.
- Specifies which
-
Progress: Type:
Progress<float>- Represents the merged progress of all
IProgressableRequestobjects.
- Represents the merged progress of all
-
Constructor:
- Creates a
ProgressableContainer<>object. You can passIProgressableRequestobjects to add them to the container.
- Creates a
-
Add: Type:
void- Adds one
IProgressableRequestobject to theProgressableContainer<>and updates the overall progress.
- Adds one
-
AttachProgress: Type:
void- Adds a
Progress<float>instance to theCombinableProgress<float>of the container.
- Adds a
-
staticMergeContainers: Type:ProgressableContainer<TRequest>- Creates a new
ProgressableContainer<>object that contains allIProgressableRequestobjects. It does not include the passedProgressableContainer<>objects; only theIProgressableRequestobjects are included.
- Creates a new
-
AddRange: Type:
void- Adds one or more
IProgressableRequestobjects to theProgressableContainer<>and updates the overall progress.
- Adds one or more
-
Remove: Type:
void- Removes one
IProgressableRequestobject from theProgressableContainer<>.
- Removes one
The IProgressableRequest interface provides an interface to be used in ProgressableContainer<>. It implements the IRequest interface.
-
Progress: Type:
Progress<float>- Represents the progress of an
IRequestimplementation.
- Represents the progress of an
The OwnRequest class implements the basic functionality of the Request base class. It utilizes VoidStruct for both the
-
Constructor:
- Creates a
Request<>object. You need to provide aFunc<CancellationToken, Task<bool>>and can optionally pass aRequestOptions<VoidStruct, VoidStruct>to customize its behavior. The constructor also callsAutoStart.
- Creates a
-
protectedRunRequestAsync: Type:Task<RequestReturn>- Invokes the
Func<CancellationToken, Task<bool>>object passed in the constructor.
- Invokes the