static void Main(string[] args) { var temp = new Book("one", "One"); var first = new Book("Роулинг Джоанн", "Гарри Поттер и философский камень", "Фантастика", "РОСМЭН-Издат", 300); var seventh = new Book("J.K.Rouling", "Harry Potter and the deathly Hallows"); var bookList = new BookListService(); bookList.AddBook(first); bookList.AddBook(seventh); bookList.AddBook(temp); try { bookList.AddBook(null); } catch (ArgumentNullException) { } try { bookList.AddBook(new Book("one", "One")); } catch (ArgumentException) { } try { bookList.RemoveBook(null); } catch (ArgumentNullException) { } try { bookList.RemoveBook(new Book("two", "Two")); } catch (ArgumentException) { } Console.WriteLine("BookListService"); var brw = new BinaryReaderWriter("books_new.bin"); bookList.SaveBooks(brw); bookList.PrintBooks(); Console.WriteLine(); bookList.SortBooksByAuthor(); bookList.PrintBooks(); Console.WriteLine(); bookList.SortBooksByTitle(); bookList.PrintBooks(); Console.WriteLine(); var newList = new BookListService(); newList.LoadBooks(brw); newList.PrintBooks(); Console.ReadLine(); }
static void Main(string[] args) { var bookService = new BookListService(new FileBookRepository("default")); bookService.AddBook(new Book("J. Richter", "C# via", 500.0, 800)); bookService.AddBook(new Book("D. Samal", "Sifo VMSIS", 350.0, 85)); bookService.AddBook(new Book("A. Pushkin", "E.Onegin", 110.0, 150)); bookService.AddBook(new Book("L. Tolstoi", "Voina i mir", 650.0, 1000)); bookService.AddBook(new Book("S. Perro", "Kot v sapogah", 60.0, 50)); foreach (var book in bookService.BookList) Console.WriteLine($"{book}"); bookService.DeleteBook(new Book("L. Tolstoi", "Voina i mir", 650.0, 1000)); bookService.DeleteBook(new Book("S. Perro", "Kot v sapogah", 60.0, 50)); Console.WriteLine("------------------------------------------"); foreach (var book in bookService.BookList) Console.WriteLine($"{book}"); Console.WriteLine("------------------------------------------"); bookService.Sort(new BookComparer()); foreach (var book in bookService.BookList) Console.WriteLine($"{book}"); Console.WriteLine("------------------------------------------"); var selectedBooksByTag = bookService.FindBooksByTags(b => b.Author.Contains('S'.ToString())); foreach (var book in selectedBooksByTag) Console.WriteLine($"{book}"); bookService.Repository.Save(bookService.BookList); Console.ReadKey(); }
static void Main(string[] args) { BookListService bl = new BookListService("booklist.txt"); bl.AddBook(new Book("Braun","Inferno",500,"Scince. Adventure")); bl.AddBook(new Book("Zamyatin","We",100,"Dystopia")); bl.AddBook(new Book("Tolkien", "The Lord Of The Rings", 1000, "Fantasy")); System.Console.WriteLine(bl.ToString()); //bl.AddBook(new Book("Zamyatin", "Hronic", 134, "Fantasy")); System.Console.WriteLine("__________________"); bl.SortBooksByTag(); System.Console.WriteLine(bl.ToString()); Book bok = bl.FindBookByTag(x => x.PagesAmount == 100); System.Console.WriteLine(bok.ToString()); System.Console.ReadLine(); }
private static void SaveService(IRepository serializator) { BookListService service = new BookListService(); service.AddBook(new Book("fAuthor1", "Title1", "Text1", 1)); service.AddBook(new Book("eAuthor2", "Title2", "Text2", 2)); service.AddBook(new Book("aAuthor3", "Title3", "Text3", 3)); service.AddBook(new Book("cAuthor4", "Title4", "Text4", 4)); service.AddBook(new Book("bAuthor5", "Title5", "Text5", 5)); service.AddBook(new Book("dAuthor6", "Title6", "Text6", 6)); Console.WriteLine("---------- Old Service ----------"); Console.WriteLine(service.PrintBooks()); service.Sort((b1, b2) => b1.Author.CompareTo(b2.Author)); Console.WriteLine("FindByAuthor: " + service.FindBy(author:"aAuthor3").Print()); Console.WriteLine("FindByTitle: " + service.FindBy(title:"Title1").Print()); Console.WriteLine(service.RemoveBook(service.FindBy(author:"fAuthor1"))); try { service.AddBook(null); } catch (Exception) { } try { service.AddBook(new Book("dAuthor6", "Title6", "Text6", 6)); } catch (Exception) { } try { service.RemoveBook(null); } catch (Exception) { } try { service.RemoveBook(new Book("dAuthor", "Title6", "Text6", 6)); } catch (Exception) { } try { service.FindBy(author: null).Print(); } catch (Exception) { } try { service.FindBy(title: "").Print(); } catch (Exception) { } try { try { service.Save("test.bin", serializator); } catch (Exception) { } } catch (ArgumentException e) { Console.WriteLine("Wrong argument error with message: {0}", e.Message); } }