static void Main(string[] args) { Logger logger = LogManager.GetCurrentClassLogger(); BookListService.BookListService bookListService = new BookListService.BookListService(); Book[] books = new Book[5]; books[0] = new Book("Albahari", "C# in a nutshell", 2012, 1043); books[1] = new Book("Richter", "CLR via C#", 2013, 896); books[2] = new Book("Eckel", "Thinking in Java", 2009, 637); books[3] = new Book("Lorem", "Ipsum", 2005, 1024); books[4] = new Book("Dolor", "Sit Amet", 2015, 512); for (int i = 0; i < books.Length; i++) { bookListService.AddBook(books[i]); logger.Info($"Book '{books[i].Title}' has been successfully added to the collection"); } try { bookListService.AddBook(books[0]); } catch (ArgumentException exception) { logger.Error(exception.Message); } BinaryBookStorage binaryBookStorage = new BinaryBookStorage("books.dat"); bookListService.SaveCollectionToStorage(binaryBookStorage); logger.Info("Collection has been successfully saved in the storage"); var anotherBookListService = new BookListService.BookListService(); anotherBookListService.ReadCollectionFromStorage(binaryBookStorage); logger.Info("Collection has been successfully loaded from the storage"); foreach (BookListService.BookListService.BookTag tag in Enum.GetValues(typeof(BookListService.BookListService.BookTag))) { logger.Info($"Sorting by tag {tag}"); anotherBookListService.SortByTag(tag); foreach (Book book in anotherBookListService.ToList()) { logger.Info(book); } } Book bookToRemove = anotherBookListService.FindBookByTag("Ipsum", BookListService.BookListService.BookTag.Title); anotherBookListService.RemoveBook(bookToRemove); try { anotherBookListService.RemoveBook(bookToRemove); } catch (ArgumentException exception) { logger.Error(exception.Message); } Console.ReadKey(); }
static void Main(string[] args) { BookListService.BookListService bookListService=new BookListService.BookListService(); Book[] books=new Book[5]; books[0] = new Book("Albahari", "C# in a nutshell", 2012, 1043); books[1] = new Book("Richter", "CLR via C#", 2013, 896); books[2] = new Book("Eckel", "Thinking in Java", 2009, 637); books[3] = new Book("Lorem", "Ipsum", 2005, 1024); books[4] = new Book("Dolor", "Sit Amet", 2015, 512); for (int i = 0; i < books.Length; i++) { bookListService.AddBook(books[i]); Console.WriteLine($"Book '{books[i].Title}' has been successfully added to the collection"); } Console.WriteLine(); try { bookListService.AddBook(books[0]); } catch (ArgumentException exception) { Console.WriteLine(exception.Message); } Console.WriteLine(); BinaryBookStorage binaryBookStorage=new BinaryBookStorage("books.dat"); bookListService.SaveCollectionToStorage(binaryBookStorage); Console.WriteLine("Collection has been successfully saved in the storage"); var anotherBookListService =new BookListService.BookListService(); anotherBookListService.ReadCollectionFromStorage(binaryBookStorage); Console.WriteLine("Collection has been successfully loaded from the storage"); foreach (BookListService.BookListService.BookTag tag in Enum.GetValues(typeof(BookListService.BookListService.BookTag))) { Console.WriteLine($"Sorting by tag {tag}"); anotherBookListService.SortByTag(tag); foreach (Book book in anotherBookListService.ToList()) { Console.WriteLine(book); } Console.WriteLine(); } Book bookToRemove = anotherBookListService.FindBookByTag("Ipsum", BookListService.BookListService.BookTag.Title); anotherBookListService.RemoveBook(bookToRemove); try { anotherBookListService.RemoveBook(bookToRemove); } catch (ArgumentException exception) { Console.WriteLine(exception.Message); } Console.ReadKey(); }
public void Filter(Predicate <Book> predicate, IBookRepository nRepository) { var books = repository.LoadBooks(); var bookList = new BookListService(nRepository); foreach (Book book in books) { if (predicate(book)) { bookList.AddBook(book); } } }
static void Main(string[] args) { BookListStorage bookListStorage = new BookListStorage("C:\\Users\\Yana_Petrochenko\\Documents\\Visual Studio 2015\\Projects\\NET.W.2016.01.petrochenko.12\\BookListService\\file.txt"); //List<Book> list = bookListStorage.LoadBooks(); BookListService bookListService = new BookListService(); bookListService.AddBook(new Book(123102, "Picture of Dorian Grey", "Oskar Wild", 300, 1890, 1000000)); bookListService.AddBook(new Book(12354, "Angelika", "Ann and Serge Gollon", 550, 1917, 1000000)); bookListService.AddBook(new Book(12349, "Gone with the wind", "Margaret Mitchell", 2000, 1936, 1000000)); bookListService.AddBook(new Book(12356, "Farengate 451", "Ray Bradbury", 2000, 1950, 1000000)); //bookListService.RemoveBook(new Book(12346, "Angelika", "Ann and Serge Gollon", 550, 1917, 1000000)); //bookListService.FindBookByIsbn(12346);//exception bookListService.SortBookByIsbn(); Console.ReadKey(); }