Esempio n. 1
0
        static void Main(string[] args)
        {
            LibraryClient libraryClient = new LibraryClient();

            Book book = libraryClient.BookInfo(1);

            Console.WriteLine("BookId: " + book.Id + ", Title: " + book.Title);

            int userId = 1;

            for (int i = 0; i < 2; i++)
            {
                if (libraryClient.BorrowBook(1, userId))
                {
                    Console.WriteLine("Book has been borrowed.");
                }
                else
                {
                    Console.WriteLine("Book is not available!");
                }
            }

            BorrowedItem[] borrowedItems = libraryClient.ListOfBorrowedItems();
            Console.WriteLine("Borrowed items:");
            foreach (BorrowedItem item in borrowedItems)
            {
                Console.WriteLine("Borrowed by: " + item.UserId + ", Book Id:" + item.Book.Id + ", Title: " + item.Book.Title + ", borrow date: " + item.BorrowDate + ", retun date: " + item.ReturnDate);
            }

            Console.WriteLine("Borrowed books by userID = " + userId);

            foreach (Book b in libraryClient.GetBorrowedBooks(userId))
            {
                Console.WriteLine("Title: " + b.Title + ", Id: " + b.Id);
            }

            try {
                libraryClient.BookInfo(11);
            } catch (FaultException <NoSuchBookException> ex)
            {
                Console.WriteLine(ex.Detail.Message);
            }

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            var klient1 = new LibraryClient("endpoint");

            Console.WriteLine("... wywoluje FindByISBN(...)");
            var result1 = klient1.FindByISBN(123);

            Console.WriteLine("{0} {1}", result1.title, result1.author);

            Console.WriteLine("... wywoluje FindByISBN(...) dla nieistniejcej ksiazki");
            try
            {
                klient1.FindByISBN(9999);
            } catch (FaultException <Contract.BookFault> faultEx)
            {
                Console.WriteLine(faultEx.Detail.ISBN);
                Console.WriteLine(faultEx.Detail.message);
            }

            Console.WriteLine("... wywoluje CurrentValueOfAllBooks(...)");
            var result2 = klient1.GetCurrentValueOffBooks();

            Console.WriteLine(result2);


            //-----------------------------------------------
            var handler         = new CallbackHandler();
            var instanceContext = new InstanceContext(handler);
            var klientCB        = new CallbackBooksClient(instanceContext);

            Console.WriteLine("... wywoluje GetAllBooks(...)");
            klientCB.GetAllBooks(); // TODO: Async?

            Console.WriteLine("... wywoluje Info(...)");
            klientCB.Info();


            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            try
            {
                var guest = new LibraryClient();
                Console.WriteLine("All books that are present in the Library:");
                foreach (Book book in guest.GetAllBooks())
                {
                    Console.WriteLine("-) Title: {0}", book._title);
                    if (book._dude.SingleAuthor)
                    {
                        Console.WriteLine("-) Author: {0} {1}", book._dude._name, book._dude._surname);
                    }
                    else
                    {
                        Console.Write("-) Authors:");
                        foreach (Author author in book._dude._authors)
                        {
                            Console.Write(" {0} {1};", author._name, author._surname);
                        }
                        Console.Write("\n");
                    }
                    Console.WriteLine("-) Signature: {0}", book._signature);
                    Console.WriteLine("-) Release date: {0}", book._year);
                    Console.WriteLine("-) Availability: {0}", !book.IsRented);
                    Console.WriteLine();
                }
                Console.ReadLine();

                Console.WriteLine("***********TESTS***********");
                Console.WriteLine(">>>Renting books.");

                //EXCEPTION 1

                try
                {
                    guest.RentBook(0);
                    guest.RentBook(0);
                    guest.RentBook(2);
                }
                catch (FaultException <BookIsAlreadyRentedFault> e)
                {
                    Console.WriteLine("////////////////////////////////////////////////////////////////");
                    Console.WriteLine("              This book is already rented!");
                    Console.WriteLine("////////////////////////////////////////////////////////////////");
                }
                Console.WriteLine("Books rented:");
                foreach (Book book in guest.GetAllRentedBooks())
                {
                    Console.WriteLine("-) Title: {0}", book._title);
                    if (book._dude.SingleAuthor)
                    {
                        Console.WriteLine("-) Author: {0} {1}", book._dude._name, book._dude._surname);
                    }
                    else
                    {
                        Console.Write("-) Authors:");
                        foreach (Author author in book._dude._authors)
                        {
                            Console.Write(" {0} {1};", author._name, author._surname);
                        }
                        Console.Write("\n");
                    }
                    Console.WriteLine("-) Signature: {0}", book._signature);
                    Console.WriteLine("-) Release date: {0}", book._year);
                    Console.WriteLine();
                }



                Console.ReadLine();
                Console.WriteLine(">>>Searching a book by title part");

                //EXCEPTION 2

                try
                {
                    foreach (Book book in guest.GetAllBooksWithTitleLike("FutureTEXTTHATISNOTINANYBOOKS"))
                    {
                        Console.WriteLine("-) Title: {0}", book._title);
                        if (book._dude.SingleAuthor)
                        {
                            Console.WriteLine("-) Author: {0} {1}", book._dude._name, book._dude._surname);
                        }
                        else
                        {
                            Console.Write("-) Authors:");
                            foreach (Author author in book._dude._authors)
                            {
                                Console.Write(" {0} {1};", author._name, author._surname);
                            }
                            Console.Write("\n");
                        }
                        Console.WriteLine("-) Signature: {0}", book._signature);
                        Console.WriteLine("-) Release date: {0}", book._year);
                        Console.WriteLine();
                    }
                }
                catch (FaultException <NoSuchBooksFault> e)
                {
                    Console.WriteLine("////////////////////////////////////////////////////////////////");
                    Console.WriteLine("              There are no such books!");
                    Console.WriteLine("////////////////////////////////////////////////////////////////");
                }



                Console.ReadLine();
                Console.WriteLine(">>>Returning books");
                foreach (Book book in guest.GetAllBooks())
                {
                    Console.WriteLine("-) Title: {0}", book._title);
                    if (book._dude.SingleAuthor)
                    {
                        Console.WriteLine("-) Author: {0} {1}", book._dude._name, book._dude._surname);
                    }
                    else
                    {
                        Console.Write("-) Authors:");
                        foreach (Author author in book._dude._authors)
                        {
                            Console.Write(" {0} {1};", author._name, author._surname);
                        }
                        Console.Write("\n");
                    }
                    Console.WriteLine("-) Signature: {0}", book._signature);
                    Console.WriteLine("-) Release date: {0}", book._year);
                    Console.WriteLine("-) Availability: {0}", !book.IsRented);
                    Console.WriteLine();
                }
                Console.WriteLine("Returning books 0 and 2...");
                guest.ReturnBook(0); guest.ReturnBook(2);
                Console.WriteLine("DONE!");
                foreach (Book book in guest.GetAllBooks())
                {
                    Console.WriteLine("-) Title: {0}", book._title);
                    if (book._dude.SingleAuthor)
                    {
                        Console.WriteLine("-) Author: {0} {1}", book._dude._name, book._dude._surname);
                    }
                    else
                    {
                        Console.Write("-) Authors:");
                        foreach (Author author in book._dude._authors)
                        {
                            Console.Write(" {0} {1};", author._name, author._surname);
                        }
                        Console.Write("\n");
                    }
                    Console.WriteLine("-) Signature: {0}", book._signature);
                    Console.WriteLine("-) Release date: {0}", book._year);
                    Console.WriteLine("-) Availability: {0}", !book.IsRented);
                    Console.WriteLine();
                }

                Console.ReadLine();
            }
            //TODO: hadnle communication
            catch (ObjectDisposedException e)
            {
                Console.WriteLine("ObjectDisposedException error");
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("CommunicationException error");
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception error");
            }
        }