Exemplo n.º 1
0
 public static void SaveLogToFile()
 {
     StoreGame.ClearLog();
     for (int i = 0; i < entriesConsole.Count; i++)
     {
         StoreGame.SaveLog(StoreGame.EType.DEBUG_LOG, entriesConsole[i].message);
     }
     if (StoreGame.Contains(StoreGame.EType.DEBUG_LOG))
     {
         SaveAndLoadFile.Save(StoreGame.LoadString(StoreGame.EType.DEBUG_LOG));
     }
 }
        public static void Main(string[] args)
        {
            SaveAndLoadFile sl = new SaveAndLoadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.txt"));
            BookListService service = new BookListService(sl);

            Book existingBook = new Book("Блок Александр", "Ее песни", 116, "Минск-Пресс", 2014);
            Book bookForRemove = new Book("Салтыков-Щедрин Михаил", "Дикий помещик", 365, "Добрая книга", 2003);

            try
            {
                serviceBookLogger.Info("Start of block processing TYR in which adding books");
                service.AddBook(existingBook);
                serviceBookLogger.Info("End of block processing TYR in which adding books");
            }
            catch (AddBookException ex)
            {
                Console.WriteLine(ex.Message);
                serviceBookLogger.Info(ex.Message);
                serviceBookLogger.Error(ex.StackTrace);
            }
            
            try
            {
                serviceBookLogger.Info("Start of block processing TYR in which remove book");
                service.RemoveBook(bookForRemove);
                serviceBookLogger.Info("End of block processing TYR in which remove book");
            }
            catch (RemoveBookException ex)
            {
                Console.WriteLine(ex.Message);
                serviceBookLogger.Info(ex.Message);
                serviceBookLogger.Error(ex.StackTrace);
            }
            
            service.SortsBooksByTag(book => book.Title);
            serviceBookLogger.Info("Sorting internal list books by Title");
            DisplayBook(service.ListBooks);

            List<Book> resultFind = service.FindByTag(book => book.NumberOfPages == 189);
            serviceBookLogger.Info("Find list book where number of page = 189");
            DisplayBook(resultFind);
                
            Console.ReadKey();
        }