Ejemplo n.º 1
0
        public void Test()
        {
            // 构造Receiver对象
            Receiver receiver = new Receiver();

            // 组织Command对象
            ICommand command1 = new SetNameCommand();
            ICommand command2 = new SetAddressCommand();

            command1.Receiver = receiver;
            command2.Receiver = receiver;

            // 定义调用者,管理Command对象
            Invoker invoker = new Invoker();

            invoker.AddCommand(command1);
            invoker.AddCommand(command2);

            Assert.AreEqual <string>(string.Empty, receiver.Name);
            Assert.AreEqual <string>(string.Empty, receiver.Address);

            // 实际执行调用并检验调用后的效果
            invoker.Run();
            Assert.AreEqual <string>("name", receiver.Name);
            Assert.AreEqual <string>("address", receiver.Address);
        }
        public string DispatchCommand(string[] commandParams, IServiceProvider serviceProvider)
        {
            string commandName = commandParams[0];

            var commandArg = commandParams.Skip(1).ToArray();

            string result = string.Empty;

            switch (commandName)
            {
            case "AddEmployee":
                var addEmployee = new AddEmployeeCommand(serviceProvider.GetService <EmployeeService>());
                result = addEmployee.Execute(commandArg);
                break;

            case "SetBirthday":
                var setBirthday = new SetBirthdayCommand(serviceProvider.GetService <EmployeeService>());
                result = setBirthday.Execute(commandArg);
                break;

            case "SetAddress":
                var setAddress = new SetAddressCommand(serviceProvider.GetService <EmployeeService>());
                result = setAddress.Execute(commandArg);
                break;

            case "EmployeeInfo":
                var employeeInfo = new EmployeeInfoCommand(serviceProvider.GetService <EmployeeService>());
                result = employeeInfo.Execute(commandArg);
                break;

            case "EmployeePersonalInfo":
                var employeePersonalInfo = new EmployeePersonalInfoCommand(serviceProvider.GetService <EmployeeService>());
                result = employeePersonalInfo.Execute(commandArg);
                break;

            case "SetManager":
                var setManager = new SetManagerCommand(serviceProvider.GetService <EmployeeService>());
                result = setManager.Execute(commandArg);
                break;

            case "ManagerInfo":
                var managerInfo = new ManagerInfoCommand(serviceProvider.GetService <EmployeeService>());
                result = managerInfo.Execute(commandArg);
                break;

            case "ListEmployeesOlderThan":
                var olderThan = new ListEmployeesOlderThanCommand(serviceProvider.GetService <EmployeeService>());
                result = olderThan.Execute(commandArg);
                break;

            default: throw new InvalidOperationException("Invalid command!");
            }
            return(result);
        }
Ejemplo n.º 3
0
        private void RaiseCommandsCanExecute()
        {
            GetAllTeamProjectsWITypesCommand.RaiseCanExecuteChanged();
            GetWITypesCommand.RaiseCanExecuteChanged();
            SetAddressCommand.RaiseCanExecuteChanged();
            ClearOutputCommand.RaiseCanExecuteChanged();

            if (WIDViewer != null)
            {
                WIDViewer.ShowCommand.RaiseCanExecuteChanged();
            }
            if (WIDExport != null)
            {
                WIDExport.ExportCommand.RaiseCanExecuteChanged();
            }
            if (WIDImport != null)
            {
                WIDImport.ImportCommand.RaiseCanExecuteChanged();
            }
            if (WIDRename != null)
            {
                WIDRename.RenameCommand.RaiseCanExecuteChanged();
            }
            if (WIDDestroy != null)
            {
                WIDDestroy.DestroyCommand.RaiseCanExecuteChanged();
            }

            if (CategoriesViewer != null)
            {
                CategoriesViewer.ShowCommand.RaiseCanExecuteChanged();
            }
            if (CategoriesExport != null)
            {
                CategoriesExport.ExportCommand.RaiseCanExecuteChanged();
            }
            if (CategoriesImport != null)
            {
                CategoriesImport.ImportCommand.RaiseCanExecuteChanged();
            }

            if (ProcessConfigViewer != null)
            {
                ProcessConfigViewer.ShowCommand.RaiseCanExecuteChanged();
            }
            if (ProcessConfigExport != null)
            {
                ProcessConfigExport.ExportCommand.RaiseCanExecuteChanged();
            }
            if (ProcessConfigImport != null)
            {
                ProcessConfigImport.ImportCommand.RaiseCanExecuteChanged();
            }
        }
Ejemplo n.º 4
0
            public void Test()
            {
                //构造Receiver对象
                Receiver receriver = new Receiver();

                //组织Command对象
                ICommand command1 = new SetNameCommand();
                ICommand command2 = new SetAddressCommand();

                command1.Receiver = receriver;
                command2.Receiver = receriver;

                Invoker invoker = new Invoker();

                invoker.AddCommand(command1);
                invoker.AddCommand(command2);

                invoker.Run();

                Console.ReadLine();
            }
Ejemplo n.º 5
0
 public async Task <IActionResult> SetAddress([FromBody] SetAddressCommand command)
 {
     return(Ok(await _mediator.Send(command)));
 }