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)
        {
            //var path = "Books.txt";
            var path1 = "Book.XML";
            //IRepository<Book> rep = new BookRepository(path);
            IRepository<Book> rep1 = new WorkWithXml(path1);
            var bookService = new BookListService(rep1);
            Book book = new Book("3qw", "23", "fantasy", 1);
            bookService.Add(book);
            //bookService.Delete(book);
            var books = bookService.Sort(x => x.Publication);
            foreach (var b in books)
            {
                Console.Write("{0}\t", b.Author);
                Console.Write("{0}\t", b.Title);
                Console.Write("{0}\t", b.Genre);
                Console.Write("{0}\t", b.Publication);
                Console.WriteLine();
            }
            /*
            Console.WriteLine();
            var _books = bookService.SearchBooks(x => x.Author == "qqq");
            foreach (var b in _books)
            {
                Console.Write("{0}\t", b.Author);
                Console.Write("{0}\t", b.Title);
                Console.Write("{0}\t", b.Genre);
                Console.Write("{0}\t", b.Publication);
                Console.WriteLine();
            }

            Console.WriteLine();
            var find = bookService.Search(x => x.Author == "qqq");
            Console.Write("{0}\t{1}\t{2}\t{3}", find.Author, find.Title, find.Genre, find.Publication);
            Console.ReadKey();
            foreach (var b in books)
            {
                Console.Write("{0}\t", b.Author);
                Console.Write("{0}\t", b.Title);
                Console.Write("{0}\t", b.Genre);
                Console.Write("{0}\t", b.Publication);
                Console.WriteLine();
            }*/

            Console.ReadKey();
        }
Ejemplo n.º 3
0
        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); }
        }