コード例 #1
0
 public ListCommand(ProcessingUnit processingUnit)
 {
     this.processingUnit = processingUnit;
 }
コード例 #2
0
        static void Main(string[] args)
        {
            ProcessingUnit processingUnit = new ProcessingUnit();

            /* Тест паттерна Command
             * Command command = new AddCommand(processingUnit, "snegana", "8-351-777777");
             * command.Execute();
             *
             * Command command1 = new AddCommand(processingUnit, "angela", "8-909-777-8888");
             * command1.Execute();
             *
             * Command command2 = new AddCommand(processingUnit, "boris", "1");
             * command2.Execute();
             *
             * Command command3 = new AddCommand(processingUnit, "danny", "3");
             * command3.Execute();
             *
             * Command commandList = new ListCommand(processingUnit);
             * commandList.Execute();
             */

            ShowHelp();

            bool exitFlag = false;

            do
            {
                Console.Write("> ");

                string   userCommand       = Console.ReadLine();
                String[] commandParameters = userCommand.Split(' ');
                if (commandParameters.Count() < 0)
                {
                    continue;
                }

                switch (commandParameters[0])
                {
                case "list":
                {
                    Command command = new ListCommand(processingUnit);
                    command.Execute();
                    break;
                }

                case "add":
                {
                    if (commandParameters.Count() == 3)
                    {
                        Command command = new AddCommand(processingUnit, commandParameters[1], commandParameters[2]);
                        command.Execute();
                    }
                    else
                    {
                        Console.WriteLine("Неверный формат команды add!");
                    }
                    break;
                }

                case "exit":
                {
                    exitFlag = true;
                    break;
                }

                case "help":
                {
                    ShowHelp();
                    break;
                }
                }
            } while (!exitFlag);
            //} while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
コード例 #3
0
 public AddCommand(ProcessingUnit processingUnit, string name, string phone)
 {
     this.name           = name;
     this.phone          = phone;
     this.processingUnit = processingUnit;
 }