Class DelegateWorkflowOperation
- Namespace
- WorkflowForge.Operations
- Assembly
- WorkflowForge.dll
A concrete workflow operation that wraps a delegate function. Use this for simple, ad-hoc operations. For complex business logic, consider creating a dedicated class that inherits from WorkflowOperationBase.
public sealed class DelegateWorkflowOperation : WorkflowOperationBase, IWorkflowOperation, IDisposable
- Inheritance
-
DelegateWorkflowOperation
- Implements
- Inherited Members
- Extension Methods
Constructors
DelegateWorkflowOperation(string, Func<object?, IWorkflowFoundry, CancellationToken, Task<object?>>, Func<object?, IWorkflowFoundry, CancellationToken, Task>?)
Initializes a new instance of the DelegateWorkflowOperation class.
public DelegateWorkflowOperation(string name, Func<object?, IWorkflowFoundry, CancellationToken, Task<object?>> executeFunc, Func<object?, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe name of the operation.
executeFuncFunc<object, IWorkflowFoundry, CancellationToken, Task<object>>The function to execute for this operation.
restoreFuncFunc<object, IWorkflowFoundry, CancellationToken, Task>The optional restoration function.
Properties
Name
Gets the name of this operation.
public override string Name { get; }
Property Value
Methods
ForgeAsyncCore(object?, IWorkflowFoundry, CancellationToken)
Executes the operation logic.
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
FromAction(string, Action<object?>, Func<object?, IWorkflowFoundry, CancellationToken, Task>?)
Creates an operation that performs an action without returning data.
public static DelegateWorkflowOperation FromAction(string name, Action<object?> action, Func<object?, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
actionAction<object>The action to perform.
restoreFuncFunc<object, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation
A new delegate workflow operation.
FromAsync(string, Func<object?, Task<object?>>, Func<object?, IWorkflowFoundry, CancellationToken, Task>?)
Creates a simple operation from an asynchronous function.
public static DelegateWorkflowOperation FromAsync(string name, Func<object?, Task<object?>> func, Func<object?, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
funcFunc<object, Task<object>>The asynchronous function to execute.
restoreFuncFunc<object, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation
A new delegate workflow operation.
FromAsyncAction(string, Func<object?, Task>, Func<object?, IWorkflowFoundry, CancellationToken, Task>?)
Creates an operation that performs an asynchronous action without returning data.
public static DelegateWorkflowOperation FromAsyncAction(string name, Func<object?, Task> action, Func<object?, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
actionFunc<object, Task>The asynchronous action to perform.
restoreFuncFunc<object, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation
A new delegate workflow operation.
FromSync(string, Func<object?, object?>, Func<object?, IWorkflowFoundry, CancellationToken, Task>?)
Creates a simple operation from a synchronous function.
public static DelegateWorkflowOperation FromSync(string name, Func<object?, object?> func, Func<object?, IWorkflowFoundry, CancellationToken, Task>? restoreFunc = null)
Parameters
namestringThe operation name.
funcFunc<object, object>The synchronous function to execute.
restoreFuncFunc<object, IWorkflowFoundry, CancellationToken, Task>Optional restoration function for compensation.
Returns
- DelegateWorkflowOperation
A new delegate workflow operation.
RestoreAsync(object?, IWorkflowFoundry, CancellationToken)
Restores the operation effects if supported.
public override Task RestoreAsync(object? outputData, IWorkflowFoundry foundry, CancellationToken cancellationToken = default)
Parameters
outputDataobjectThe output data to restore.
foundryIWorkflowFoundryThe workflow foundry providing context and services.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task
A task representing the restoration operation.