static void Main(string[] args)
 {
     try
     {
         log = LogManager.GetCurrentClassLogger();
         BookListService bls = new BookListService();
         log.Debug("Старт записи в двоичный файл");
             WriteDefaultValues(fileName);
         log.Debug("Окончание записи в двоичный файл");
         log.Debug("Старт чтения данных из двоичног файла");
         bls = ReadDefaultValues(fileName);
         log.Debug("Окончание чтения данных из двоичног файла");
         Book[] find = bls.FindByTag("1999", EnumTag.Year); //Поиск
         foreach (Book b in find)
         Console.WriteLine(b);
         Console.WriteLine("-------------------------");
         Book[] sort = bls.SortBooksByTag(EnumTag.Page);//Сортировка
         foreach (Book b in sort)
             Console.WriteLine(b);
         //log.Warn("Попытка добавить уже существующую книгу");
         //bls.AddBook(sort[0]); 
         bls.RemoveBook(sort[0]);//Удаление книги
         log.Warn("Попытка удаления книги отсутствующей в каталоге");
         bls.RemoveBook(sort[0]);
     }
     catch (Exception e)
     {
         log.Error(e.Message);
     }
     
 }
        private static void WriteDefaultValues(string fileName)
        {
            Book first = new Book("Author1", "Title1", "Pub1", 1990, 200);
            Book second = new Book("Author2", "Title2", "Pub1", 1999, 250);
            Book third = new Book("Author3", "Title3", "Pub1", 1998, 205);
            BookListService bls = new BookListService();
            bls.AddBook(first);
            bls.AddBook(second);
            bls.AddBook(third);
            
            FileStream fs = new FileStream(fileName, FileMode.Create);

            BinaryFormatter formatter = new BinaryFormatter();
            try
            {
                formatter.Serialize(fs, bls);                

            }
            catch (SerializationException e)
            {
                log.Error("Failed to serialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            string path = @"BooksList.dat";

            BookListService books = new BookListService(path);
            ShowBooksList(books, "Спосок книг");

            /*
             * bl.AddBook(new Book() { Author = "Лев Толстой", Title = "Война и мир", Genre = "Роман", Year = 1869 });
             * bl.AddBook(new Book() { Author = "Алан Александр Милн",Title ="Вини-Пух", Genre = "Детский рассказ", Year = 1926});
             * bl.AddBook(new Book() { Author = "Мари Шелли", Title="Франкенштейн", Genre = "Научная фантастика", Year = 1818}); 
             * bl.AddBook(new Book() { Author = "Михаил Булгаков", Title ="Мастер и Маргарита", Genre="Роман", Year = 1966});
             * bl.AddBook(new Book() { Author = "Федор Достоевский", Title = "Преступление и наказание" , Genre = "Роман" , Year = 1866});
             * bl.AddBook(new Book() { Author = "Николай Гоголь", Title = "Мёртвые души", Genre = "Сатира", Year = 1842 });
             * bl.AddBook(new Book() { Author = "Александр Пушкин", Title = "Евгений Онегин", Genre = "Роман", Year = 1825 });
             */

            books.SortBooksByTag( new ComparableBook());
            ShowBooksList(books, "Отсортированный список");

            books.AddBook(new Book() { Author = "Николай Гоголь", Title = "Вечера на хуторе близ Диканьки", Year = 1832, Genre = "Проза"});
            ShowBooksList(books, "Список книг с добавленной книгой");

            books.RemoveBook(new Book() { Author = "Николай Гоголь", Title = "Вечера на хуторе близ Диканьки", Year = 1832, Genre = "Проза" });
            ShowBooksList(books, "Список книг с удаленной книгой");

            Console.WriteLine("Спосок книг выбранны по тегу \"Жанр = Роман\"");
            foreach(Book b in books.FindByTag(new TagGanre(), "Роман"))
                Console.WriteLine(b);
        }
示例#4
0
        private static void ShowBooksList(BookListService books, string massege)
        {
            Console.WriteLine(massege);
            foreach (Book b in books)
                Console.WriteLine(b);

            Console.WriteLine();
        }
示例#5
0
        static void Main(string[] args)
        {
            #region Writing To Binary Repository/ Reading From It
            List<Book> booksList = new List<Book>()
            {
                new Book(){Author = "Mark Twen", Title = "Oliver Twist",
                    Year = 1935, Publisher = "WilliamsPublish.", PagesQuantity = 350},
                new Book(){Author = "Andew Tanenbaum", Title = "Computer Networks",
                    Year = 2010, Publisher = "ClassicOfComputerScience.", PagesQuantity = 750},
                new Book(){Author = "Gang Of Fours", Title = "Design Patterns",
                    Year = 1995, Publisher = "O'Realy.", PagesQuantity = 520}
            };
            BinaryFileRepository repository = new BinaryFileRepository("BinFile.dat");
            BookListService bookListService = new BookListService(repository);
            bookListService.DeleteBooks();
            foreach (Book member in booksList)
            {
                bookListService.AddBook(member);
            }
            PrintBookList(bookListService.GetBooks());
            #endregion

            #region Write To Xml/ Read From Xml By XmlManager
            string fileName = @"C:\BookCollection.xml";
            XmlManager xManager = new XmlManager(fileName);
            xManager.Export(booksList);
            PrintBookList(xManager.Import());
            #endregion

            #region Export In Xml By BookListService
            bookListService.ExportInXml(new XmlManager(@"C:\BooksCollection(Service).xml"));
            #endregion

            #region Binary Serializer Repository
            string binFileName = @"C:\BooksCollection.bin";
            BinarySerializerRepository serializerRepository = new BinarySerializerRepository(binFileName);
            serializerRepository.SaveBooks(booksList);
            PrintBookList(serializerRepository.LoadBooks());
            #endregion

            #region Filtering Books And Saving In Other Repository
            BinarySerializerRepository anotherBinRep = new BinarySerializerRepository(@"C:\MarkTwenBooks.bin");
            bookListService.FilterBooks(anotherBinRep, book => book.Author == "Mark Twen");
            PrintBookList(anotherBinRep.LoadBooks());
            #endregion

            Console.ReadKey();
        }
        public static BookListService ReadDefaultValues(string fileName)
        {
            BookListService bls = new BookListService();
            FileStream fs = new FileStream(fileName, FileMode.Open);
        try 
        {
            BinaryFormatter formatter = new BinaryFormatter();
            bls = (BookListService)formatter.Deserialize(fs);
            return bls;
        }
        catch (SerializationException e) 
        {
            log.Error("Failed to deserialize. Reason: " + e.Message);
            throw;
        }
        finally 
        {
            fs.Close();
        }

        }
示例#7
0
 static void Main(string[] args)
 {
     List<Book> booksList = new List<Book>()
     {
         new Book(){Author = "Mark Twen", Title = "Oliver Twist",
             Year = 1935, Publisher = "WilliamsPublish.", PagesQuantity = 350},
         new Book(){Author = "Andew Tanenbaum", Title = "Computer Networks",
             Year = 2010, Publisher = "ClassicOfComputerScience.", PagesQuantity = 750},
         new Book(){Author = "Gang Of Fours", Title = "Design Patterns",
             Year = 1995, Publisher = "O'Realy.", PagesQuantity = 520}
     };
     BinaryFileRepository repository = new BinaryFileRepository("BinFile.dat");
     BookListService bookListService = new BookListService(repository);
     bookListService.DeleteBooks();
     foreach (Book member in booksList)
     {
         bookListService.AddBook(member);
     }
     PrintBookList(bookListService.GetBooks());
     Console.ReadKey();
 }
 static void Main(string[] args)
 {
     try
     {
         BinBookRepozitory rep = new BinBookRepozitory(fileName);
         SaveDefaultValues();
         BookListService bls = new BookListService(rep);             
         Book[] find = bls.FindByTag("1999", EnumTag.Year); 
         foreach (Book b in find)
         Console.WriteLine(b);
         Console.WriteLine("-------------------------");
         Book[] sort = bls.SortBooksByTag(EnumTag.Page);
         foreach (Book b in sort)
             Console.WriteLine(b);
         //bls.AddBook(sort[0]); 
         bls.RemoveBook(sort[0]);
         bls.RemoveBook(sort[0]);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     
 }