Ejemplo n.º 1
0
        private static void ProcessCommands(IEnumerable <string> commands, Phonebook phonebook)
        {
            foreach (var command in commands)
            {
                Console.WriteLine(START);
                Console.WriteLine("Command to execute: " + command);
                var args        = command.Substring(5, command.Length - 6);
                var searchTerms = args.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                try
                {
                    var entries = phonebook.Find(searchTerms);
                    Console.WriteLine(string.Join("\n", entries));
                }
                catch (KeyNotFoundException)
                {
                    Console.WriteLine("Command failed: {0}!", args);
                }

                Console.WriteLine(END);
            }
        }
Ejemplo n.º 2
0
        private static void ProcessInput(Phonebook phonebook, string line)
        {
            var input = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);

            phonebook.Add(new PhonebookEntry(input[0].Trim(), input[1].Trim(), input[2].Trim()));
        }