static void Main(string[] args)
        {
            List<Book> library = new List<Book>
            {
                new Book("Михаил Булгаков", "Мастер и Маргарита",  462, "Эксмо", 2006),
                new Book("Фёдор Достоевский", "Преступление и наказание",  630, "АСТ, Неоклассик", 2006),
                new Book("Михаил Лермонтов", "Герой нашего времени",  189, "АСТ, Неоклассик", 2008),
                new Book("Лев Толстой", "Анна Каренина",  706, "Издательский Дом Ридерз Дайджест", 2006),
            };

            BookListService service = new BookListService(library);
            DisplayBook(service.ListBooks);
           
            Book bookToAdd = new Book("Александр Пушкин", "Евгений Онегин", 203, "Питер", 2012);
            service.AddBook(bookToAdd);
            DisplayBook(service.ListBooks);
            
            service.RemoveBook(library[2]);
            DisplayBook(service.ListBooks);

            ComparerByNumberOfPages compareNumberOfPages = new ComparerByNumberOfPages();
            ComparerByPublisher comparePublisher = new ComparerByPublisher();
            ComparerByTitle comaperTitle = new ComparerByTitle();
            ComparerByYearIssued comaperYearIssued = new ComparerByYearIssued();

            service.SortsBooksByTag(comaperTitle);
            DisplayBook(service.ListBooks);

            IEnumerable<Book> resultBook = service.FindByTag(book => book.YearIssued == 2006);
            foreach (var item in resultBook)
                Console.WriteLine(item);

            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {

                logger.Trace("Начало работы программы");
                logger.Trace("Создание книг начато");
                Book a = new Book("Anna Korenina", "Tolstoy", 1878, "russian");
                Book b = new Book("Idiot", "Dostoevsky", 1868, "russian");
                Book c = new Book("Misery", "Stiven King", 1987, "english");
                Book d = new Book("It", "Stiven King", 1985, "english");
                logger.Trace("Создание книг завершено");
                BineryFileStorage data = new BineryFileStorage();
                BookListService dataService = new BookListService(data);
                logger.Trace("Добавление книг начато");
                dataService.AddBook(a);
                dataService.AddBook(b);
                dataService.AddBook(c);
                dataService.AddBook(d);
                logger.Trace("Добавление книг завершено");
                logger.Trace("Удаляется книга");
                dataService.RemoveBook(a);
                Show(data.Load());
                dataService.SortBooksByTag(BookListService.Tags.Year);
                Show(data.Load());
                Show(dataService.FindByTag(BookListService.Tags.Year, 1985));
            }
            catch (ArgumentException e)
            {
                logger.Error(e.ToString());
            }

            
        }
        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();
        }