|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Microsoft.Extensions.Logging; |
| 4 | +using SimpleStateMachineLibrary; |
| 5 | + |
| 6 | +namespace Examples |
| 7 | +{ |
| 8 | + class Program |
| 9 | + { |
| 10 | + static void Method1(State state, Dictionary<string, object> parameters) |
| 11 | + { |
| 12 | + state.StateMachine.InvokeTransition("Transition1"); |
| 13 | + } |
| 14 | + static void Method2(State state, Dictionary<string, object> parameters) |
| 15 | + { |
| 16 | + state.StateMachine.InvokeTransition("Transition2"); |
| 17 | + } |
| 18 | + static void Method3(State state, Dictionary<string, object> parameters) |
| 19 | + { |
| 20 | + state.StateMachine.InvokeTransition("Transition3"); |
| 21 | + } |
| 22 | + static void Method4(State state, Dictionary<string, object> parameters) |
| 23 | + { |
| 24 | + |
| 25 | + } |
| 26 | + |
| 27 | + static Dictionary<string, object> parametersForStart = new Dictionary<string, object>() { { "Data1", "Test Data" } }; |
| 28 | + |
| 29 | + static void Main(string[] args) |
| 30 | + { |
| 31 | + var loggerFactory = LoggerFactory.Create(builder => { builder.AddConsole().AddDebug().SetMinimumLevel(LogLevel.Debug); }); |
| 32 | + var logger = loggerFactory.CreateLogger<StateMachine>(); |
| 33 | + StateMachine stateMachine = new StateMachine(logger); |
| 34 | + |
| 35 | + State state1 = stateMachine.AddState("State1"); |
| 36 | + State state2 = stateMachine.AddState("State2"); |
| 37 | + State state3 = stateMachine.AddState("State3"); |
| 38 | + State state4 = stateMachine.AddState("State4"); |
| 39 | + |
| 40 | + Transition transition1 = state1.AddTransitionFromThis("Transition1", state2); |
| 41 | + Transition transition2 = stateMachine.AddTransition("Transition2", state2, state3); |
| 42 | + Transition transition3 = state4.AddTransitionToThis("Transition3", state3); |
| 43 | + |
| 44 | + state1.SetAsStartState(); |
| 45 | + state1.OnExit(Method1); |
| 46 | + state2.OnExit(Method2); |
| 47 | + state3.OnExit(Method3); |
| 48 | + state4.OnExit(Method4); |
| 49 | + |
| 50 | + stateMachine.AddData("int1", 55); |
| 51 | + stateMachine.AddData("string1", "Roman"); |
| 52 | + stateMachine.AddData("double1", 1001.0005); |
| 53 | + |
| 54 | + stateMachine.Start(parametersForStart); |
| 55 | + |
| 56 | + stateMachine.ToXDocument("text.xml"); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments