appccelerate - Appccelerate.StateMachine 2.7.0
Hierarchical state machine with fluent definition syntax Features: states and events can be defined with enums, strings or ints - resulting in single class state machines, actions on transitions, entry and exit actions, transition guards, hierarchical with different history behaviors to initialize state always to same state or last active state, fluent definition interface, synchronous/asynchronous state machine (passive state machine handles state transitions synchronously, active state machine handles state transitions asynchronously on the worker thread of the state machine), extensible thorough logging, state machine report for description of state machine (csv, yEd)
PM> Install-Package Appccelerate.StateMachine -Version 2.7.0 -Source https://www.myget.org/F/appccelerate/api/v3/index.json
> nuget.exe install Appccelerate.StateMachine -Version 2.7.0 -Source https://www.myget.org/F/appccelerate/api/v3/index.json
> dotnet add package Appccelerate.StateMachine --version 2.7.0 --source https://www.myget.org/F/appccelerate/api/v3/index.json
source https://www.myget.org/F/appccelerate/api/v3/index.json
nuget Appccelerate.StateMachine ~> 2.7.0
Copy to clipboard
> choco install Appccelerate.StateMachine --version 2.7.0 --source https://www.myget.org/F/appccelerate/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "appccelerate" -SourceLocation "https://www.myget.org/F/appccelerate/api/v2"
Install-Module -Name "Appccelerate.StateMachine" -RequiredVersion "2.7.0" -Repository "appccelerate"
Copy to clipboard
I'm working on moving the documention from www.appccelerate.com (where it is not up-to-date :-( ) to here because it is less time consuming to update the documentation.
Features
- use enums, ints, strings or your own class for states and events - resulting in single class state machines.
- transition, entry and exit actions.
- transition guards
- hierarchical states with history behavior to initialize state always to same state or last active state.
- supports async/await
- fluent definition syntax.
- passive state machine handles state transitions synchronously.
- active state machine handles state transitions asynchronously on the worker thread of the state machine.
- active state machine is thread-safe
- current state, queued events and history states can be persisted
- extension support to extend functionality of state machine.
- extensible thorough logging simplifies debugging.
- state machine reports as text, csv or yEd diagram. Or write your own report.
StateMachine
Appccelerate contains four different state machines:
- Passive State Machine
- Active State Machine
- Async Passive State Machine
- Async Active State Machine
Both async and not-async variants implement an interface called IStateMachine. For better testability and flexibility, I suggest that you reference your state machine only by the interface and use dependency injection to get either of the implementations. You can use then a passive state machine as a replacement for an active one in your tests to simplify the tests because everything is run on the same thread.
States and Events
A state machine is defined using States and Events. States and events have to be IComparables (enum, int, string, ...). If you have a well known set of states and events then I suggest you use enums which make the code much more readable. If you plan to build some flexibility into your state machine (e.g. add states, transitions in base classes) then you better use an "open" type like string or integer.
Transitions
Transitions are state switches that are executed in response to an event that was fired onto the state machine. You can define per state and event which transition is taken and therefore which state to go to.
Actions
You can define actions either on transitions or on entry or exit of a state. Transition actions are executed when the transition is taken as the response to an event. The entry and exit actions of a state are excuted when the state machine enters or exits the state due to a taken transition. In case of hierarchical states, multiple entry and exit actions can be executed.
Guards
Guards give you the possibility to decide which transition is executed depending on a boolean criteria. When an event is fired onto the state machine, it takes all transitions defined in the current state for the fired event and executes the first transition with a guard returning true.
Extensions
Extensions can be used to extend the functionality of the state machine. They provide for example a simple way to write loggers.
Reports
Out of the box, Appccelerate provides a textual report, a csv report and a yEd diagram reporter. You can add your own reports by just implementing IStateMachineReport.
Simple Sample State Machine
public class SimpleStateMachine
{
private enum States
{
On,
Off
}
private enum Events
{
TurnOn,
TurnOff
}
private readonly PassiveStateMachine<States, Events> machine;
public SimpleStateMachine()
{
var builder = new StateMachineDefinitionBuilder<States, Events>();
builder
.In(States.Off)
.On(Events.TurnOn)
.Goto(States.On)
.Execute(SayHello);
builder
.In(States.On)
.On(Events.TurnOff)
.Goto(States.Off)
.Execute(SayBye);
builder
.WithInitialState(States.Off);
machine = builder
.Build()
.CreatePassiveStateMachine();
machine.Start();
}
public void TurnOn()
{
machine
.Fire(
Events.TurnOn);
}
public void TurnOff()
{
machine
.Fire(
Events.TurnOff);
}
private void SayHello()
{
Console.WriteLine("hello");
}
private void SayBye()
{
Console.WriteLine("bye");
}
}
More Documentation
- Portable Class Library (.NETFramework 4.5, Windows 8.0): Profile7: 0.0.0.0
OwnersPhilipp Dolder Urs Enzler |
AuthorsAppccelerate team |
Project URLhttps://github.com/appccelerate/statemachine |
LicenseApache-2.0 |
TagsAppccelerate state-machine |
Info495 total downloads |
| 12 downloads for version 2.7.0 |
| Download (166.92 KB) |
| Found on the current feed only |
Package history
| Version | Size | Last updated | Downloads | Mirrored? | |||
|---|---|---|---|---|---|---|---|
|
5.2.0-alpha.0.4 | 96.57 KB | Wed, 04 Dec 2019 08:47:53 GMT | 14 |
|
||
|
5.2.0-alpha.0.3 | 96.57 KB | Wed, 04 Dec 2019 08:44:33 GMT | 7 |
|
||
|
5.2.0-alpha.0.2 | 96.57 KB | Mon, 02 Dec 2019 16:30:04 GMT | 7 |
|
||
|
5.2.0-alpha.0.1 | 96.57 KB | Mon, 02 Dec 2019 08:57:46 GMT | 6 |
|
||
|
5.1.0 | 96.54 KB | Wed, 27 Nov 2019 14:40:58 GMT | 16 |
|
||
|
5.1.0-alpha.0.11 | 96.27 KB | Thu, 03 Oct 2019 11:49:07 GMT | 14 |
|
||
|
5.1.0-alpha.0.10 | 94.3 KB | Thu, 03 Oct 2019 09:18:38 GMT | 6 |
|
||
|
5.1.0-alpha.0.9 | 95.5 KB | Thu, 03 Oct 2019 08:21:41 GMT | 6 |
|
||
|
5.1.0-alpha.0.8 | 91.88 KB | Thu, 03 Oct 2019 07:28:09 GMT | 7 |
|
||
|
5.1.0-alpha.0.7 | 89.48 KB | Mon, 09 Sep 2019 14:47:16 GMT | 6 |
|
||
|
5.0.1-alpha.0.6 | 89.47 KB | Mon, 09 Sep 2019 14:46:22 GMT | 7 |
|
||
|
5.0.1-alpha.0.5 | 89.45 KB | Mon, 09 Sep 2019 14:44:34 GMT | 7 |
|
||
|
5.0.1-alpha.0.4 | 89.45 KB | Mon, 09 Sep 2019 14:43:48 GMT | 6 |
|
||
|
5.0.1-alpha.0.3 | 89.09 KB | Thu, 22 Aug 2019 07:38:18 GMT | 7 |
|
||
|
5.0.1-alpha.0.2 | 69.13 KB | Wed, 21 Aug 2019 15:22:52 GMT | 6 |
|
||
|
5.0.1-alpha.0.1 | 69.13 KB | Wed, 21 Aug 2019 12:48:15 GMT | 7 |
|
||
|
5.0.0 | 68.89 KB | Wed, 21 Aug 2019 12:45:04 GMT | 7 |
|
||
|
5.0.0-pre0006 | 84.49 KB | Fri, 20 Jul 2018 12:45:06 GMT | 7 |
|
||
|
5.0.0-pre0003 | 84.1 KB | Fri, 22 Dec 2017 13:42:38 GMT | 8 |
|
||
|
3.38.0 | 84.11 KB | Fri, 22 Dec 2017 13:36:45 GMT | 6 |
|
||
|
3.28.0 | 77.63 KB | Fri, 22 Dec 2017 09:59:50 GMT | 5 |
|
||
|
3.26.0 | 77.01 KB | Fri, 22 Dec 2017 09:58:32 GMT | 5 |
|
||
|
3.24.0 | 77.02 KB | Mon, 18 Dec 2017 13:15:07 GMT | 5 |
|
||
|
2.17.0 | 43.83 KB | Wed, 30 Nov 2016 18:15:26 GMT | 15 |
|
||
|
2.17.0-commitdc50fd10 | 41.97 KB | Wed, 30 Nov 2016 14:55:09 GMT | 7 |
|
||
|
2.17.0-commit3cc423a7 | 43.89 KB | Wed, 30 Nov 2016 13:45:53 GMT | 5 |
|
||
|
2.15.0 | 170.54 KB | Thu, 02 Jul 2015 14:49:19 GMT | 116 |
|
||
|
2.14.0 | 167.77 KB | Tue, 21 Apr 2015 09:14:03 GMT | 45 |
|
||
|
2.13.0 | 167.73 KB | Fri, 10 Apr 2015 09:21:41 GMT | 64 |
|
||
|
2.12.0 | 168.73 KB | Wed, 14 Jan 2015 08:43:24 GMT | 17 |
|
||
|
2.11.0 | 168.02 KB | Tue, 13 Jan 2015 16:07:11 GMT | 8 |
|
||
|
2.9.0 | 166.87 KB | Mon, 05 Jan 2015 14:12:55 GMT | 9 |
|
||
|
2.9.0-commitd156d451 | 166.93 KB | Mon, 05 Jan 2015 14:05:56 GMT | 4 |
|
||
|
2.7.0 | 166.92 KB | Mon, 06 Oct 2014 06:51:19 GMT | 12 |
|
||
|
2.6.0 | 166.87 KB | Fri, 03 Oct 2014 13:12:29 GMT | 5 |
|
||
|
2.5.0 | 166.88 KB | Wed, 23 Jul 2014 06:09:00 GMT | 10 |
|
||
|
2.1.1-alpha.0.33 | 68.91 KB | Wed, 21 Aug 2019 12:23:47 GMT | 6 |
|