Beispiel #1
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();
        }
Beispiel #2
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();
 }