Class AutomatonymousStateMachine<TInstance>
- Namespace
- Automatonymous
- Assembly
- Automatonymous.dll
public abstract class AutomatonymousStateMachine<TInstance> : StateMachine<TInstance>, StateMachine, Visitable, IProbeSite where TInstance : class
Type Parameters
TInstance
- Inheritance
-
AutomatonymousStateMachine<TInstance>
- Implements
-
StateMachine<TInstance>IProbeSite
- Inherited Members
Constructors
AutomatonymousStateMachine()
protected AutomatonymousStateMachine()
Properties
Events
The events defined in the state machine
public IEnumerable<Event> Events { get; }
Property Value
Final
The final state of a state machine instance
public State Final { get; }
Property Value
Initial
The initial state of a new state machine instance
public State Initial { get; }
Property Value
States
The states defined in the state machine
public IEnumerable<State> States { get; }
Property Value
Methods
AfterLeave(State, Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>)
After leaving the specified state
protected void AfterLeave(State state, Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>> activityCallback)
Parameters
stateStateactivityCallbackFunc<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>
AfterLeaveAny(Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>)
After leaving any state
protected void AfterLeaveAny(Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>> activityCallback)
Parameters
activityCallbackFunc<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>
BeforeEnter(State, Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>)
Before entering the specified state
protected void BeforeEnter(State state, Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>> activityCallback)
Parameters
stateStateactivityCallbackFunc<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>
BeforeEnterAny(Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>)
Before entering any state
protected void BeforeEnterAny(Func<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>> activityCallback)
Parameters
activityCallbackFunc<EventActivityBinder<TInstance, State>, EventActivityBinder<TInstance, State>>
CompositeEvent(Expression<Func<Event>>, Expression<Func<TInstance, CompositeEventStatus>>, CompositeEventOptions, params Event[])
Adds a composite event to the state machine. A composite event is triggered when all off the required events have been raised. Note that required events cannot be in the initial state since it would cause extra instances of the state machine to be created
protected virtual void CompositeEvent(Expression<Func<Event>> propertyExpression, Expression<Func<TInstance, CompositeEventStatus>> trackingPropertyExpression, CompositeEventOptions options, params Event[] events)
Parameters
propertyExpressionExpression<Func<Event>>The composite event
trackingPropertyExpressionExpression<Func<TInstance, CompositeEventStatus>>The property in the instance used to track the state of the composite event
optionsCompositeEventOptionsOptions on the composite event
eventsEvent[]The events that must be raised before the composite event is raised
CompositeEvent(Expression<Func<Event>>, Expression<Func<TInstance, CompositeEventStatus>>, params Event[])
Adds a composite event to the state machine. A composite event is triggered when all off the required events have been raised. Note that required events cannot be in the initial state since it would cause extra instances of the state machine to be created
protected virtual void CompositeEvent(Expression<Func<Event>> propertyExpression, Expression<Func<TInstance, CompositeEventStatus>> trackingPropertyExpression, params Event[] events)
Parameters
propertyExpressionExpression<Func<Event>>The composite event
trackingPropertyExpressionExpression<Func<TInstance, CompositeEventStatus>>The property in the instance used to track the state of the composite event
eventsEvent[]The events that must be raised before the composite event is raised
CompositeEvent(Expression<Func<Event>>, Expression<Func<TInstance, int>>, CompositeEventOptions, params Event[])
Adds a composite event to the state machine. A composite event is triggered when all off the required events have been raised. Note that required events cannot be in the initial state since it would cause extra instances of the state machine to be created
protected virtual void CompositeEvent(Expression<Func<Event>> propertyExpression, Expression<Func<TInstance, int>> trackingPropertyExpression, CompositeEventOptions options, params Event[] events)
Parameters
propertyExpressionExpression<Func<Event>>The composite event
trackingPropertyExpressionExpression<Func<TInstance, int>>The property in the instance used to track the state of the composite event
optionsCompositeEventOptionsOptions on the composite event
eventsEvent[]The events that must be raised before the composite event is raised
CompositeEvent(Expression<Func<Event>>, Expression<Func<TInstance, int>>, params Event[])
Adds a composite event to the state machine. A composite event is triggered when all off the required events have been raised. Note that required events cannot be in the initial state since it would cause extra instances of the state machine to be created
protected virtual void CompositeEvent(Expression<Func<Event>> propertyExpression, Expression<Func<TInstance, int>> trackingPropertyExpression, params Event[] events)
Parameters
propertyExpressionExpression<Func<Event>>The composite event
trackingPropertyExpressionExpression<Func<TInstance, int>>The property in the instance used to track the state of the composite event
eventsEvent[]The events that must be raised before the composite event is raised
During(State, params EventActivities<TInstance>[])
Declares the events and associated activities that are handled during the specified state
protected void During(State state, params EventActivities<TInstance>[] activities)
Parameters
stateStateThe state
activitiesEventActivities<TInstance>[]The event and activities
During(State, State, params EventActivities<TInstance>[])
Declares the events and associated activities that are handled during the specified states
protected void During(State state1, State state2, params EventActivities<TInstance>[] activities)
Parameters
state1StateThe state
state2StateThe other state
activitiesEventActivities<TInstance>[]The event and activities
During(State, State, State, params EventActivities<TInstance>[])
Declares the events and associated activities that are handled during the specified states
protected void During(State state1, State state2, State state3, params EventActivities<TInstance>[] activities)
Parameters
state1StateThe state
state2StateThe other state
state3StateThe other other state
activitiesEventActivities<TInstance>[]The event and activities
During(State, State, State, State, params EventActivities<TInstance>[])
Declares the events and associated activities that are handled during the specified states
protected void During(State state1, State state2, State state3, State state4, params EventActivities<TInstance>[] activities)
Parameters
state1StateThe state
state2StateThe other state
state3StateThe other other state
state4StateOkay, this is getting a bit ridiculous at this point
activitiesEventActivities<TInstance>[]The event and activities
During(IEnumerable<State>, params EventActivities<TInstance>[])
Declares the events and associated activities that are handled during the specified states
protected void During(IEnumerable<State> states, params EventActivities<TInstance>[] activities)
Parameters
statesIEnumerable<State>The states
activitiesEventActivities<TInstance>[]The event and activities
DuringAny(params EventActivities<TInstance>[])
Declares events and activities that are handled during any state exception Initial and Final
protected void DuringAny(params EventActivities<TInstance>[] activities)
Parameters
activitiesEventActivities<TInstance>[]The event and activities
Event(Expression<Func<Event>>)
Declares an event, and initializes the event property
protected virtual void Event(Expression<Func<Event>> propertyExpression)
Parameters
propertyExpressionExpression<Func<Event>>
Event<T>(Expression<Func<Event<T>>>)
Declares a data event on the state machine, and initializes the property
protected virtual void Event<T>(Expression<Func<Event<T>>> propertyExpression)
Parameters
propertyExpressionExpression<Func<Event<T>>>The event property
Type Parameters
T
Event<TProperty, T>(Expression<Func<TProperty>>, Expression<Func<TProperty, Event<T>>>)
Declares a data event on a property of the state machine, and initializes the property
protected virtual void Event<TProperty, T>(Expression<Func<TProperty>> propertyExpression, Expression<Func<TProperty, Event<T>>> eventPropertyExpression) where TProperty : class
Parameters
propertyExpressionExpression<Func<TProperty>>The property
eventPropertyExpressionExpression<Func<TProperty, Event<T>>>The event property on the property
Type Parameters
TPropertyT
Finally(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)
When the Final state is entered, execute the chained activities. This occurs in any state that is not the initial or final state
protected void Finally(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)
Parameters
activityCallbackFunc<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>Specify the activities that are executes when the Final state is entered.
GetState(string)
Returns the state requested bound to the instance
public State<TInstance> GetState(string name)
Parameters
namestring
Returns
- State<TInstance>
Ignore(Event)
Ignore the event in this state (no exception is thrown)
protected EventActivities<TInstance> Ignore(Event @event)
Parameters
eventEventThe ignored event
Returns
- EventActivities<TInstance>
Ignore<TData>(Event<TData>)
Ignore the event in this state (no exception is thrown)
protected EventActivities<TInstance> Ignore<TData>(Event<TData> @event)
Parameters
eventEvent<TData>The ignored event
Returns
- EventActivities<TInstance>
Type Parameters
TDataThe event data type
Ignore<TData>(Event<TData>, StateMachineEventFilter<TInstance, TData>)
Ignore the event in this state (no exception is thrown)
protected EventActivities<TInstance> Ignore<TData>(Event<TData> @event, StateMachineEventFilter<TInstance, TData> filter)
Parameters
eventEvent<TData>The ignored event
filterStateMachineEventFilter<TInstance, TData>The filter to apply to the event data
Returns
- EventActivities<TInstance>
Type Parameters
TDataThe event data type
Initially(params EventActivities<TInstance>[])
Declares the events and activities that are handled during the initial state
protected void Initially(params EventActivities<TInstance>[] activities)
Parameters
activitiesEventActivities<TInstance>[]The event and activities
InstanceState(Expression<Func<TInstance, State>>)
Declares what property holds the TInstance's state on the current instance of the state machine
protected void InstanceState(Expression<Func<TInstance, State>> instanceStateProperty)
Parameters
instanceStatePropertyExpression<Func<TInstance, State>>
Remarks
Setting the state accessor more than once will cause the property managed by the state machine to change each time. Please note, the state machine can only manage one property at a given time per instance, and the best practice is to manage one property per machine.
InstanceState(Expression<Func<TInstance, int>>, params State[])
Declares the property to hold the instance's state as an int (0 - none, 1 = initial, 2 = final, 3... the rest)
protected void InstanceState(Expression<Func<TInstance, int>> instanceStateProperty, params State[] states)
Parameters
instanceStatePropertyExpression<Func<TInstance, int>>statesState[]Specifies the states, in order, to which the int values should be assigned
InstanceState(Expression<Func<TInstance, string>>)
Declares the property to hold the instance's state as a string (the state name is stored in the property)
protected void InstanceState(Expression<Func<TInstance, string>> instanceStateProperty)
Parameters
instanceStatePropertyExpression<Func<TInstance, string>>
Name(string)
Specifies the name of the state machine
protected void Name(string machineName)
Parameters
machineNamestring
OnUnhandledEvent(UnhandledEventCallback<TInstance>)
Specifies a callback to invoke when an event is raised in a state where the event is not handled
protected void OnUnhandledEvent(UnhandledEventCallback<TInstance> callback)
Parameters
callbackUnhandledEventCallback<TInstance>The unhandled event callback
Probe(ProbeContext)
public void Probe(ProbeContext context)
Parameters
contextProbeContext
State(Expression<Func<State>>)
Declares a state on the state machine, and initialized the property
protected virtual void State(Expression<Func<State>> propertyExpression)
Parameters
propertyExpressionExpression<Func<State>>The state property
State<TProperty>(Expression<Func<TProperty>>, Expression<Func<TProperty, State>>)
Declares a state on the state machine, and initialized the property
protected virtual void State<TProperty>(Expression<Func<TProperty>> propertyExpression, Expression<Func<TProperty, State>> statePropertyExpression) where TProperty : class
Parameters
propertyExpressionExpression<Func<TProperty>>The property containing the state
statePropertyExpressionExpression<Func<TProperty, State>>The state property
Type Parameters
TProperty
SubState(Expression<Func<State>>, State)
Declares a sub-state on the machine. A sub-state is a state that is valid within a super-state, allowing a state machine to have multiple "states" -- nested parts of an overall state.
protected virtual void SubState(Expression<Func<State>> propertyExpression, State superState)
Parameters
propertyExpressionExpression<Func<State>>The state property expression
superStateStateThe superstate of which this state is a substate
SubState<TProperty>(Expression<Func<TProperty>>, Expression<Func<TProperty, State>>, State)
Declares a state on the state machine, and initialized the property
protected virtual void SubState<TProperty>(Expression<Func<TProperty>> propertyExpression, Expression<Func<TProperty, State>> statePropertyExpression, State superState) where TProperty : class
Parameters
propertyExpressionExpression<Func<TProperty>>The property containing the state
statePropertyExpressionExpression<Func<TProperty, State>>The state property
superStateStateThe superstate of which this state is a substate
Type Parameters
TProperty
When(Event)
When the event is fired in this state, execute the chained activities
protected EventActivityBinder<TInstance> When(Event @event)
Parameters
eventEventThe fired event
Returns
- EventActivityBinder<TInstance>
When(Event, StateMachineEventFilter<TInstance>)
When the event is fired in this state, and the event data matches the filter expression, execute the chained activities
protected EventActivityBinder<TInstance> When(Event @event, StateMachineEventFilter<TInstance> filter)
Parameters
eventEventThe fired event
filterStateMachineEventFilter<TInstance>The filter applied to the event
Returns
- EventActivityBinder<TInstance>
WhenEnter(State, Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)
When entering the specified state
protected void WhenEnter(State state, Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)
Parameters
stateStateactivityCallbackFunc<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>
WhenEnterAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)
When entering any state
protected void WhenEnterAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)
Parameters
activityCallbackFunc<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>
WhenLeave(State, Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)
When leaving the specified state
protected void WhenLeave(State state, Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)
Parameters
stateStateactivityCallbackFunc<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>
WhenLeaveAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)
When leaving any state
protected void WhenLeaveAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)
Parameters
activityCallbackFunc<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>
When<TData>(Event<TData>)
When the event is fired in this state, execute the chained activities
protected EventActivityBinder<TInstance, TData> When<TData>(Event<TData> @event)
Parameters
eventEvent<TData>The fired event
Returns
- EventActivityBinder<TInstance, TData>
Type Parameters
TDataThe event data type
When<TData>(Event<TData>, StateMachineEventFilter<TInstance, TData>)
When the event is fired in this state, and the event data matches the filter expression, execute the chained activities
protected EventActivityBinder<TInstance, TData> When<TData>(Event<TData> @event, StateMachineEventFilter<TInstance, TData> filter)
Parameters
eventEvent<TData>The fired event
filterStateMachineEventFilter<TInstance, TData>The filter applied to the event
Returns
- EventActivityBinder<TInstance, TData>
Type Parameters
TDataThe event data type