Class StateMachine
- Namespace
- Acuit.Pinpoint.Workflows.Activities
- Assembly
- Acuit.Pinpoint.Workflows.dll
A state machine activity.
public class StateMachine : Activity, IActivity
- Inheritance
-
StateMachine
- Implements
- Inherited Members
Remarks
A state machine consists of a hierarchy of states (states can be nested). The initial state must be specified via InitialState. One or more states must be marked as final (via IsFinal).
When the state machine activity is executed, the state specified by InitialState will be entered.
When the state machine transitions to a state nested within one or more other states, states are entered from outermost to innermost in the hierarchy, and states are exited from innermost to outermost. If a state change occurs entirely within one or more parent states, then those parent states will remain active--they are not entered or exited.
The current state and all of its ascendant states in the hierarchy are considered "active," and all of their transitions will be in effect.
Any time a state change is initiated, the sequence of events is as follows:
- For the states that must be exited to accomplish the state change, from the innermost to the outermost:
- The Exiting activity is executed, if defined.
- CancelExitCondition is evaluated, if defined. If it is true, then the state change is immediately aborted.
- For the states that must be exited to accomplish the state change, from the innermost to the outermost:
- If the state change is occurring due to a transition, then the transition's Action is executed, if defined.
- For the states that must be entered to accomplish the state change, from the outermost to the innermost:
Once a state change is complete, if it results in a state with IsFinal is true, the state machine activity execution completes. Otherwise, transition trigger activities for all active states are monitored. When one or more complete (or have no trigger defined), each transition across all active states are checked, from innermost to outermost state. For each that is completed (or has no trigger defined), Condition is evaluated, if set. If it is false, then the trigger activity is restarted. If it is true or is not set, then a state change will be initiated and no more transitions will be checked until after the state change (whether it succeeds or not).
Changes to the state machine while the state machine activity executes are not supported and the resulting behavior is undefined.
If an ILogger<TCategoryName> service is available, it will be used to log debug messages.
Properties
InitialState
Gets or sets the start point of the state machine.
public State InitialState { get; set; }
Property Value
Remarks
This is required and must be set to a member of the States hierarchy.
States
Gets the root-level states in the state machine.
public Collection<State> States { get; }
Property Value
Methods
EnumerateStateHierarchy()
public IEnumerable<State> EnumerateStateHierarchy()
Returns
OnExecuteAsync(ActivityContext, CancellationToken)
Derived classes must implement this to perform the activity.
protected override Task OnExecuteAsync(ActivityContext context, CancellationToken cancellationToken)
Parameters
context
ActivityContextThe activity context.
cancellationToken
CancellationTokenThe cancellation token used to request canceling the activity.
Returns
- Task
A task that represents the asynchronous operation.
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.