11using Microsoft . Extensions . Logging ;
22using SimpleStateMachineLibrary . Helpers ;
3+ using System ;
4+ using System . Collections . Generic ;
35using System . Xml . Linq ;
46
57
68namespace SimpleStateMachineLibrary
79{
810 public partial class StateMachine
911 {
10- private State _State ( string nameState , out bool result , bool exception )
12+ private State _GetState ( string nameState , out bool result , bool exception )
1113 {
1214 var _state = Check . GetElement ( _states , nameState , this . _logger , out result , exception ) ;
1315
@@ -19,35 +21,38 @@ private State _State(string nameState, out bool result, bool exception)
1921 return _state ;
2022 }
2123
22- private State _State ( State state , out bool result , bool exception )
23- {
24- var _state = Check . GetElement ( _states , state , this . _logger , out result , exception ) ;
24+ // private State _GetState (State state, out bool result, bool exception)
25+ // {
26+ // var _state = Check.GetElement(_states, state, this._logger, out result, exception);
2527
26- if ( exception )
27- _logger ? . LogDebug ( "Get state \" {NameState}\" " , state . Name ) ;
28- else
29- _logger ? . LogDebug ( "Try get state \" {NameState}\" " , state . Name ) ;
28+ // if (exception)
29+ // _logger?.LogDebug("Get state \"{NameState}\"", state.Name);
30+ // else
31+ // _logger?.LogDebug("Try get state \"{NameState}\"", state.Name);
3032
3133
32- return _state ;
33- }
34+ // return _state;
35+ //}
36+
3437
35- public State State ( string nameState , bool exception = true )
38+ public State GetState ( string nameState )
3639 {
37- return _State ( nameState , out bool result , exception ) ;
40+ return _GetState ( nameState , out bool result , true ) ;
3841 }
3942
4043 public State TryGetState ( string nameState , out bool result )
4144 {
42- return _State ( nameState , out result , false ) ;
45+ return _GetState ( nameState , out result , false ) ;
4346 }
4447
45- public State TryGetState ( State state , out bool result )
46- {
47- return _State ( state , out result , false ) ;
48- }
48+ // public State TryGetState(State state, out bool result)
49+ // {
50+ // return _GetState (state, out result, false);
51+ // }
4952
50- private State _AddState ( string nameState , out bool result , bool exception )
53+
54+
55+ internal State _AddState ( string nameState , Action < State , Dictionary < string , object > > actionOnEntry , Action < State , Dictionary < string , object > > actionOnExit , out bool result , bool exception )
5156 {
5257 //throw that element already contains
5358 result = Check . NotContains ( _states , nameState , this . _logger , exception ) ;
@@ -56,8 +61,9 @@ private State _AddState(string nameState, out bool result, bool exception)
5661 if ( ! result )
5762 return null ;
5863
59- return new State ( this , nameState ) ;
64+ return new State ( this , nameState , actionOnEntry , actionOnExit ) ;
6065 }
66+
6167 internal State AddState ( State state , out bool result , bool exception )
6268 {
6369 //throw that element already contains
@@ -76,22 +82,24 @@ internal State AddState(State state, out bool result, bool exception)
7682 return state ;
7783 }
7884
79- public State AddState ( string nameState )
85+ internal State AddState ( XElement xElement )
8086 {
81- return _AddState ( nameState , out bool result , true ) ;
87+ return SimpleStateMachineLibrary . State . FromXElement ( this , Check . Object ( xElement , this . _logger ) ) ;
8288 }
8389
84- public State AddState ( XElement xElement )
90+
91+ public State AddState ( string nameState , Action < State , Dictionary < string , object > > actionOnEntry = null , Action < State , Dictionary < string , object > > actionOnExit = null )
8592 {
86- return SimpleStateMachineLibrary . State . FromXElement ( this , Check . Object ( xElement , this . _logger ) ) ;
93+ return _AddState ( nameState , actionOnEntry , actionOnExit , out bool result , true ) ;
8794 }
8895
89- public State TryAddState ( string nameState , out bool result )
96+ public State TryAddState ( out bool result , string nameState , Action < State , Dictionary < string , object > > actionOnEntry = null , Action < State , Dictionary < string , object > > actionOnExit = null )
9097 {
91- return _AddState ( nameState , out result , false ) ;
98+ return _AddState ( nameState , actionOnEntry , actionOnExit , out result , false ) ;
9299 }
93100
94101
102+
95103 private State _DeleteState ( State state , out bool result , bool exception )
96104 {
97105
@@ -118,14 +126,15 @@ private State _DeleteState(string stateName, out bool result, bool exception)
118126 return _state ;
119127 }
120128
129+
121130 public State DeleteState ( State state )
122131 {
123132 return _DeleteState ( state , out bool result , true ) ;
124133 }
125134
126135 public State DeleteState ( string stateName )
127136 {
128- return _DeleteState ( State ( stateName ) , out bool result , true ) ;
137+ return _DeleteState ( GetState ( stateName ) , out bool result , true ) ;
129138 }
130139
131140 public State TryDeleteState ( State state , out bool result )
0 commit comments