public StateMachine <Inputs, Outputs, StateTypes> Create() { var stateMachineBuilder = new StateMachineBuilder <Inputs, Outputs, StateTypes>(); stateMachineBuilder.AddState(StateTypes.Z1); stateMachineBuilder.AddState(StateTypes.Z2); stateMachineBuilder.AddState(StateTypes.Z3); stateMachineBuilder.AddState(StateTypes.Z4); stateMachineBuilder.AddTransition(StateTypes.Z1, Inputs.X1, Outputs.Y1, StateTypes.Z2); stateMachineBuilder.AddTransition(StateTypes.Z1, Inputs.X4, Outputs.Y1, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z1, Inputs.X2, Outputs.Y1, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z1, Inputs.X3, Outputs.Y1, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z1, Inputs.X5, Outputs.Y1, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z2, Inputs.X2, Outputs.Y2, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z2, Inputs.X1, Outputs.Y2, StateTypes.Z2); stateMachineBuilder.AddTransition(StateTypes.Z2, Inputs.X3, Outputs.Y3, StateTypes.Z3); stateMachineBuilder.AddTransition(StateTypes.Z2, Inputs.X4, Outputs.Y4, StateTypes.Z4); stateMachineBuilder.AddTransition(StateTypes.Z2, Inputs.X5, Outputs.Y1, StateTypes.Z2); stateMachineBuilder.AddTransition(StateTypes.Z3, Inputs.X5, Outputs.Y3, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z3, Inputs.X1, Outputs.Y2, StateTypes.Z3); stateMachineBuilder.AddTransition(StateTypes.Z3, Inputs.X4, Outputs.Y1, StateTypes.Z3); stateMachineBuilder.AddTransition(StateTypes.Z3, Inputs.X2, Outputs.Y1, StateTypes.Z3); stateMachineBuilder.AddTransition(StateTypes.Z3, Inputs.X3, Outputs.Y1, StateTypes.Z3); stateMachineBuilder.AddTransition(StateTypes.Z4, Inputs.X5, Outputs.Y4, StateTypes.Z1); stateMachineBuilder.AddTransition(StateTypes.Z4, Inputs.X1, Outputs.Y2, StateTypes.Z4); stateMachineBuilder.AddTransition(StateTypes.Z4, Inputs.X4, Outputs.Y1, StateTypes.Z4); stateMachineBuilder.AddTransition(StateTypes.Z4, Inputs.X2, Outputs.Y1, StateTypes.Z4); stateMachineBuilder.AddTransition(StateTypes.Z4, Inputs.X3, Outputs.Y1, StateTypes.Z4); return(stateMachineBuilder.Build(StateTypes.Z1)); }
public Sample() { InitializeComponent(); stateMachineBuilder = new StateMachineBuilder(); stateMachineBuilder.AddState(States.Green) .TransitionOn(Events.Change, States.Yellow) .OnEnter(s => Invoker(() => pnlGreen.BackColor = GreenOn)) .OnExit(s => Invoker(() => pnlGreen.BackColor = GreenOff)) .Timeout(3000, States.Yellow) .InitialState(); stateMachineBuilder.AddState(States.Yellow) .TransitionOn(Events.Change, States.Red) .Timeout(3000, States.Red) .OnEnter(s => Invoker(() => pnlYellow.BackColor = YellowOn)) .OnExit(s => Invoker(() => pnlYellow.BackColor = YellowOff)); stateMachineBuilder.AddState(States.Red) .TransitionOn(Events.Change, States.Green) .Timeout(3000, States.Green) .OnEnter(s => Invoker(() => pnlRed.BackColor = RedOn)) .OnExit(s => Invoker(() => pnlRed.BackColor = RedOff)); stateMachine = new StateMachine("StopLight", stateMachineBuilder); stateMachine.Asynchronous(); }