Example #1
0
 /// <summary>
 /// Process the command from the user.
 /// </summary>
 /// <param name="m">Model which triggered the command</param>
 /// <param name="c">Command that was triggered</param>
 public virtual void ProcessInputCommand(CalcModel m, Command c)
 {
     if (commands.ContainsKey(c))
     {
         commands[c].ProcessCommand(m, c);
     }
 }
Example #2
0
        /// <summary>
        /// Creates a new Program instance
        /// </summary>
        /// <param name="model">Model to use to facilitate the interaction between
        /// the UI and the logic</param>
        public Program(CalcModel model)
        {
            // The calculator core
            Calculator cal = new Calculator();

            RegisterCommandProcessors(cal, model);
        }
Example #3
0
        /// <summary>
        /// Registers the command processors.
        /// </summary>
        /// <param name="cal">Calulator the processors are to manipulate.</param>
        /// <param name="model">Model for the communication between the UI and logic</param>
        private void RegisterCommandProcessors(Calculator cal, CalcModel model)
        {
            CommandManager manager = new CommandManager(model);

            manager.RegisterProcessor(new NumericCommandProcessor(cal));
            manager.RegisterProcessor(new OperationCommandProcessor(cal));
            manager.RegisterProcessor(new EqualsCommandProcessor(cal));
            manager.RegisterProcessor(new ClearCommandProcessor(cal));
        }
Example #4
0
        /// <summary>
        /// The entry point of the program, creates the calculator logic and UI
        /// and creates the interface between the two halfs.
        /// </summary>
        public static void Main(string[] args)
        {
            // The model which is to be shared
            CalcModel calcModel = new CalcModel();
            Program   program   = new Program(calcModel);

            // Create and display the UI
            Application.Init();
            MainWindow win = new MainWindow(calcModel);

            win.Show();
            Application.Run();
        }
Example #5
0
 /// <summary>
 /// Creates a new manager for the specified model.
 /// </summary>
 /// <param name="calcModel">Calculator model from where the commands are
 /// to be received.</param>
 public CommandManager(CalcModel calcModel)
 {
     this.calcModel          = calcModel;
     calcModel.InputCommand += ProcessInputCommand;
 }