Class Activity<TResult>
- Namespace
- Acuit.Pinpoint.Workflows.Activities
- Assembly
- Acuit.Pinpoint.Workflows.dll
A workflow activity that produces a result value.
public abstract class Activity<TResult> : ValueSource<TResult>, IActivity
Type Parameters
TResult
The type of the result that the workflow activity produces.
- Inheritance
-
ValueSource<TResult>Activity<TResult>
- Implements
- Derived
- Inherited Members
Examples
public class MyActivity : Activity<int>
{
public ValueSource<int> InputArgument { get; set; }
protected override async Task<int> OnExecuteAsync(ActivityContext context, CancellationToken cancellationToken)
{
if (context is null)
throw new ArgumentNullException(nameof(context));
var inputArgument = await context.EvaluateRequiredArgumentAsync(InputArgument, nameof(InputArgument), cancellationToken).ConfigureAwait(true)
var someService = context.ServiceProvider.GetRequiredService<ISomeService>();
// Perform the activity logic asynchronously here...
return inputArgument + 1; // Return the result value here; in this case, we will return the evaluated InputArgument, incremented
}
}
Remarks
A workflow activity produces a result value is just like any other ValueSource<T>, except that each has its own parameters and variables, and it executes (i.e., evaluate its value) with its own context instance that reflects its parameters and variables and has its own private state.
See the remarks for Activity for general notes about implementing workflow activities.
Properties
DisplayName
Gets or sets the display name of the activity.
public string DisplayName { get; set; }
Property Value
Remarks
This is used by debug log messages.
Parameters
Gets the list of input parameters defined for the activity.
public Collection<ParameterBase> Parameters { get; }
Property Value
Variables
Gets the list of variables defined for the activity.
public Collection<Variable> Variables { get; }
Property Value
Methods
EvaluateAsync(ActivityContext, CancellationToken)
Evaluates the value.
public override Task<TResult> EvaluateAsync(ActivityContext context, CancellationToken cancellationToken = default)
Parameters
context
ActivityContextThe activity context.
cancellationToken
CancellationTokenA token that can request cancelling the evaluation.
Returns
- Task<TResult>
A task that represents the asynchronous operation. The value of its Result property contains the resulting value.
OnExecuteAsync(ActivityContext, CancellationToken)
Derived classes must implement this to perform the activity.
protected abstract Task<TResult> OnExecuteAsync(ActivityContext context, CancellationToken cancellationToken)
Parameters
context
ActivityContextThe activity context.
cancellationToken
CancellationTokenThe cancellation token used to request canceling the activity.
Returns
- Task<TResult>
A task that represents the asynchronous operation. The value of its Result property contains the result.
Exceptions
- ArgumentNullException
context
is null.- InvalidOperationException
A service required by the activity is not available, or a required activity property value is not set.
- Exception
An error occurred while performing the activity.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
Remarks
This is expected to produce a string suitable for labeling this activity in a workflow diagram. It should be as specific as possible, but while keeping it very short. In general, it should be the short name of the class (as that is how it would typically be defined in the workflow XAML), optionally followed by other property values of interest in a diagram. The default implementation returns the short name of the class.