Table of Contents

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

name string

The name of the operation.

executeFunc Func<object, IWorkflowFoundry, CancellationToken, Task<object>>

The function to execute for this operation.

restoreFunc Func<object, IWorkflowFoundry, CancellationToken, Task>

The optional restoration function.

Properties

Name

Gets the name of this operation.

public override string Name { get; }

Property Value

string

Methods

ForgeAsyncCore(object?, IWorkflowFoundry, CancellationToken)

Executes the operation logic.

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.

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

name string

The operation name.

action Action<object>

The action to perform.

restoreFunc Func<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

name string

The operation name.

func Func<object, Task<object>>

The asynchronous function to execute.

restoreFunc Func<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

name string

The operation name.

action Func<object, Task>

The asynchronous action to perform.

restoreFunc Func<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

name string

The operation name.

func Func<object, object>

The synchronous function to execute.

restoreFunc Func<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

outputData object

The output data to restore.

foundry IWorkflowFoundry

The workflow foundry providing context and services.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task representing the restoration operation.