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
conditionFunc<object, IWorkflowFoundry, bool>The synchronous condition to evaluate.
trueOperationIWorkflowOperationThe operation to execute if the condition is true.
falseOperationIWorkflowOperationThe optional operation to execute if the condition is false.
namestringOptional name for the operation.
idGuid?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
conditionFunc<object, IWorkflowFoundry, CancellationToken, Task<bool>>The condition to evaluate. Receives input data for evaluation.
trueOperationIWorkflowOperationThe operation to execute if the condition is true.
falseOperationIWorkflowOperationThe optional operation to execute if the condition is false.
namestringOptional name for the operation.
idGuid?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
conditionFunc<IWorkflowFoundry, CancellationToken, Task<bool>>The simple condition to evaluate.
trueOperationIWorkflowOperationThe operation to execute if the condition is true.
falseOperationIWorkflowOperationThe optional operation to execute if the condition is false.
namestringOptional name for the operation.
idGuid?Optional operation ID.
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(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
conditionFunc<IWorkflowFoundry, bool>The simple condition to evaluate.
trueOperationIWorkflowOperationThe operation to execute when condition is true.
falseOperationIWorkflowOperationThe optional operation to execute when condition is false.
namestringOptional 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
conditionFunc<object, IWorkflowFoundry, CancellationToken, Task<bool>>The condition that receives input data for evaluation.
trueOperationIWorkflowOperationThe operation to execute when condition is true.
falseOperationIWorkflowOperationThe optional operation to execute when condition is false.
namestringOptional 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
conditionFunc<T, IWorkflowFoundry, CancellationToken, Task<bool>>The typed condition function.
trueOperationIWorkflowOperationThe operation to execute when condition is true.
falseOperationIWorkflowOperationThe optional operation to execute when condition is false.
namestringOptional name for the operation.
Returns
- ConditionalWorkflowOperation
A new conditional operation instance.
Type Parameters
TThe 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
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.