StateMachine - SimpleStateMachine/SimpleStateMachineLibrary GitHub Wiki
Сontent
Create
StateMachine stateMachine = new StateMachine();
Import
You can import state machine to xml
StateMachine stateMachine = StateMachine.FromXDocument("fileName.xml");
StateMachine stateMachine = new StateMachine("fileName.xml");
Export
You can export state machine to xml
stateMachine.ToXDocument("fileName.xml");
Logging
For logging you need use ILogger
//Example create logger
var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole().AddDebug().SetMinimumLevel(LogLevel.Debug); });
var logger = loggerFactory.CreateLogger<StateMachine>();
StateMachine stateMachine = new StateMachine(logger);
StateMachine stateMachine = StateMachine.FromXDocument("fileName.xml", logger);
StateMachine stateMachine = new StateMachine("fileName.xml", logger);
OnChangeState
Triggered after entry to new state.
Action Syntax
void ActionOnChangeState(State stateFrom, State stateTo)
{
}
Add action
stateMachine.OnChangeState(ActionOnChangeState);
CurrentState
You can get current state or it name
State currentState = StateMachine.CurrentState;
string currentStateName = StateMachine.CurrentStateName;
PreviousState
You can get previus state or it name
State previus State = StateMachine.PreviousState;
string previusStateName = StateMachine.PreviousStateName;
CurrentTransition
You can get current transition or it name
Transition currentTransition= StateMachine.CurrentTransition;
string currentTransitionName= StateMachine.CurrentTransitionName;