Table of Contents

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

IEnumerable<Event>

Final

The final state of a state machine instance

public State Final { get; }

Property Value

State

Initial

The initial state of a new state machine instance

public State Initial { get; }

Property Value

State

States

The states defined in the state machine

public IEnumerable<State> States { get; }

Property Value

IEnumerable<State>

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

state State
activityCallback Func<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

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

state State
activityCallback Func<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

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

propertyExpression Expression<Func<Event>>

The composite event

trackingPropertyExpression Expression<Func<TInstance, CompositeEventStatus>>

The property in the instance used to track the state of the composite event

options CompositeEventOptions

Options on the composite event

events Event[]

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

propertyExpression Expression<Func<Event>>

The composite event

trackingPropertyExpression Expression<Func<TInstance, CompositeEventStatus>>

The property in the instance used to track the state of the composite event

events Event[]

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

propertyExpression Expression<Func<Event>>

The composite event

trackingPropertyExpression Expression<Func<TInstance, int>>

The property in the instance used to track the state of the composite event

options CompositeEventOptions

Options on the composite event

events Event[]

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

propertyExpression Expression<Func<Event>>

The composite event

trackingPropertyExpression Expression<Func<TInstance, int>>

The property in the instance used to track the state of the composite event

events Event[]

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

state State

The state

activities EventActivities<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

state1 State

The state

state2 State

The other state

activities EventActivities<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

state1 State

The state

state2 State

The other state

state3 State

The other other state

activities EventActivities<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

state1 State

The state

state2 State

The other state

state3 State

The other other state

state4 State

Okay, this is getting a bit ridiculous at this point

activities EventActivities<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

states IEnumerable<State>

The states

activities EventActivities<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

activities EventActivities<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

propertyExpression Expression<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

propertyExpression Expression<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

propertyExpression Expression<Func<TProperty>>

The property

eventPropertyExpression Expression<Func<TProperty, Event<T>>>

The event property on the property

Type Parameters

TProperty
T

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

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

name string

Returns

State<TInstance>

Ignore(Event)

Ignore the event in this state (no exception is thrown)

protected EventActivities<TInstance> Ignore(Event @event)

Parameters

event Event

The 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

event Event<TData>

The ignored event

Returns

EventActivities<TInstance>

Type Parameters

TData

The 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

event Event<TData>

The ignored event

filter StateMachineEventFilter<TInstance, TData>

The filter to apply to the event data

Returns

EventActivities<TInstance>

Type Parameters

TData

The 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

activities EventActivities<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

instanceStateProperty Expression<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

instanceStateProperty Expression<Func<TInstance, int>>
states State[]

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

instanceStateProperty Expression<Func<TInstance, string>>

Name(string)

Specifies the name of the state machine

protected void Name(string machineName)

Parameters

machineName string

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

callback UnhandledEventCallback<TInstance>

The unhandled event callback

Probe(ProbeContext)

public void Probe(ProbeContext context)

Parameters

context ProbeContext

State(Expression<Func<State>>)

Declares a state on the state machine, and initialized the property

protected virtual void State(Expression<Func<State>> propertyExpression)

Parameters

propertyExpression Expression<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

propertyExpression Expression<Func<TProperty>>

The property containing the state

statePropertyExpression Expression<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

propertyExpression Expression<Func<State>>

The state property expression

superState State

The 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

propertyExpression Expression<Func<TProperty>>

The property containing the state

statePropertyExpression Expression<Func<TProperty, State>>

The state property

superState State

The 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

event Event

The 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

event Event

The fired event

filter StateMachineEventFilter<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

state State
activityCallback Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>

WhenEnterAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)

When entering any state

protected void WhenEnterAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)

Parameters

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

state State
activityCallback Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>

WhenLeaveAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>>)

When leaving any state

protected void WhenLeaveAny(Func<EventActivityBinder<TInstance>, EventActivityBinder<TInstance>> activityCallback)

Parameters

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

event Event<TData>

The fired event

Returns

EventActivityBinder<TInstance, TData>

Type Parameters

TData

The 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

event Event<TData>

The fired event

filter StateMachineEventFilter<TInstance, TData>

The filter applied to the event

Returns

EventActivityBinder<TInstance, TData>

Type Parameters

TData

The event data type