Table of Contents

Class ConditionalWorkflowOperation

Namespace
WorkflowForge.Operations
Assembly
WorkflowForge.dll

Executes different operations based on a condition evaluation with data flow support. The orchestrator controls data flow and this operation routes it based on conditions.

public sealed class ConditionalWorkflowOperation : WorkflowOperationBase, IWorkflowOperation, IDisposable
Inheritance
ConditionalWorkflowOperation
Implements
Inherited Members
Extension Methods

Constructors

ConditionalWorkflowOperation(Func<object?, IWorkflowFoundry, bool>, IWorkflowOperation, IWorkflowOperation?, string?, Guid?)

Initializes with a synchronous condition.

public ConditionalWorkflowOperation(Func<object?, IWorkflowFoundry, bool> condition, IWorkflowOperation trueOperation, IWorkflowOperation? falseOperation = null, string? name = null, Guid? id = null)

Parameters

condition Func<object, IWorkflowFoundry, bool>

The synchronous condition to evaluate.

trueOperation IWorkflowOperation

The operation to execute if the condition is true.

falseOperation IWorkflowOperation

The optional operation to execute if the condition is false.

name string

Optional name for the operation.

id Guid?

Optional operation ID.

ConditionalWorkflowOperation(Func<object?, IWorkflowFoundry, CancellationToken, Task<bool>>, IWorkflowOperation, IWorkflowOperation?, string?, Guid?)

Initializes a new instance of the ConditionalWorkflowOperation class.

public ConditionalWorkflowOperation(Func<object?, IWorkflowFoundry, CancellationToken, Task<bool>> condition, IWorkflowOperation trueOperation, IWorkflowOperation? falseOperation = null, string? name = null, Guid? id = null)

Parameters

condition Func<object, IWorkflowFoundry, CancellationToken, Task<bool>>

The condition to evaluate. Receives input data for evaluation.

trueOperation IWorkflowOperation

The operation to execute if the condition is true.

falseOperation IWorkflowOperation

The optional operation to execute if the condition is false.

name string

Optional name for the operation.

id Guid?

Optional operation ID.

ConditionalWorkflowOperation(Func<IWorkflowFoundry, CancellationToken, Task<bool>>, IWorkflowOperation, IWorkflowOperation?, string?, Guid?)

Initializes with a simple condition that doesn't use input data.

public ConditionalWorkflowOperation(Func<IWorkflowFoundry, CancellationToken, Task<bool>> condition, IWorkflowOperation trueOperation, IWorkflowOperation? falseOperation = null, string? name = null, Guid? id = null)

Parameters

condition Func<IWorkflowFoundry, CancellationToken, Task<bool>>

The simple condition to evaluate.

trueOperation IWorkflowOperation

The operation to execute if the condition is true.

falseOperation IWorkflowOperation

The optional operation to execute if the condition is false.

name string

Optional name for the operation.

id Guid?

Optional operation ID.

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(Func<IWorkflowFoundry, bool>, IWorkflowOperation, IWorkflowOperation?, string?)

Creates a conditional operation using a synchronous foundry-only predicate.

public static ConditionalWorkflowOperation Create(Func<IWorkflowFoundry, bool> condition, IWorkflowOperation trueOperation, IWorkflowOperation? falseOperation = null, string? name = null)

Parameters

condition Func<IWorkflowFoundry, bool>

The simple condition to evaluate.

trueOperation IWorkflowOperation

The operation to execute when condition is true.

falseOperation IWorkflowOperation

The optional operation to execute when condition is false.

name string

Optional name for the operation.

Returns

ConditionalWorkflowOperation

A new conditional operation instance.

CreateDataAware(Func<object?, IWorkflowFoundry, CancellationToken, Task<bool>>, IWorkflowOperation, IWorkflowOperation?, string?)

Creates a conditional operation with data-aware condition.

public static ConditionalWorkflowOperation CreateDataAware(Func<object?, IWorkflowFoundry, CancellationToken, Task<bool>> condition, IWorkflowOperation trueOperation, IWorkflowOperation? falseOperation = null, string? name = null)

Parameters

condition Func<object, IWorkflowFoundry, CancellationToken, Task<bool>>

The condition that receives input data for evaluation.

trueOperation IWorkflowOperation

The operation to execute when condition is true.

falseOperation IWorkflowOperation

The optional operation to execute when condition is false.

name string

Optional name for the operation.

Returns

ConditionalWorkflowOperation

A new conditional operation instance.

CreateTyped<T>(Func<T, IWorkflowFoundry, CancellationToken, Task<bool>>, IWorkflowOperation, IWorkflowOperation?, string?)

Creates a conditional operation with typed input data.

public static ConditionalWorkflowOperation CreateTyped<T>(Func<T, IWorkflowFoundry, CancellationToken, Task<bool>> condition, IWorkflowOperation trueOperation, IWorkflowOperation? falseOperation = null, string? name = null)

Parameters

condition Func<T, IWorkflowFoundry, CancellationToken, Task<bool>>

The typed condition function.

trueOperation IWorkflowOperation

The operation to execute when condition is true.

falseOperation IWorkflowOperation

The optional operation to execute when condition is false.

name string

Optional name for the operation.

Returns

ConditionalWorkflowOperation

A new conditional operation instance.

Type Parameters

T

The type of input data.

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.