Table of Contents

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

operations IEnumerable<IWorkflowOperation>

The operations to execute in parallel.

timeout TimeSpan?

Optional timeout for the entire foreach operation.

dataStrategy ForEachDataStrategy

Strategy for distributing input data among operations.

maxConcurrency int?

Optional maximum number of concurrent operations (throttling).

name string

Optional name for the operation.

id Guid?

Optional operation ID. If null, a new GUID is generated.

timeProvider ISystemTimeProvider

The 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

Guid

Name

Gets the name of this operation for identification and logging purposes.

public override string Name { get; }

Property Value

string

Methods

Create(params IWorkflowOperation[])

Creates a ForEach operation from a params array of child operations.

public static ForEachWorkflowOperation Create(params IWorkflowOperation[] operations)

Parameters

operations IWorkflowOperation[]

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

operations IEnumerable<IWorkflowOperation>

The operations to execute.

timeout TimeSpan?

Optional timeout for the entire operation.

maxConcurrency int?

Optional maximum number of concurrent operations.

name string

Optional 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

operations IEnumerable<IWorkflowOperation>

The operations to execute.

timeout TimeSpan?

Optional timeout for the entire operation.

maxConcurrency int?

Optional maximum number of concurrent operations.

name string

Optional 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

operations IEnumerable<IWorkflowOperation>

The operations to execute.

timeout TimeSpan?

Optional timeout for the entire operation.

maxConcurrency int?

Optional maximum number of concurrent operations.

name string

Optional 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

operations IEnumerable<IWorkflowOperation>

The operations to execute.

maxConcurrency int

Maximum number of concurrent operations.

timeout TimeSpan?

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

disposing bool

True if called from Dispose(), false if from a finalizer.

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

inputData object

The input data for the operation.

foundry IWorkflowFoundry

The workflow foundry providing context and services.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<object>

The output data from the operation.

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

outputData object

The data that was produced by this operation during ForgeAsync.

foundry IWorkflowFoundry

The workflow foundry providing execution context and shared services.

cancellationToken CancellationToken

The 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.