Class ForEachWorkflowOperation
- Namespace
- WorkflowForge.Operations
- Assembly
- WorkflowForge.dll
Runs a fixed set of operations over the input, distributing items to operations by index according to the configured data strategy. Supports parallel and sequential execution with resource management and error handling.
public sealed class ForEachWorkflowOperation : WorkflowOperationBase, IWorkflowOperation, IDisposable
- Inheritance
-
ForEachWorkflowOperation
- Implements
- Inherited Members
- Extension Methods
Constructors
ForEachWorkflowOperation(IEnumerable<IWorkflowOperation>, TimeSpan?, ForEachDataStrategy, int?, string?, Guid?, ISystemTimeProvider?)
Initializes a new instance of the ForEachWorkflowOperation class.
public ForEachWorkflowOperation(IEnumerable<IWorkflowOperation> operations, TimeSpan? timeout = null, ForEachDataStrategy dataStrategy = ForEachDataStrategy.SharedInput, int? maxConcurrency = null, string? name = null, Guid? id = null, ISystemTimeProvider? timeProvider = null)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to execute in parallel.
timeoutTimeSpan?Optional timeout for the entire foreach operation.
dataStrategyForEachDataStrategyStrategy for distributing input data among operations.
maxConcurrencyint?Optional maximum number of concurrent operations (throttling).
namestringOptional name for the operation.
idGuid?Optional operation ID. If null, a new GUID is generated.
timeProviderISystemTimeProviderThe time provider to use for timestamps.
Exceptions
- ArgumentNullException
Thrown when operations is null.
- ArgumentException
Thrown when operations is empty or maxConcurrency is invalid.
Properties
Id
Gets the unique identifier for this operation.
public override Guid Id { get; }
Property Value
Name
Gets the name of this operation for identification and logging purposes.
public override string Name { get; }
Property Value
Methods
Create(params IWorkflowOperation[])
Creates a ForEach operation from a params array of child operations.
public static ForEachWorkflowOperation Create(params IWorkflowOperation[] operations)
Parameters
operationsIWorkflowOperation[]The operations to execute.
Returns
- ForEachWorkflowOperation
A new ForEach operation instance.
CreateNoInput(IEnumerable<IWorkflowOperation>, TimeSpan?, int?, string?)
Creates a ForEach operation where operations receive no input data.
public static ForEachWorkflowOperation CreateNoInput(IEnumerable<IWorkflowOperation> operations, TimeSpan? timeout = null, int? maxConcurrency = null, string? name = null)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to execute.
timeoutTimeSpan?Optional timeout for the entire operation.
maxConcurrencyint?Optional maximum number of concurrent operations.
namestringOptional name for the operation.
Returns
- ForEachWorkflowOperation
A new ForEach operation instance.
CreateSharedInput(IEnumerable<IWorkflowOperation>, TimeSpan?, int?, string?)
Creates a ForEach operation where all operations share the same input data.
public static ForEachWorkflowOperation CreateSharedInput(IEnumerable<IWorkflowOperation> operations, TimeSpan? timeout = null, int? maxConcurrency = null, string? name = null)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to execute.
timeoutTimeSpan?Optional timeout for the entire operation.
maxConcurrencyint?Optional maximum number of concurrent operations.
namestringOptional name for the operation.
Returns
- ForEachWorkflowOperation
A new ForEach operation instance.
CreateSplitInput(IEnumerable<IWorkflowOperation>, TimeSpan?, int?, string?)
Creates a ForEach operation where input data is split among operations.
public static ForEachWorkflowOperation CreateSplitInput(IEnumerable<IWorkflowOperation> operations, TimeSpan? timeout = null, int? maxConcurrency = null, string? name = null)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to execute.
timeoutTimeSpan?Optional timeout for the entire operation.
maxConcurrencyint?Optional maximum number of concurrent operations.
namestringOptional name for the operation.
Returns
- ForEachWorkflowOperation
A new ForEach operation instance.
CreateWithThrottling(IEnumerable<IWorkflowOperation>, int, TimeSpan?)
Creates a ForEach operation with concurrency throttling.
public static ForEachWorkflowOperation CreateWithThrottling(IEnumerable<IWorkflowOperation> operations, int maxConcurrency, TimeSpan? timeout = null)
Parameters
operationsIEnumerable<IWorkflowOperation>The operations to execute.
maxConcurrencyintMaximum number of concurrent operations.
timeoutTimeSpan?Optional timeout for the entire operation.
Returns
- ForEachWorkflowOperation
A new ForEach operation instance.
Dispose(bool)
Releases managed resources. Override in derived classes to dispose of owned resources.
protected override void Dispose(bool disposing)
Parameters
ForgeAsyncCore(object?, IWorkflowFoundry, CancellationToken)
Core operation logic. Implement this method with your operation's business logic. This is called between OnBeforeExecuteAsync and OnAfterExecuteAsync.
protected override Task<object?> ForgeAsyncCore(object? inputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
inputDataobjectThe input data for the operation.
foundryIWorkflowFoundryThe workflow foundry providing context and services.
cancellationTokenCancellationTokenThe cancellation token.
Returns
RestoreAsync(object?, IWorkflowFoundry, CancellationToken)
Restores (compensates) the operation's effects to undo its changes. Used for rollback scenarios when subsequent operations fail.
public override Task RestoreAsync(object? outputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
outputDataobjectThe data that was produced by this operation during ForgeAsync.
foundryIWorkflowFoundryThe workflow foundry providing execution context and shared services.
cancellationTokenCancellationTokenThe cancellation token for cooperative cancellation.
Returns
- Task
A task representing the asynchronous restoration.
Remarks
The base implementation is a no-op. Override this method in your operation to provide compensation/rollback logic. Operations that don't override this are safely skipped during compensation.
Exceptions
- ArgumentNullException
Thrown when foundry is null.
- ObjectDisposedException
Thrown when the operation has been disposed.