예제 #1
0
파일: Phonebook.cs 프로젝트: elibk/DSA
        public static void Main(string[] args)
        {
            // needed to display the report right
            Console.WindowWidth = 80;

            PhonebookRepository repository = new PhonebookRepository();

            StreamReader enriesReader = new StreamReader(EnriesPath);

            using (enriesReader)
            {
                string line = enriesReader.ReadLine();
                while (line != null)
                {
                    PhonebookEntry currentEntry = PhonebookEntry.Parse(line);
                    repository.AddEntry(currentEntry);
                    line = enriesReader.ReadLine();
                }
            }

            StreamReader commandsReader = new StreamReader(CommandPath);

            using (commandsReader)
            {
                Console.WriteLine(new string('_', Console.WindowWidth));
                string line = commandsReader.ReadLine();
                while (line != null)
                {
                    var report = ParseCommand(line, repository);

                    if (report.Count() != 0)
                    {
                        foreach (var item in report)
                        {
                            Console.WriteLine(item);
                        }

                        Console.WriteLine(new string('_', Console.WindowWidth));
                    }
                    else
                    {
                        Console.WriteLine("No information found.");
                        Console.WriteLine(new string('_', Console.WindowWidth));
                    }

                    line = commandsReader.ReadLine();
                }
            }
        }
예제 #2
0
        public void AddEntry(PhonebookEntry newEntry)
        {
            if (newEntry.FirstName != PhonebookEntry.NameDefaultValue)
            {
                this.dictByFirstName.Add(newEntry.FirstName, newEntry);
            }

            if (!(newEntry.MiddleName != PhonebookEntry.NameDefaultValue))
            {
                this.dictByMiddleName.Add(newEntry.MiddleName, newEntry);
            }

            if (newEntry.LastName != PhonebookEntry.NameDefaultValue)
            {
                this.dictByLastName.Add(newEntry.LastName, newEntry);
            }

            if (newEntry.NickName != PhonebookEntry.NameDefaultValue)
            {
                this.dictByNickname.Add(newEntry.NickName, newEntry);
            }
        }