A simple C# based State Machine that can be configured via State Transitions based on an idea by Juliet "Simple state machine example in C#?"
You can download this package via NuGet with Install-Package biz.dfch.CS.StateMachine.
The project contains an extendable StateMachine that defines a few simple states and two conditions ("Continue", "Cancel") that can be used to advance (transition) through that state machine.
When instatiating the StateMachine with the default constructor the following states, conditions and transitions will be set up per default
- Running
- InternalErrorState
- Completed
- Cancelled
- Disposed
- Continue
- Cancel
Source state | Condition | Target state |
---|---|---|
InitialState | Continue | Running |
InitialState | Cancel | InternalErrorState |
Running | Continue | Completed |
Running | Cancel | Cancelled |
Completed | Continue | Disposed |
Completed | Cancel | InternalErrorState |
Cancelled | Continue | Disposed |
Cancelled | Cancel | InternalErrorState |
InternalErrorState | Continue | Disposed |
- The
Continue
condition makes a transition from an arbitrary state to the next state as the "good case" - The
Cancel
condition makes a transition from an arbitrary state to the next state as the "bad case" - Furthermore there is the
GetNext
method to transit to the next state based on a given condition.
There are as well methods for exporting and importing the configuration along with the states:
GetStringRepresentation()
SetupStateMachine(String configuration, String currentState = null, String previousState = null)
- adjust namespace
- States and Conditions can now be retrieved by consumer
- added code contracts pre-conditions
- enabled CodeContracts assemlby
Built and released with TeamCity