Esempio n. 1
0
        public ViewModel()
        {
            // コマンドの初期化
            PlusCommand  = new PlusCommand();
            MinusCommand = new MinusCommand();
            MultiCommand = new MultiCommand();
            DivCommand   = new DivCommand();

            // コマンド実行後の結果をResultに反映
            PlusCommand.PropertyChanged += (sender, e) =>
            {
                Result = ((PlusCommand)sender).Result.ToString();
                RaisePropertyChanged(e.PropertyName);
            };
            MinusCommand.PropertyChanged += (sender, e) =>
            {
                Result = ((MinusCommand)sender).Result.ToString();
                RaisePropertyChanged(e.PropertyName);
            };
            MultiCommand.PropertyChanged += (sender, e) =>
            {
                Result = ((MultiCommand)sender).Result.ToString();
                RaisePropertyChanged(e.PropertyName);
            };
            DivCommand.PropertyChanged += (sender, e) =>
            {
                Result = ((DivCommand)sender).Result;
                RaisePropertyChanged(e.PropertyName);
            };
        }
Esempio n. 2
0
 public CalculatorViewModel()
 {
     plusCommand     = new PlusCommand(this);
     minusCommand    = new MinusCommand(this);
     multiplyCommand = new MultiplyCommand(this);
     divisionCommand = new DivionCommand(this);
 }
 public ControlBarVM(FGM m) : base(m)
 {
     PauseTheFlight   = new PauseCommand(PauseThread);
     PlayTheFlight    = new PlayCommand(ContinueRunning);
     IncreaseTheSpeed = new PlusCommand(IncreaseSpeed);
     DecreaseTheSpeed = new MinusCommand(DecreaseSpeed);
     StopTheFlight    = new StopCommand(StopFlight);
 }
Esempio n. 4
0
        public void MinusCommand_WithOneNumberInStack_FailExecute()
        {
            var command = new MinusCommand();
            var stack   = new Stack <decimal>();

            stack.Push(1);

            Exception ex = Assert.Throws <CalculateException>(() => command.Calculate(stack));

            Assert.Equal("Невозможно вычесть 2 числа", ex.Message);
        }
Esempio n. 5
0
        public void MinusCommand_WithTwoNumberInStack_DifferenceInStack()
        {
            var command = new MinusCommand();
            var stack   = new Stack <decimal>();

            stack.Push(3);
            stack.Push(2);

            command.Calculate(stack);

            Assert.Single(stack);
            Assert.Equal(1m, stack.Peek());
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Calculator calc = new Calculator();

            while (true)
            {
                string[] input = Console.ReadLine().Split();

                int value = int.Parse(input[1]);

                ICommmand command = null;

                switch (input[0])
                {
                case "+":
                    command = new PlusCommand(value);
                    break;

                case "-":
                    command = new MinusCommand(value);
                    break;

                case "*":
                    command = new MultiplyCommand(value);
                    break;

                case "undo":
                    calc.Undo(value);
                    break;

                case "redo":
                    calc.Redo(value);
                    break;
                }

                if (command != null)
                {
                    calc.AddCommand(command);
                }


                Console.WriteLine(calc.Result);
            }
        }
        public PalettePartsDetailsViewModel()
        {
            _palettePartsRepository = new PalettePartsSQLServer();
            _bomRepository          = new BomSQLServer();
            AssyNumbers.Value       = new ObservableCollection <string>();

            GetAssyNumbers();
            GetPalettes();
            SelectedAssyNumber.Subscribe(_ => SelectedAssyNumberChangeEcecute());
            SelectedPaletteDetails.Subscribe(_ => SelectedPaletteDetailsChangeExecute());
            SelectedBom.Subscribe(_ => SelectedBomChangeExecute());
            PlusCommand.Subscribe(_ => PlusCommandExecute());
            MinusCommand.Subscribe(_ => MinusCommandExecute());
            SelectedPalette.Subscribe(_ => SearchCommandExecute());
            PaletteDetailsPlusCommand.Subscribe(_ => PaletteDetailsPlusCommandExecute());
            PaletteDetailsMinusCommand.Subscribe(_ => PaletteDetailsMinusommandExecute());
            PaletteDetailsUpdateCommand.Subscribe(_ => PaletteDetailsSaveExecute());
            PaletteDetailsAddCommand.Subscribe(_ => PaletteDetailsAddCommandExecute());
            PaletteDetailsDeleteCommand.Subscribe(_ => PaletteDetailsDeleteCommandExecute());
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            using (reader = File.OpenText("input.txt"))
                using (writer = new StreamWriter(File.Create("output.txt")))
                {
                    QuackVM  vm = new QuackVM();
                    Workflow wf = new Workflow(vm);

                    while (!reader.EndOfStream)
                    {
                        string   str = reader.ReadLine();
                        ICommand cmd = null;
                        switch (str[0])
                        {
                        case '+':
                            cmd = new PlusCommand();
                            break;

                        case '-':
                            cmd = new MinusCommand();
                            break;

                        case '*':
                            cmd = new MultiplyCommand();
                            break;

                        case '/':
                            cmd = new DivideCommand();
                            break;

                        case '%':
                            cmd = new ModuloCommand();
                            break;

                        case '>':
                            cmd = new SetRegisterCommand(str[1]);
                            break;

                        case '<':
                            cmd = new GetRegisterCommand(str[1]);
                            break;

                        case 'P':
                            if (str.Length > 1)
                            {
                                cmd = new PrintRegisterCommand(str[1]);
                            }
                            else
                            {
                                cmd = new PrintCommand();
                            }
                            break;

                        case 'C':
                            if (str.Length > 1)
                            {
                                cmd = new PrintRegisterCharCommand(str[1]);
                            }
                            else
                            {
                                cmd = new PrintCharCommand();
                            }
                            break;

                        case ':':
                            cmd = new LabelCommand(str.Substring(1));
                            break;

                        case 'J':
                            cmd = new GoToLabelCommand(str.Substring(1));
                            break;

                        case 'Z':
                            cmd = new GoToLabelZCommand(str[1], str.Substring(2));
                            break;

                        case 'E':
                            cmd = new GoToLabelECommand(str[1], str[2], str.Substring(3));
                            break;

                        case 'G':
                            cmd = new GoToLabelGCommand(str[1], str[2], str.Substring(3));
                            break;

                        case 'Q':
                            cmd = new QuitCommand();
                            break;

                        default:
                            cmd = new NumberCommand(int.Parse(str));
                            break;
                        }
                        wf.AddCommand(cmd);
                    }

                    while (!wf.IsCompleted())
                    {
                        wf.ExecuteCurrentCommand();
                    }
                }
        }