Exemple #1
0
        public void DoLoop()
        {
            System.Console.WriteLine("Enter: I to increase, D to decrease, R to reset, or anything else to exit");
            var model = new Models.Model()
            {
                Counter = 0
            };                                              // initial state of the model

            while (true)
            {
                var input = System.Console.ReadLine();
                if (input == "I")
                {
                    if (Actions.Actions.Incr.Enabled(model))
                    {
                        _presenter.Present(model, Actions.Actions.Incr.Propose(model));
                    }
                }
                else if (input == "D")
                {
                    if (Actions.Actions.Decr.Enabled(model))
                    {
                        _presenter.Present(model, Actions.Actions.Decr.Propose(model));
                    }
                }
                else if (input == "R")
                {
                    if (Actions.Actions.Reset.Enabled(model))
                    {
                        _presenter.Present(model, Actions.Actions.Reset.Propose(model));
                    }
                }
                else if (input == "K")
                {
                    if (Actions.Actions.Lookup.Enabled(model))
                    {
                        _presenter.Present(model, Actions.Actions.Lookup.Propose(model));
                    }
                }
                else
                {
                    // stop
                    break;
                }
                Display(model);
            }
        }
Exemple #2
0
 /// <summary>
 /// Rendering:
 /// - all that is necessary for rendering should already have been computed in [render]
 /// - in a web page, we might simply use a templating engine to turn this into HTML
 /// - in a winforms app, the form could handle the representation
 /// </summary>
 /// <param name="model"></param>
 public void Display(Models.Model model)
 {
     if (_readyState.Current(model))
     {
         var repr = _readyState.Render(model);
         System.Console.WriteLine("counter: {0}", repr.Count);
         var nextAction = _readyState.Nap(model);
         if (nextAction != null)
         {
             var proposal = nextAction.Propose(model);
             _presenter.Present(model, proposal);
             Display(model);
         }
     }
     else
     {
         System.Console.WriteLine("Unreachable control state detected!");
     }
 }
Exemple #3
0
 public abstract States.StateRepr Render(Models.Model model);
Exemple #4
0
 public abstract Actions.SAMAction Nap(Models.Model model);
Exemple #5
0
 public abstract bool Current(Models.Model model);