Exemplo n.º 1
0
        public ICommand CreateCommand(string commandName, string[] arguments)
        {
            ICommand command;
            if (commandName.StartsWith("AddPhone") && (arguments.Length >= 2))
            {
                command = new AddPhoneCommand(arguments, this.sanitizer, this.phonebookDatabase, this.printer);
            }
            else if ((commandName == "ChangePhone") && (arguments.Length == 2))
            {
                command = new ChangePhoneCommand(arguments, this.sanitizer, this.phonebookDatabase, this.printer);
            }
            else if ((commandName == "List") && (arguments.Length == 2))
            {
                command = new ListCommand(arguments, this.phonebookDatabase, this.printer);
            }
            else
            {
                throw new ArgumentException();
            }

            return command;
        }
Exemplo n.º 2
0
        public string ProceedCommand(Command command)
        {
            string result = string.Empty;
            IPhonebookCommand cmd = null;

            if (command.Name == "AddPhone")
            {
                cmd = new AddCommand(this.Printer, this.PhonebookRepository, this.PhoneConverter);
            }
            else if (command.Name == "ChangePhone")
            {
                cmd = new ChangePhoneCommand(this.Printer, this.PhonebookRepository, this.PhoneConverter);
            }
            else if (command.Name == "List")
            {
                cmd = new ListCommand(this.Printer, this.PhonebookRepository);
            }

            cmd.Execute(command);

            return result;
        }