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));
        }
Ejemplo n.º 2
0
 public static NoSetupMachine Create()
 {
     return(StateMachineBuilder <NoSetupMachine, NoState> .Build
                ((b, m) =>
                b.CreateTransition(
                    when: NoState.None,
                    then: nsm => nsm.Foo(),
                    goesTo: NoState.None)));
 }
Ejemplo n.º 3
0
        public void Init()
        {
            stateMachineBuilder = new StateMachineBuilder <State, Operation, string>()
                                  .SetStart(State.Start)
                                  .WithTransition(State.Start, Operation.StartToFinish, State.Finish, async ctx => this.contextString = ctx.Data)
                                  .WithTransition(State.Start, Operation.StartToMiddle, State.Middle)
                                  .WithTransition(State.Middle, Operation.MiddleToFinish, State.Finish);

            this.machine = stateMachineBuilder
                           .Build();
        }
Ejemplo n.º 4
0
        public static SimpleMachine Create()
        {
            var machine = StateMachineBuilder <SimpleMachine, Simple> .Build(
                (b, m) =>
                b.CreateTransition(
                    when : Simple.One,
                    then : vm => vm.Foo(),
                    goesTo : Simple.Two)
                .Setup(getState : () => m.State,
                       setState : s => m.State = s)
                );

            return(machine);
        }
Ejemplo n.º 5
0
 public static VendingMachine Create()
 {
     return(StateMachineBuilder <VendingMachine, VendingState> .Build
                ((b, m) =>
                b.CreateTransition(
                    when : VendingState.Waiting,
                    then : vm => vm.Pay(),
                    goesTo : VendingState.Paid)
                .CreateTransition(
                    when : VendingState.Paid,
                    then : vm => vm.Select(),
                    goesTo : VendingState.Waiting)
                .Setup(getState : () => m.State,
                       setState : s => m.State = s,
                       onStateChanging : a => m.StateChanging(m, a),
                       onStateChanged : a => m.StateChanged(m, a)
                       )
                ));
 }
Ejemplo n.º 6
0
        public async Task SaveAndLoad()
        {
            machine.State.Should().Be(State.Start);

            await machine.Process(Operation.StartToMiddle);

            machine.State.Should().Be(State.Middle);

            State savedMiddleState = machine.State;

            var newMachine = stateMachineBuilder.Build(savedMiddleState);

            newMachine.State.Should().Be(State.Middle);
            newMachine.IsFinished.Should().BeFalse();

            await newMachine.Process(Operation.MiddleToFinish);

            newMachine.State.Should().Be(State.Finish);
            newMachine.IsFinished.Should().BeTrue();
        }
Ejemplo n.º 7
0
        public void SetUp()
        {
            stateMachine = StateMachineBuilder.Build().WithLayers().WithStates();

            //---------------------------
            stateMachine.AddLayer("LayerA");

            stateMachine.AddState("e");
            stateMachine.AddState("f");
            stateMachine.AddState("g");
            stateMachine.AddState("h");
            stateMachine.AddState("i");
            stateMachine.AddState("j");
            //---------------------------
            stateMachine.AddLayer("LayerB");
            stateMachine.AddState("a15445");
            stateMachine.AddState("b");
            stateMachine.AddState("c");
            stateMachine.AddState("d");
            stateMachine.AddState("k");
            stateMachine.AddState("l");
            stateMachine.AddState("m");
        }
Ejemplo n.º 8
0
 public void SetUp()
 {
     stateMachine = StateMachineBuilder.Build().WithLayers().WithStates();
 }
Ejemplo n.º 9
0
 public static NoTransitionMachine Create()
 {
     return(StateMachineBuilder <NoTransitionMachine, NoState> .Build
                ((b, m) => b.Setup(s => { }, () => NoState.None)));
 }
Ejemplo n.º 10
0
 public void SetUp() => stateMachine = StateMachineBuilder.Build();
 public void SetUp()
 {
     stateMachine = StateMachineBuilder.Build().WithLayers();
     stateMachine.AddState("abc");
 }