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();
        }
Пример #2
0
        static void Main(string[] args)
        {
            var book3 = new Book("978-0743273565", "F. Scott Fitzgerald", "The Great Gatsby", "Scribner", 1925, 180, 9.92);
            var book2 = new Book("978-0060935467", "Harper Lee", "To Kill a Mockingbird", "Harper Perennial", 1960, 336, 7.19);
            var book1 = new Book("978-1451673319", "Ray Bradbury", "Fahrenheit 451", "Simon & Schuster", 1953, 249, 8.29);


            Console.WriteLine(book1.CompareTo(book3, Tags.ISBN.ToString()));
            Console.WriteLine(book1.CompareTo(book2));

            var usualListService = new BookListService();

            usualListService.AddBook(book1);
            usualListService.AddBook(book2);
            usualListService.AddBook(book3);
            usualListService.SortBooksByTag(Tags.Author);
            usualListService.ShowBooks();

            usualListService.FindBookByTag(Tags.Price, 8.29);


            var binaryStorage = new BinaryStorage(@"D:\BinaryStorage\binary.dat");

            binaryStorage.AddBook(book1);
            binaryStorage.AddBook(book2);
            binaryStorage.AddBook(book3);
            binaryStorage.SortBooksByTag(Tags.Title);
            binaryStorage.ShowBooks();

            Console.ReadLine();
        }
Пример #3
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 void WriteListBooksInFile(BookListService listBookForWrite)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            using (FileStream stream = File.Create(path))
            {
                formatter.Serialize(stream, listBookForWrite);
            }
        }
        public List<Book> ReadFromFileToListBooks()
        {
            BinaryFormatter formatter = new BinaryFormatter();
            using (FileStream stream = File.OpenRead(path))
            {
                bookList = (BookListService) formatter.Deserialize(stream);
            }

            return bookList.ListBooks;
        }
        public void WriteListBooksInFile(BookListService listBookForWrite)
        {
            XElement books = new XElement("books");
            foreach (var writeBook in listBookForWrite.ListBooks)
            {
                books.Add(new XElement("book", 
                    new XElement("Author", writeBook.Author),
                    new XElement("Title", writeBook.Title),
                    new XElement("Publisher", writeBook.Publisher),
                    new XElement("YearIssued", writeBook.YearIssued),
                    new XElement("NumberOfPages", writeBook.NumberOfPages)
                    ));
            }

            books.Save(path);
        }
        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();
        }
 public void WriteListBooksInFile(BookListService listBookForWrite)
 {
     XmlWriterSettings settings = new XmlWriterSettings {Indent = true};
     using (XmlWriter writer = XmlWriter.Create(path, settings))
     {
         writer.WriteStartElement("books");
         foreach (var book in listBookForWrite.ListBooks)
         {
             writer.WriteStartElement("book");
             writer.WriteElementString("Author", book.Author);
             writer.WriteElementString("Title", book.Title);
             writer.WriteElementString("Publisher", book.Publisher);
             writer.WriteElementString("YearIssued", book.YearIssued.ToString());
             writer.WriteElementString("NumberOfPages", book.NumberOfPages.ToString());
             writer.WriteEndElement();
         }
         writer.WriteEndElement();
     }
 }
Пример #9
0
        static void Main(string[] args)
        {
            List<Book> startList = new List<Book>
            {
                new Book("Лев Толстой", "Анна Каренина", 562, "Минск-Пресс", 2003),
                new Book("Александр Островский", "Снегурочка", 102, "Питер-Пресс", 2000),
                new Book("Сергей Есенин", "На поле Куликовом", 86, "Киев-Пресс", 2001),
                new Book("Лев Толстой", "Путь жизни", 368, "Минск-Пресс", 2000),
                new Book("Михаил Лермонтов", "Мцыри", 153, "Киев-Пресс", 2001),
                new Book("Николай Некрасов", "Русские женщины", 385, "Киев-Пресс", 2006),
            };
            
            #region Using Binary Serializer
            string pathBS = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "books.bin");
            RepositoryUsingBinarySerializer bs = new RepositoryUsingBinarySerializer(pathBS);
            BookListService bookServiceFirst = new BookListService(bs);
            bookServiceFirst.AddBook(startList);

            bookServiceFirst.SaveListBook();
            bookServiceFirst.LoadListBook();
            #endregion

            #region Using XML Writer
            string pathXML = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "books.xml");
            RepositoryUsingXmlWriter xws = new RepositoryUsingXmlWriter(pathXML);
            BookListService bookServiceSecond = new BookListService(xws);
            bookServiceSecond.AddBook(startList);

            bookServiceSecond.SaveListBook();
            bookServiceSecond.LoadListBook();
            #endregion
            
            #region Using Linq2XML
            string pathLinqXML = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "booksLinq.xml");
            RepositoryUsingLINQ2XML xlis = new RepositoryUsingLINQ2XML(pathLinqXML);
            BookListService bookServiceThird = new BookListService(xlis);
            bookServiceThird.AddBook(startList);

            bookServiceThird.SaveListBook();
            bookServiceThird.LoadListBook();
            #endregion
        }
Пример #10
0
        static void Main(string[] args)
        {
            BookListService service = new BookListService();

            service.AddBook(new Book("978-1-10-769989-2", "Dog in the hell", "Pushkin", 1997, "RR.C", 234, 333));
            service.AddBook(new Book("978-1-10-763989-2", "Dog in the sky", "Pushkin", 1999, "RR.C", 224, 536));
            service.AddBook(new Book("978-1-10-739989-2", "Black lake", "Losna", 2008, "RB.C", 238, 621));

            service.ShowList();
            service.SortBooksByTag(new NameComparer());
            Console.WriteLine();

            service.ShowList();
            service.DeleteBook("978-1-10-769989-2");
            Console.WriteLine();

            service.ShowList();
            Console.WriteLine();

            service.WriteToStorage(new BinaryStorage());
            List <Book> list = service.FindBookByTag(new TitleTag("Black lake"));

            foreach (Book b in list)
            {
                Console.WriteLine(b);
            }

            Console.WriteLine();

            BookListService service1 = new BookListService();

            service1.LoadFromStorage(new BinaryStorage());
            service1.ShowList();

            Console.Read();
        }