Beispiel #1
0
        private static void ExecuteCommands(List <string> commands, PhoneBook phoneBook)
        {
            foreach (var command in commands)
            {
                List <PhoneEntry> found     = new List <PhoneEntry>();
                string[]          arguments = command.Split();
                if (arguments.Length == 1)
                {
                    found = phoneBook.Find(arguments[0]);
                }
                else if (arguments.Length == 2)
                {
                    found = phoneBook.Find(arguments[0], arguments[1]);
                }

                PrintFoundEntries(found, command);
            }
        }
        private static void ExecuteCommands(List<string> commands, PhoneBook phoneBook)
        {
            foreach (var command in commands)
            {
                List<PhoneEntry> found = new List<PhoneEntry>();
                string[] arguments = command.Split();
                if (arguments.Length == 1)
                {
                    found = phoneBook.Find(arguments[0]);
                }
                else if (arguments.Length == 2)
                {
                    found = phoneBook.Find(arguments[0], arguments[1]);
                }

                PrintFoundEntries(found, command);
            }
        }
Beispiel #3
0
        public static void Main()
        {
            HashSet<string> phoneEntriesInput = ReadFile("../../phones.txt");
            HashSet<string> commandsInput = ReadFile("../../commands.txt");
            IList<Entry> phoneEntries = ParsePhoneEntries(phoneEntriesInput);

            PhoneBook phoneBook = new PhoneBook();

            foreach (var entry in phoneEntries)
            {
                phoneBook.Add(entry);
            }

            IList<ICommand<Entry>> commands = ParsePhonebookCommands(commandsInput, phoneBook);

            foreach (var command in commands)
            {
                var result = command.Execute();
            }
        }
Beispiel #4
0
        private static IList<ICommand<Entry>> ParsePhonebookCommands(HashSet<string> commandsInput, PhoneBook phoneBook)
        {
            List<ICommand<Entry>> commands = new List<ICommand<Entry>>();
            foreach (var command in commandsInput)
            {
                string[] commandParts = command.Split(new char[] { '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
                var parametres = commandParts[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                switch (parametres.Length)
                {
                    case 1: commands.Add(new FindCommand(phoneBook, parametres[0].Trim()));
                        break;
                    case 2: commands.Add(new FindCommand(phoneBook, parametres[0].Trim(), parametres[1].Trim()));
                        break;
                    default:
                        break;
                }
            }

            return commands;
        }
Beispiel #5
0
        private static void Test1()
        {
            var book = new PhoneBook();

            book.Add("Ivan", "1", "2");
            book.Add("Ivan Vankata", "3", "4");

            Console.WriteLine(book.Find("Ivan"));
            Console.WriteLine();
            Console.WriteLine(book.Find("Ivan", "3"));
        }
        static void Main(string[] args)
        {
            List<PhoneEntry> phoneEntries = GetPhones();
            PhoneBook phoneBook = new PhoneBook(phoneEntries);

            List<string> commands = GetCommands();

            ExecuteCommands(commands, phoneBook);
        }