Exemple #1
0
        private static void BuildStateTwo(DemoModel model, MachineEditor <DemoState> builder)
        {
            var two = builder.EditState(DemoState.Two);

            // Transition from TWO to FOUR
            var twoToFour = two.TransitionTo(DemoState.Four)
                            .TriggerWithCollection(model.Observables, 5)
                            .TriggerWithEvent <DemoModel, DemoEventArgs>(model, nameof(model.TriggerEvent));
        }
Exemple #2
0
        private static void BuildStateThree(DemoModel model, MachineEditor <DemoState> builder)
        {
            var three = builder.EditState(DemoState.Three);

            // Transition from THREE to ONE
            var threeToOne = three.TransitionTo(DemoState.One)
                             .GuardWith(() => model.Children.All(c => c.StateMachine.CurrentState == ChildState.Ready), "All Children Ready")
                             .TriggerWithStateChange(model.Children.Select(c => c.StateMachine).ToList(), builder.Machine, ChildState.Ready)
                             .TriggerWithEvent <DemoModel, DemoEventArgs>(model, nameof(model.TriggerEvent));
        }
        public DemoViewModel()
        {
            _model = new DemoModel(_logger);

            ControlPanelVM = new ControlPanelViewModel(_model);
            StateMachineVM = new StateMachineViewModel(_model, _logger);

            _model.StateMachine.StateChanged += HandleStateChanged;
            _model.ResetOccurred             += HandleModelReset;
        }
        public ControlPanelViewModel(DemoModel demoModel)
        {
            Model             = demoModel;
            TriggerAllCommand = new DelegateCommand(Model.TriggerAll);

            // Compile a dummy expression in order to front load all the roslyn dependencies.
            _expression = "false";
            CompileExpression();
            _expression = string.Empty;

            Model.PropertyChanged += HandleModelPropertyChanged;
        }
Exemple #5
0
        public static MachineEditor <DemoState> BuildStateMachine(this DemoModel model, StateMachine <DemoState> machine)
        {
            var builder = MachineEditor <DemoState> .Edit(machine);

            machine.SetInitialState(DemoState.One);
            BuildStateOne(model, builder);
            BuildStateTwo(model, builder);
            BuildStateThree(model, builder);
            BuildStateFour(model, builder);

            return(builder);
        }
Exemple #6
0
        private static void BuildStateFour(DemoModel model, MachineEditor <DemoState> builder)
        {
            var four = builder.EditState(DemoState.Four);

            // Transition from FOUR to FOUR
            var fourToFour = four.TransitionTo(DemoState.Four)
                             .GuardWith(() => model.LoopCount > 0, "Loop Count>0")
                             .TriggerWithProperty(model, nameof(model.LoopCount))
                             .TriggerWithEvent <DemoModel, DemoEventArgs>(model, nameof(model.TriggerEvent));

            // Transition from FOUR to THREE
            var fourToThree = four.TransitionTo(DemoState.Three)
                              .GuardWith(() => model.BoolFunc.Invoke() && model.LoopCount == 0, "Expression Is True")
                              .TriggerWithProperty(model, nameof(model.BoolFunc))
                              .TriggerWithEvent <DemoModel, DemoEventArgs>(model, nameof(model.TriggerEvent));
        }
Exemple #7
0
        private static void BuildStateOne(DemoModel model, MachineEditor <DemoState> builder)
        {
            var one = builder.EditState(DemoState.One);

            // Transition from ONE to TWO
            one.TransitionTo(DemoState.Two)
            .GuardWith(() => model.OnOff, "On")
            .TriggerWithProperty(model, nameof(model.OnOff))
            .TriggerWithEvent <DemoModel, DemoEventArgs>(model, nameof(model.TriggerEvent));

            // Transition from ONE to THREE
            one.TransitionTo(DemoState.Three)
            .GuardWith(() => model.Number == 1 && !model.OnOff, "Number==1 && Off")
            .TriggerWithProperty(model, nameof(model.OnOff))
            .TriggerWithProperty(model, nameof(model.Number))
            .TriggerWithEvent <DemoModel, DemoEventArgs>(model, nameof(model.TriggerEvent));
        }
Exemple #8
0
 public StateMachineViewModel(DemoModel demoModel, ILog logger)
 {
     _logger = logger;
     Model   = demoModel;
 }