diff --git a/.gitignore b/.gitignore
index 4ce6fdd..f03b9e4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -337,4 +337,8 @@ ASALocalRun/
.localhistory/
# BeatPulse healthcheck temp database
-healthchecksdb
\ No newline at end of file
+healthchecksdb
+
+CodeMap1.dgml
+
+SimpleStateMachine.png
\ No newline at end of file
diff --git a/CodeMap1.dgml b/CodeMap1.dgml
deleted file mode 100644
index a17b13b..0000000
--- a/CodeMap1.dgml
+++ /dev/null
@@ -1,463 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Examples/Examples.csproj b/Examples/Examples.csproj
index 07cd9f3..afd8aea 100644
--- a/Examples/Examples.csproj
+++ b/Examples/Examples.csproj
@@ -6,10 +6,10 @@
-
-
-
-
+
+
+
+
diff --git a/README.md b/README.md
index ba74655..47d57e2 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,32 @@
-[](https://www.nuget.org/packages/SimpleStateMachineLibrary)
-[](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary)
-[](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary)
-# SimpleStateMachineLibrary
+
+[](https://www.nuget.org/packages/SimpleStateMachineLibrary) [](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary) [](https://www.nuget.org/packages/SimpleStateMachineLibrary) [](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary) [](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary)
+ [](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary) [](https://join.slack.com/t/simplestatemachine/shared_invite/zt-fnfhvvsx-fTejcpPn~PPb2ojdG_MQBg) [](https://t.me/joinchat/HMLJFkv9do6aDV188rhd0w)
+ [](https://dev.azure.com/GMIKE/SimpleStateMachineLibrary/_build/latest?definitionId=2&branchName=master)
+ # SimpleStateMachineLibrary
A C# library for realization simple state-machine on .Net
-# Why SimpleStateMachine?
- Create state machine in **two steps** :
-1. Create scheme in [node editor](https://github.com/SimpleStateMachine/SimpleStateMachineNodeEditor) ♦️
-2. Load scheme in your project using [library](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary)📑
-
- Just describe your app logic and run the state machine🚀
-
-## Give a Star! :star:
+
+ ## Give a Star! :star:
If you like or are using this project please give it a star. Thanks!
-## Сontent
-1. [Features](#Features)
-2. [Examples](#Examples)
-4. [Documentation](#Documentation)
-4. [License](#License)
-## Features
+ # Why SimpleStateMachine?
+Create state machine in **three** steps :
+
+**1.** Create scheme in [node editor🔗](https://github.com/SimpleStateMachine/SimpleStateMachineNodeEditor) and load it in your project using [this library📚](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary)
+```C#
+StateMachine stateMachine = new StateMachine("scheme.xml");
+```
+**2.** Describe your app logic on events⚡
+ ```C#
+stateMachine.GetState("State1").OnExit(Action1);
+stateMachine.GetState("State2").OnEntry(Action2);
+stateMachine.GetTransition("Transition1").OnInvoke(Action3);
+stateMachine.OnChangeState(Action4);
+```
+**3.** Run the state machine🚘
+ ```C#
+stateMachine.Start();
+```
+## Features💡
State machine properties:
* Start state
@@ -34,93 +42,23 @@ Useful extensions for work:
* Export/Import to/from XML
* Logging
-
-## Examples:
-
-### Structure ###
-```C#
- StateMachine stateMachine = new StateMachine();
-
- //Add states
- State state1 = stateMachine.AddState("State1");
- State state2 = stateMachine.AddState("State2");
- State state3 = stateMachine.AddState("State3");
- State state4 = stateMachine.AddState("State4");
-
- //Add transitions three ways:
-
- //Standart way
- Transition transition1 = stateMachine.AddTransition("Transition1", state1, state2);
-
- //From state
- Transition transition2 = state2.AddTransitionFromThis("Transition2", state3);
-
- //To state
- Transition transition3 = state4.AddTransitionToThis("Transition3", state3);
-
- //Add action on entry or/and exit
- state1.OnExit(Action1);
- state2.OnEntry(Action2);
- state3.OnExit(Action3);
- state4.OnExit(Action4);
-
- //Set start state
- state1.SetAsStartState();
-
- //Start work
- stateMachine.Start();
-```
-### Actions Syntax ###
-##### Action on entry/exit #####
-```C#
- void ActionOnEtnry(State state, Dictionary parameters)
- {
- //you need invoke transition in entry or exit action, differently work state machine will be end
- state.StateMachine.InvokeTransition("Transition1");
- }
-
+## Getting Started📂
+Install from Nuget:
+```sh
+ Install-Package SimpleStateMachineLibrary
```
-##### Action on change state #####
-```C#
- void ActionOnChangeState(State stateFrom, State stateTo)
- {
+## Documentation📄
+Documentation here: https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki
- }
-```
-##### Action on transition invoke #####
-```C#
- void ActionOnTransitionInvoke(Transition transition, Dictionary parameters)
- {
+ ## FAQ❔
+ If you think you have found a bug, create a github [issue](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/issues).
+
+ But if you just have questions about how to use:
+
+- [Slack channel](https://join.slack.com/t/simplestatemachine/shared_invite/zt-fnfhvvsx-fTejcpPn~PPb2ojdG_MQBg)
+- [Telegram channel](https://t.me/joinchat/HMLJFkv9do6aDV188rhd0w)
- }
-```
-## Documentation
-* StateMachine
- * [Create](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/StateMachine#Create)
- * [Import](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/StateMachine#Import)
- * [Export](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/StateMachine#Export)
- * [Logging](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/StateMachine#Logging)
-* State
- * [Create](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/State#Create)
- * [Get](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/State#Get)
- * [Exists](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/State#Exists)
- * [Delete](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/State#Delete)
- * [Entry](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/State#Entry)
- * [Exit](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/State#Exit)
-* Transition
- * [Create](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Transition#Create)
- * [Get](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Transition#Get)
- * [Exists](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Transition#Exists)
- * [Delete](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Transition#Delete)
- * [Invoke](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Transition#Invoke)
- * [Parameters](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Transition#Parameters)
-* Data
- * [Create](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Data#Create)
- * [Get](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Data#Get)
- * [Exists](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Data#Exists)
- * [Delete](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Data#Delete)
- * [Change](https://github.com/SimpleStateMachine/SimpleStateMachineLibrary/wiki/Data#Change)
-## License
+## License📑
Copyright (c) SimpleStateMachine
diff --git a/SimpleStateMachineLibrary/Data/Data.cs b/SimpleStateMachineLibrary/Data/Data.cs
index b9f55a1..bbd8077 100644
--- a/SimpleStateMachineLibrary/Data/Data.cs
+++ b/SimpleStateMachineLibrary/Data/Data.cs
@@ -19,18 +19,18 @@ public object Value
private Action _onChange;
- internal Data(StateMachine stateMachine, string nameData, object valueData, Action actionOnChange) : base(stateMachine, nameData)
+ internal Data(StateMachine stateMachine, string nameData, object valueData, Action actionOnChange, bool withLog) : base(stateMachine, nameData)
{
Value = valueData;
- stateMachine?._logger?.LogDebug("Create data \"{NameData}\" ", nameData);
+ //stateMachine?._logger.LogDebug("Create data \"{NameData}\" ", nameData);
+
+ stateMachine._AddData(this, out _, true, withLog);
if (actionOnChange != null)
{
OnChange(actionOnChange);
- }
-
- stateMachine.AddData(this, out bool result, true);
+ }
}
public Data Delete()
@@ -48,7 +48,7 @@ public Data OnChange(Action actionOnChange)
actionOnChange = Check.Object(actionOnChange, this.StateMachine?._logger);
_onChange += actionOnChange;
- this.StateMachine._logger?.LogDebugAndInformation("Method \"{NameMethod}\" subscribe on change data \"{NameData}\"", actionOnChange.Method.Name, this.Name);
+ this.StateMachine._logger.LogDebug("Method \"{NameMethod}\" subscribe on change data \"{NameData}\"", actionOnChange.Method.Name, this.Name);
return this;
}
}
diff --git a/SimpleStateMachineLibrary/Data/DataWorkWithXML.cs b/SimpleStateMachineLibrary/Data/DataWorkWithXML.cs
index 54d90b5..7423213 100644
--- a/SimpleStateMachineLibrary/Data/DataWorkWithXML.cs
+++ b/SimpleStateMachineLibrary/Data/DataWorkWithXML.cs
@@ -7,22 +7,25 @@ namespace SimpleStateMachineLibrary
{
public partial class Data
{
- internal static XElement ToXElement(Data data)
+ internal static XElement _ToXElement(Data data, bool withLog)
{
Check.NamedObject(data, data?.StateMachine?._logger);
XElement element = new XElement("Data");
element.Add(new XAttribute("Name", data.Name));
element.Add(new XAttribute("Value", data.Value.ToString()));
- data.StateMachine._logger?.LogDebug("Data \"{NameData}\" to XElement", data.Name);
+
+ if(withLog)
+ data.StateMachine._logger.LogDebug("Data \"{NameData}\" to XElement", data.Name);
+
return element;
}
- internal XElement ToXElement()
+ internal XElement _ToXElement(bool withLog)
{
- return Data.ToXElement(this);
+ return Data._ToXElement(this, withLog);
}
- internal static Data FromXElement(StateMachine stateMachine, XElement data)
+ internal static Data _FromXElement(StateMachine stateMachine, XElement data, bool withLog)
{
stateMachine = Check.Object(stateMachine, stateMachine?._logger);
data = Check.Object(data, stateMachine?._logger);
@@ -30,8 +33,12 @@ internal static Data FromXElement(StateMachine stateMachine, XElement data)
string Name = data.Attribute("Name")?.Value;
string Value = data.Attribute("Value")?.Value;
- stateMachine?._logger?.LogDebug("Initialization data \"{NameData}\" from XElement", Name);
- return stateMachine.AddData(Name, Value);
+ Data dataObj = stateMachine._AddData(Name, Value, null, result: out bool result, exception:true, withLog: false);
+
+ if((result)&&(withLog))
+ stateMachine?._logger.LogDebug("Initialization data \"{NameData}\" from XElement", Name);
+
+ return dataObj;
}
}
diff --git a/SimpleStateMachineLibrary/SimpleStateMachineLibrary.csproj b/SimpleStateMachineLibrary/SimpleStateMachineLibrary.csproj
index 0701970..927afb1 100644
--- a/SimpleStateMachineLibrary/SimpleStateMachineLibrary.csproj
+++ b/SimpleStateMachineLibrary/SimpleStateMachineLibrary.csproj
@@ -9,18 +9,18 @@
MIT
statemachine state-machine finite-state-machine
https://github.com/SimpleStateMachine/SimpleStateMachineLibrary
- 2.1.0.0
+ 2.1.1.0
Library for SimpleStateMachine
SimpleStateMachine.png
- 2.1.0.0
- 2.1.0.0
- Add methods for check on exists
-Update package: Microsoft.Extensions.Logging.Abstractions
-Some fix
+ 2.1.1.0
+ 2.1.1.0
+ add PreviousState and CurrentTransition
+Some fix for logging
+Microsoft.Extensions.Logging.Abstractions 3.1.5
-
+
diff --git a/SimpleStateMachineLibrary/StateMachines/StateMachine.cs b/SimpleStateMachineLibrary/StateMachines/StateMachine.cs
index 00f4f22..e6a4ec6 100644
--- a/SimpleStateMachineLibrary/StateMachines/StateMachine.cs
+++ b/SimpleStateMachineLibrary/StateMachines/StateMachine.cs
@@ -19,10 +19,10 @@ public partial class StateMachine
private Dictionary _data = new Dictionary();
- internal string _currentState;
+ public string CurrentStateName { get; private set; }
- internal string _previousState;
- internal string _currentTransition { get; private set; }
+ public string PreviousStateName{ get; private set; }
+ public string CurrentTransitionName { get; private set; }
internal string _nextTransition;
internal string _startState { get; private set; }
@@ -33,10 +33,9 @@ public partial class StateMachine
internal Action _onChangeState;
- public State CurrentState { get { return GetState(_currentState); } }
- public Transition CurrentTransition { get { return GetTransition(_currentTransition); } }
-
-
+ public State CurrentState { get { return _GetState(CurrentStateName, out _, true, false); } }
+ public Transition CurrentTransition { get { return _GetTransition(CurrentTransitionName, out _, true, false); } }
+ public State PreviousState { get { return _GetState(PreviousStateName, out _, true, false); } }
@@ -58,46 +57,47 @@ public StateMachine(ILogger logger=null)
public StateMachine(XDocument xDocument, ILogger logger = null) : this(logger)
{
- FromXDocument(this, xDocument);
+ _FromXDocument(this, xDocument, true);
}
public StateMachine(string xDocumentPath, ILogger logger = null): this(logger)
{
- FromXDocument(this, xDocumentPath);
+ _FromXDocument(this, xDocumentPath, true);
}
public StateMachine OnChangeState(Action actionOnChangeState)
{
_onChangeState += actionOnChangeState;
- _logger?.LogDebug("Method \"{NameMethod}\" subscribe on change state State Machine", actionOnChangeState.Method.Name);
+ _logger.LogDebug("Method \"{NameMethod}\" subscribe on change state for State Machine", actionOnChangeState.Method.Name);
return this;
}
public State SetStartState(State state)
{
- _startState = _StateExists(state.Name, out _, true);
+ _startState = _StateExists(state.Name, out _, true, false);
- _logger?.LogDebug("State \"{NameState}\" set as start", state.Name);
+ _logger.LogDebug("State \"{NameState}\" set as start", state.Name);
return state;
}
public State SetStartState(string stateName)
{
- State state = GetState(stateName);
+ State state = _GetState(stateName, out bool result, true, false);
_startState = state.Name;
- _logger?.LogDebug("State \"{NameState}\" set as start", stateName);
+ if(result)
+ _logger.LogDebug("State \"{NameState}\" set as start", stateName);
return state;
}
public InvokeParameters InvokeTransition(string nameTransition, Dictionary parameters=null)
{
- _nextTransition = TransitionExists(nameTransition, out _);
+ _nextTransition = _TransitionExists(nameTransition, out _,true, false);
- CheckBeforeInvoke(this._logger);
+ _CheckBeforeInvoke(this._logger, true);
InvokeParameters invokeParameters = new InvokeParameters(this);
if(parameters!=null)
@@ -105,19 +105,21 @@ public InvokeParameters InvokeTransition(string nameTransition, Dictionary parameters = null)
@@ -126,7 +128,7 @@ public InvokeParameters InvokeTransition(Transition transition, Dictionary obj = new List