コード例 #1
0
    // Precondition:  None
    // Postcondition: The LibraryBook and LibaryPatron classes have been tested
    public static void Main(string[] args)
    {
        LibraryBook book1 = new LibraryBook("First Book", "Brick Green", "UofL Press",
            2010, "ZZ25 3G");  // 1st test book
        LibraryBook book2 = new LibraryBook("Second Book", "Lee Cole", "Stealer Books",
            2000, "AG773 ZF"); // 2nd test book
        LibraryBook book3 = new LibraryBook("White Fang", "Jack London", "Unsure Books Ltd.",
            1985, "JJ438 4T"); // 3rd test book
        LibraryBook book4 = new LibraryBook("The Old Man and the Sea", "Ernest Hemingway", "Charles Schribner Sons",
            -1, "ZZ24 4F");    // 5th test book
        LibraryBook book5 = new LibraryBook("The Big Book of Doughnuts", "Homer Simpson", "Doh Books",
            2001, "AE842 7A"); // 4th test book

        LibraryPatron patron1 = new LibraryPatron("Ima Reader", "12345"); // 1st test patron
        LibraryPatron patron2 = new LibraryPatron("Jane Doe", "112233");  // 2nd test patron
        LibraryPatron patron3 = new LibraryPatron("John Smith", "54321"); // 3rd test patron

        List<LibraryBook> theBooks = new List<LibraryBook>(); // Test list of books

        // Add books to the list
        theBooks.Add(book1);
        theBooks.Add(book2);
        theBooks.Add(book3);
        theBooks.Add(book4);
        theBooks.Add(book5);

        Console.WriteLine("Original list of books");
        PrintBooks(theBooks);

        // Make changes
        book1.CheckOut(patron1);
        book2.Publisher = "Borrowed Books";
        book3.CheckOut(patron2);
        book4.CallNumber = "AB123 4A";
        book5.CheckOut(patron3);

        Console.WriteLine("After changes");
        PrintBooks(theBooks);

        // Return all the books
        for (int i = 0; i < theBooks.Count; ++i)
            theBooks[i].ReturnToShelf();

        Console.WriteLine("After returning the books");
        PrintBooks(theBooks);
    }
コード例 #2
0
        private async Task <string> downloadBookAsync(LibraryBook libraryBook, string tempAaxFilename)
        {
            validate(libraryBook);

            var api = await GetApiAsync(libraryBook);

            var actualFilePath = await PerformDownloadAsync(
                tempAaxFilename,
                (p) => api.DownloadAaxWorkaroundAsync(libraryBook.Book.AudibleProductId, tempAaxFilename, p));

            System.Threading.Thread.Sleep(100);
            // if bad file download, a 0-33 byte file will be created
            // if service unavailable, a 52 byte string will be saved as file
            var length = new FileInfo(actualFilePath).Length;

            if (length > 100)
            {
                return(actualFilePath);
            }

            var contents = File.ReadAllText(actualFilePath);

            File.Delete(actualFilePath);

            var exMsg = contents.StartsWithInsensitive(SERVICE_UNAVAILABLE)
                                ? SERVICE_UNAVAILABLE
                                : "Error downloading file";

            var ex = new Exception(exMsg);

            Serilog.Log.Logger.Error(ex, "Download error {@DebugInfo}", new
            {
                libraryBook.Book.Title,
                libraryBook.Book.AudibleProductId,
                libraryBook.Book.Locale,
                libraryBook.Account,
                tempAaxFilename,
                actualFilePath,
                length,
                contents
            });
            throw ex;
        }
コード例 #3
0
ファイル: AudioDecodeForm.cs プロジェクト: rmcrackan/Libation
        public override void Processable_Begin(object sender, LibraryBook libraryBook)
        {
            base.Processable_Begin(sender, libraryBook);

            GetCoverArtDelegate = () => PictureStorage.GetPictureSynchronously(
                new PictureDefinition(
                    libraryBook.Book.PictureId,
                    PictureSize._500x500));

            //Set default values from library
            AudioDecodable_TitleDiscovered(sender, libraryBook.Book.Title);
            AudioDecodable_AuthorsDiscovered(sender, string.Join(", ", libraryBook.Book.Authors));
            AudioDecodable_NarratorsDiscovered(sender, string.Join(", ", libraryBook.Book.NarratorNames));
            AudioDecodable_CoverImageDiscovered(sender,
                                                PictureStorage.GetPicture(
                                                    new PictureDefinition(
                                                        libraryBook.Book.PictureId,
                                                        PictureSize._80x80)).bytes);
        }
コード例 #4
0
        public async Task Put(int libraryId, [FromBody] BookTitle book)
        {
            var lb = db.LibraryBook.FirstOrDefault(o => o.BookId == book.BookId && o.LibraryId == libraryId);

            if (lb == null)
            {
                db.LibraryBook.Remove(lb);
            }

            var newLibraryBook = new LibraryBook
            {
                Book      = book,
                LibraryId = libraryId
            };

            db.LibraryBook.Add(newLibraryBook);

            await db.SaveChangesAsync();
        }
コード例 #5
0
ファイル: DownloadPdf.cs プロジェクト: Mulchman/Libation
        private static string getProposedDownloadFilePath(LibraryBook libraryBook)
        {
            // if audio file exists, get it's dir. else return base Book dir
            var existingPath = Path.GetDirectoryName(AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId));
            var file         = getdownloadUrl(libraryBook);

            if (existingPath != null)
            {
                return(Path.Combine(existingPath, Path.GetFileName(file)));
            }

            var full = FileUtility.GetValidFilename(
                AudibleFileStorage.PDF.StorageDirectory,
                libraryBook.Book.Title,
                Path.GetExtension(file),
                libraryBook.Book.AudibleProductId);

            return(full);
        }
コード例 #6
0
        /// <summary>
        /// Static <c>Map</c> method maps a <see cref="Core.Model.LibraryBook"/> class to a 
        /// <see cref="THLibrary.DataModel.BookViewModel"/> class.
        /// </summary>
        /// <param name="book">The LibraryBook instance.</param>
        /// <returns>The BookViewModel instance.</returns>
        public static BookViewModel Map(LibraryBook book)
        {
            //  Instantiate directly as this is only even used within this UI.
            //  TODO: (If Time) refactor this to an abstract factory to create the BookViewModel
            var bookVM = new BookViewModel()
            {
                Author = book.Author,
                Title = book.Title,
                ISBN = book.ISBN,
                Keywords = new ObservableCollection<string>(book.KeyWords),
                Synopsis = book.Synopsis
            };
            if (book.ImagePath==string.Empty)
                bookVM.SetImage("Assets/Logo.png");     //  TODO: update to correct image file, default for now.
            else
                bookVM.SetImage(string.Format("Assets/{0}", book.ImagePath));

            return bookVM;
        }
コード例 #7
0
        public IActionResult MyLibrary()
        {
            //find current user
            User currentUser = CurrentUser();

            //Find all books where the owner is the current user and the book is active
            List <Book> dbPersonalLibrary = _libraryDB.Books.Where(x => x.BookOwner == currentUser.Id && x.IsActive == true).ToList();

            List <LibraryBook> libraryBooks = new List <LibraryBook>();

            foreach (Book book in dbPersonalLibrary)
            {
                //let's get their info about that book in the api
                BookInfo apiBook = _libraryDAL.GetBookInfo(book.TitleIdApi);
                //let's get the author info
                List <Author> authors = new List <Author>();
                if (apiBook.authors is not null)
                {
                    foreach (Author author in apiBook.authors)
                    {
                        string authorId  = author.author.key;
                        Author apiAuthor = _libraryDAL.GetAuthorInfo(authorId);

                        authors.Add(apiAuthor);
                    }
                    apiBook.authors = authors;
                }
                LibraryBook libraryBook = new LibraryBook();

                User bookHolder = _libraryDB.Users.First(x => x.Id == book.CurrentHolder);
                User bookOwner  = _libraryDB.Users.First(x => x.Id == book.BookOwner);

                libraryBook.ApiBook    = apiBook;
                libraryBook.DbBook     = book;
                libraryBook.BookOwner  = bookOwner.UserName;
                libraryBook.BookHolder = bookHolder.UserName;
                libraryBooks.Add(libraryBook);
            }


            return(View(libraryBooks));
        }
コード例 #8
0
    // Precondition:  None
    // Postcondition: The LibraryBook class has been tested
    public static void Main(string[] args)
    {
        LibraryBook book1 = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press",
                                            2010, "ZZ25 3G");           // 1st test book
        LibraryBook book2 = new LibraryBook("Harriet Pooter", "IP Thief", "Stealer Books",
                                            2000, "AG773 ZF");          // 2nd test book
        LibraryBook book3 = new LibraryBook("The Color Mauve", "Mary Smith", "Beautiful Books Ltd.",
                                            1985, "JJ438 4T");          // 3rd test book
        LibraryBook book4 = new LibraryBook("The Guan Guide to SQL", "Jeff Guan", "UofL Press",
                                            2016, "ZZ24 4F");           // 4th test book
        LibraryBook book5 = new LibraryBook("The Big Book of Doughnuts", "Homer Simpson", "Doh Books",
                                            2001, "AE842 7A");          // 5th test book

        LibraryBook[] theBooks = { book1, book2, book3, book4, book5 }; // Test array of books

        WriteLine("Original list of books");
        WriteLine("----------------------");
        PrintBooks(theBooks);
        Pause();

        // Make changes
        book1.CheckOut();
        book2.Publisher = "Borrowed Books";
        book3.CheckOut();
        book4.CallNumber = "AB123 4A";
        book5.CheckOut();
        book5.CopyrightYear = -1234; // Attempt invalid year

        WriteLine("After changes");
        WriteLine("-------------");
        PrintBooks(theBooks);
        Pause();

        // Return the books
        book1.ReturnToShelf();
        book3.ReturnToShelf();
        book5.ReturnToShelf();

        WriteLine("After returning the books");
        WriteLine("-------------------------");
        PrintBooks(theBooks);
    }
コード例 #9
0
ファイル: DownloadPdf.cs プロジェクト: rmcrackan/Libation
        public override async Task <StatusHandler> ProcessAsync(LibraryBook libraryBook)
        {
            OnBegin(libraryBook);

            try
            {
                var proposedDownloadFilePath = getProposedDownloadFilePath(libraryBook);
                var actualDownloadedFilePath = await downloadPdfAsync(libraryBook, proposedDownloadFilePath);

                var result = verifyDownload(actualDownloadedFilePath);

                libraryBook.Book.UserDefinedItem.PdfStatus = result.IsSuccess ? LiberatedStatus.Liberated : LiberatedStatus.NotLiberated;

                return(result);
            }
            finally
            {
                OnCompleted(libraryBook);
            }
        }
コード例 #10
0
ファイル: LibraryImporter.cs プロジェクト: tanitall/Libation
        private int upsertLibraryBooks(IEnumerable <ImportItem> importItems)
        {
            // technically, we should be able to have duplicate books from separate accounts.
            // this would violate the current pk and would be difficult to deal with elsewhere:
            // - what to show in the grid
            // - which to consider liberated
            //
            // sqlite cannot alter pk. the work around is an extensive headache. it'll be fixed in pre .net5/efcore5
            //
            // currently, inserting LibraryBook will throw error if the same book is in multiple accounts for the same region.
            //
            // CURRENT SOLUTION: don't re-insert

            var currentLibraryProductIds = DbContext.Library.Select(l => l.Book.AudibleProductId).ToList();
            var newItems = importItems.Where(dto => !currentLibraryProductIds.Contains(dto.DtoItem.ProductId)).ToList();

            foreach (var newItem in newItems)
            {
                var libraryBook = new LibraryBook(
                    DbContext.Books.Local.Single(b => b.AudibleProductId == newItem.DtoItem.ProductId),
                    newItem.DtoItem.DateAdded,
                    newItem.AccountId);
                DbContext.Library.Add(libraryBook);
            }

            // needed for v3 => v4 upgrade
            var toUpdate = DbContext.Library.Where(l => l.Account == null);

            foreach (var u in toUpdate)
            {
                var item = importItems.FirstOrDefault(ii => ii.DtoItem.ProductId == u.Book.AudibleProductId);
                if (item != null)
                {
                    u.UpdateAccount(item.AccountId);
                }
            }

            var qtyNew = newItems.Count;

            return(qtyNew);
        }
コード例 #11
0
ファイル: UnitTest1.cs プロジェクト: nskr/Lab2
        public void TestReaderUsing()
        {
            LibraryBook newBook = new LibraryBook(BookType.Drama, 25);

            newBook.PutToStack();
            Reader newReader = new Reader("John", 1302);
            int    res1      = newReader.TakeBook(newBook);
            int    res2      = newReader.TakeBook(newBook);
            int    res3      = newReader.ReturnBook(newBook);
            int    res4      = newReader.ReturnBook(newBook);

            Assert.AreEqual(1, res1);
            Assert.AreEqual(0, res2);
            Assert.AreEqual(1, res3);
            Assert.AreEqual(0, res4);

            LibraryBook newBook2 = new LibraryBook(BookType.Horror, 29);

            newReader[0] = newBook2;
            Assert.AreEqual(newBook2, newReader[0]);
        }
コード例 #12
0
            public async Task <Unit> Handle(RequestBookNew request, CancellationToken cancellationToken)
            {
                var newBook = new LibraryBook
                {
                    Title          = request.Title,
                    AuthorBookGuid = request.AuthorBookGuid,
                    PublishDate    = request.PublishDate,
                    BookGuid       = request.BookGuid
                };

                await context.LibraryBooks.AddAsync(newBook);

                var newEntries = await context.SaveChangesAsync();

                if (newEntries > 0)
                {
                    return(Unit.Value);
                }

                throw new Exception("Something goes wrong adding a new entry");
            }
コード例 #13
0
        // do NOT use ConfigureAwait(false) on ProcessAsync()
        // often calls events which prints to forms in the UI context
        public async Task <StatusHandler> ProcessAsync(LibraryBook libraryBook)
        {
            Begin?.Invoke(this, libraryBook);

            try
            {
                {
                    var statusHandler = await DownloadBook.TryProcessAsync(libraryBook);

                    if (statusHandler.HasErrors)
                    {
                        return(statusHandler);
                    }
                }

                {
                    var statusHandler = await DecryptBook.TryProcessAsync(libraryBook);

                    if (statusHandler.HasErrors)
                    {
                        return(statusHandler);
                    }
                }

                {
                    var statusHandler = await DownloadPdf.TryProcessAsync(libraryBook);

                    if (statusHandler.HasErrors)
                    {
                        return(statusHandler);
                    }
                }

                return(new StatusHandler());
            }
            finally
            {
                Completed?.Invoke(this, libraryBook);
            }
        }
コード例 #14
0
        /// <summary>Move new files to 'Books' directory</summary>
        /// <returns>True if audiobook file(s) were successfully created and can be located on disk. Else false.</returns>
        private static bool moveFilesToBooksDir(LibraryBook libraryBook, List <FilePathCache.CacheEntry> entries)
        {
            // create final directory. move each file into it
            var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook);

            Directory.CreateDirectory(destinationDir);

            FilePathCache.CacheEntry getFirstAudio() => entries.FirstOrDefault(f => f.FileType == FileType.Audio);

            if (getFirstAudio() == default)
            {
                return(false);
            }

            for (var i = 0; i < entries.Count; i++)
            {
                var entry = entries[i];

                var realDest = FileUtility.SaferMoveToValidPath(entry.Path, Path.Combine(destinationDir, Path.GetFileName(entry.Path)));
                FilePathCache.Insert(libraryBook.Book.AudibleProductId, realDest);

                // propogate corrected path. Must update cache with corrected path. Also want updated path for cue file (after this for-loop)
                entries[i] = entry with {
                    Path = realDest
                };
            }

            var cue = entries.FirstOrDefault(f => f.FileType == FileType.Cue);

            if (cue != default)
            {
                Cue.UpdateFileName(cue.Path, getFirstAudio().Path);
            }

            AudibleFileStorage.Audio.Refresh();

            return(true);
        }
    }
コード例 #15
0
    // Precondition:  None
    // Postcondition: The LibraryBook class has been tested
    public static void Main(string[] args)
    {
        const int DAYSLATE = 5;                                                                                                                                                                      // Number of days late to test each object's CalcLateFee method

        LibraryBook     book1     = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press", 2010, 2, "ZZ25 3G");                                                                    // 1st test book
        LibraryBook     book2     = new LibraryBook("Harriet Pooter", "IP Thief", "Stealer Books", 2000, 3, "AG773 ZF");                                                                             // 2nd test book
        LibraryMovie    movie1    = new LibraryMovie("The Hills have Eyes", "Emily Robertson", 2010, 10, "AA232", 2.0, "Molly Simmins", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.G); //1st test movie
        LibraryMovie    movie2    = new LibraryMovie("The Child", "Tom Boyd", 2019, 10, "A0U32", 1.0, "Sean Smith", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.R);                     //2nd test movie
        LibraryJournal  journal1  = new LibraryJournal("The Wall Street Journal", "The NY Press", 2016, 10, "WW234", 3, 5, "Business", "John Smith");                                                //1st test journal
        LibraryJournal  journal2  = new LibraryJournal("The New Yorker", "The NY Press", 2018, 10, "W9234", 7, 12, "Business", "Yolanda Rogers");                                                    //2nd test journal
        LibraryMusic    music1    = new LibraryMusic("Theory of a Deadman", "The Press", 2018, 10, "QW234", 34.67, "Theory of a Deadman", LibraryMediaItem.MediaType.CD, 5);                         // 1st test music
        LibraryMusic    music2    = new LibraryMusic("Kids Bop 45", "The Kidz", 2019, 10, "XC234", 56.67, "KIDS Inc.", LibraryMediaItem.MediaType.CD, 8);                                            // 2nd test music
        LibraryMagazine magazine1 = new LibraryMagazine("Gossip Central", "Teen Vogue", 2015, 10, "TT189", 7, 6);                                                                                    //1st test magazine
        LibraryMagazine magazine2 = new LibraryMagazine("People", "The Press", 2019, 10, "KJ189", 9, 2);                                                                                             //2nd test magazine

        LibraryPatron patron1 = new LibraryPatron("Ima Reader", "123456");                                                                                                                           // 1st test patron
        LibraryPatron patron2 = new LibraryPatron("Jane Doe", "112233");                                                                                                                             // 2nd test patron
        LibraryPatron patron3 = new LibraryPatron("   John Smith   ", "   654321   ");                                                                                                               // 3rd test patron - Trims?
        LibraryPatron patron4 = new LibraryPatron("Jessie Hehn", "234567");                                                                                                                          // 4th test patron
        LibraryPatron patron5 = new LibraryPatron("AJ Ross", "654321");                                                                                                                              // 5th test patron


        List <LibraryItem> theLibraryItems = new List <LibraryItem> {
            book1, book2, movie1, movie2, journal1, journal2, music1, music2, magazine1, magazine2
        };                                                                                                                                                    // Test list of books, movies, journals,music,and magazines

        WriteLine("Original list of books");
        WriteLine("----------------------");
        PrintItems(theLibraryItems);
        Pause();


        foreach (LibraryItem item in theLibraryItems)
        {
            WriteLine($"{item.Title,30} {item.CallNumber,11} {item.CalcLateFee(DAYSLATE),8:C}");
        }
        Pause();
    }
コード例 #16
0
        private static async Task ProcessOneAsync(Processable Processable, LibraryBook libraryBook, bool validate)
        {
            try
            {
                var statusHandler = await Processable.ProcessSingleAsync(libraryBook, validate);

                if (statusHandler.IsSuccess)
                {
                    return;
                }

                foreach (var errorMessage in statusHandler.Errors)
                {
                    Serilog.Log.Logger.Error(errorMessage);
                }
            }
            catch (Exception ex)
            {
                var msg = "Error processing book. Skipping. This book will be tried again on next attempt. For options of skipping or marking as error, retry with main Libation app.";
                Console.WriteLine(msg + ". See log for more details.");
                Serilog.Log.Logger.Error(ex, $"{msg} {{@DebugInfo}}", new { Book = libraryBook.LogFriendly() });
            }
        }
コード例 #17
0
        public LibraryBook Create(LibraryBook libraryBookData)
        {
            LibraryBook libraryBook = new LibraryBook()
            {
                BookId    = libraryBookData.BookId,
                LibraryId = libraryBookData.LibraryId,
                UserId    = libraryBookData.UserId
            };

            int id = _db.ExecuteScalar <int>(@"
                INSERT INTO librarybooks(
                    bookId,
                    libraryId,
                    userId
                    ) VALUES (
                        @BookId,
                        @LibraryId,
                        @UserId
                    )", libraryBook);

            libraryBook.Id = id;
            return(libraryBook);
        }
コード例 #18
0
        /// <summary>
        /// Static <c>Map</c> method maps a <see cref="Core.Model.LibraryBook"/> class to a
        /// <see cref="THLibrary.DataModel.BookViewModel"/> class.
        /// </summary>
        /// <param name="book">The LibraryBook instance.</param>
        /// <returns>The BookViewModel instance.</returns>
        public static BookViewModel Map(LibraryBook book)
        {
            //  Instantiate directly as this is only even used within this UI.
            //  TODO: (If Time) refactor this to an abstract factory to create the BookViewModel
            var bookVM = new BookViewModel()
            {
                Author   = book.Author,
                Title    = book.Title,
                ISBN     = book.ISBN,
                Keywords = new ObservableCollection <string>(book.KeyWords),
                Synopsis = book.Synopsis
            };

            if (book.ImagePath == string.Empty)
            {
                bookVM.SetImage("Assets/Logo.png");     //  TODO: update to correct image file, default for now.
            }
            else
            {
                bookVM.SetImage(string.Format("Assets/{0}", book.ImagePath));
            }

            return(bookVM);
        }
コード例 #19
0
        public ActionResult LendingHistory(string lib, string bk)
        {
            if (String.IsNullOrEmpty(lib) || String.IsNullOrEmpty(bk))
            {
                return(RedirectToAction(""));
            }
            if (!HasAccessToLib(lib))
            {
                return(RedirectToAction(""));
            }
            Book                  book            = db.Books.FirstOrDefault(x => x.Id.ToString() == bk);
            LibraryBook           libraryBook     = db.LibraryBooks.FirstOrDefault(x => x.BookId.ToString() == bk && x.LibraryId.ToString() == lib);
            List <LibraryLending> libraryLendings = db.LibraryLendings.Where(x => x.LibraryBookId == libraryBook.Id).ToList();
            List <string>         Lenders         = new List <string>();

            foreach (LibraryLending lending in libraryLendings)
            {
                if (!String.IsNullOrEmpty(lending.ExternalBorrower))
                {
                    Lenders.Add(lending.ExternalBorrower);
                }
                else
                {
                    LibraryBook     lb      = db.LibraryBooks.FirstOrDefault(x => x.Id == lending.CopyLibraryBookId);
                    Library         library = db.Libraries.FirstOrDefault(x => x.Id == lb.LibraryId);
                    ApplicationUser user    = db.Users.FirstOrDefault(x => x.Id == library.UserId);
                    Lenders.Add(user.UserName);
                }
            }
            LibraryLendingHistory model = new LibraryLendingHistory()
            {
                Book = book, Lendings = libraryLendings, LenderName = Lenders
            };

            return(View(model));
        }
コード例 #20
0
ファイル: DownloadableBase.cs プロジェクト: tanitall/Libation
 protected static Task <AudibleApi.Api> GetApiAsync(LibraryBook libraryBook)
 => InternalUtilities.AudibleApiActions.GetApiAsync(libraryBook.Account, libraryBook.Book.Locale);
コード例 #21
0
ファイル: DownloadableBase.cs プロジェクト: tanitall/Libation
 public abstract Task <StatusHandler> ProcessItemAsync(LibraryBook libraryBook);
コード例 #22
0
ファイル: DownloadableBase.cs プロジェクト: tanitall/Libation
 public abstract bool Validate(LibraryBook libraryBook);
コード例 #23
0
ファイル: Program.cs プロジェクト: HFMoha01/Portfolio
    // Precondition:  None
    // Postcondition: The LibraryBook class has been tested
    public static void Main(string[] args)
    {
        LibraryBook book1 = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press",
                                            2011, "ZZ25 3G");  // 1st test book
        LibraryBook book2 = new LibraryBook("Harriet Pooter", "IP Thief", "Stealer Books",
                                            2001, "AG773 ZF"); // 2nd test book
        LibraryBook book3 = new LibraryBook("The Color Mauve", "Mary Smith", "Beautiful Books Ltd.",
                                            1986, "JJ438 4T"); // 3rd test book
        LibraryBook book4 = new LibraryBook("The Guan Guide to SQL", "Jeff Guan", "UofL Press",
                                            2019, "ZZ24 4F");  // 4th test book
        LibraryBook book5 = new LibraryBook("The Big Book of Doughnuts", "Homer Simpson", "Doh Books",
                                            2004, "AE842 7A"); // 5th test book

        // LibraryBook[] theBooks = { book1, book2, book3, book4, book5 }; // Test array of books

        //Creates a List of a books
        List <LibraryBook> theBooks = new List <LibraryBook>();

        theBooks.Add(book1);     // adds book1 to the list
        theBooks.Add(book2);     // adds book1 to the list
        theBooks.Add(book3);     // adds book1 to the list
        theBooks.Add(book4);     // adds book1 to the list
        theBooks.Add(book5);     // adds book1 to the list


        WriteLine("Original list of books");
        WriteLine("----------------------");
        PrintBooks(theBooks);
        Pause();

        LibraryPatron patron1 = new LibraryPatron("Harry", "H00001");   //Creates 1st Library Patron
        LibraryPatron patron2 = new LibraryPatron("Larry", "L00001");   //Creates 2nd Library Patron
        LibraryPatron patron3 = new LibraryPatron("Moe", "M00001");     //Creates 3rd Library Patron


        // Make changes
        book1.CheckOut(patron1);
        book2.Publisher = "Borrowed Books";
        book2.CheckOut(patron2);
        book3.CheckOut(patron2);
        book4.CheckOut(patron1);
        book4.CallNumber = "AB123 4A";
        book5.CheckOut(patron3);
        // book5.CopyrightYear = -2024; //Test



        WriteLine("After changes");
        WriteLine("-------------");
        PrintBooks(theBooks);
        Pause();

        // Return the books
        book1.ReturnToShelf();
        book2.ReturnToShelf();
        book3.ReturnToShelf();
        book4.ReturnToShelf();
        book5.ReturnToShelf();

        WriteLine("After returning the books");
        WriteLine("-------------------------");
        PrintBooks(theBooks);
    }
コード例 #24
0
ファイル: LibraryBookDialog.cs プロジェクト: dennex/Comp2614
        private void controlsToObject()
        {
            if (libraryBook == null)
            {
                libraryBook = new LibraryBook();
            }

            libraryBook.Title = textBoxTitle.Text;
            libraryBook.Author = textBoxAuthor.Text;
            libraryBook.CopyrightYear = int.Parse(textBoxCopyrightYear.Text);
        }
コード例 #25
0
    // Precondition:  None
    // Postcondition: The LibraryBook class has been tested
    public static void Main(string[] args)
    {
        LibraryMovie    movie1   = new LibraryMovie("the movie", "B", 1999, "a1234", 10, 120, "MR.T", LibraryMediaItem.MediaType.DVD, LibraryMovie.MPAARatings.PG13);
        LibraryMovie    movie2   = new LibraryMovie("the film", "H", 2007, "ghghg1", 14, 100, "MR.A", LibraryMediaItem.MediaType.BLURAY, LibraryMovie.MPAARatings.R);
        LibraryJournal  journal1 = new LibraryJournal("Scifi", "SCE", 2019, "f12367", 15, 201, 3, "chemistry", "uofl");
        LibraryMusic    music1   = new LibraryMusic("the music", "musicpub", 1976, "z120", 12, 120, LibraryMediaItem.MediaType.CD, "the who", 12);
        LibraryMagazine mag1     = new LibraryMagazine("The Mag", "MagPub", 1989, "12ACD", 30, 2, 15);

        LibraryBook book1 = new LibraryBook("The Wright Guide to C#", "Andrew Wright", "UofL Press",
                                            2010, "ZZ25 3G", 10);                      // 1st test book
        LibraryBook book2 = new LibraryBook("Harriet Pooter", "IP Thief", "Stealer Books",
                                            2000, "AG773 ZF", 10);                     // 2nd test book
        LibraryBook book3 = new LibraryBook("The Color Mauve", "Mary Smith", "Beautiful Books Ltd.",
                                            1985, "JJ438 4T", 10);                     // 3rd test book
        LibraryBook book4 = new LibraryBook("The Guan Guide to SQL", "Jeff Guan", "UofL Press",
                                            2016, "ZZ24 4F", 10);                      // 4th test book
        LibraryBook book5 = new LibraryBook("    The Big Book of Doughnuts   ", "   Homer Simpson   ", "   Doh Books   ",
                                            2001, "   AE842 7A   ", 10);               // 5th test book - Trims?

        LibraryPatron patron1 = new LibraryPatron("Ima Reader", "123456");             // 1st test patron
        LibraryPatron patron2 = new LibraryPatron("Jane Doe", "112233");               // 2nd test patron
        LibraryPatron patron3 = new LibraryPatron("   John Smith   ", "   654321   "); // 3rd test patron - Trims?

        List <LibraryBook> theBooks = new List <LibraryBook> {
            book1, book2, book3, book4, book5
        };                                                                                        // Test list of books

        //Library Movie test
        WriteLine("Testing the LibraryMovie class");
        WriteLine("--------------------------------");
        WriteLine(movie1);
        WriteLine($"Late Fee: {movie1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {movie1.CalcLateFee(45):C}\n");
        WriteLine("_____________________________________");
        WriteLine(movie2);
        WriteLine($"Late Fee: {movie2.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {movie2.CalcLateFee(45):C}");
        Pause();

        //Library Journal test
        WriteLine("Testing the LibraryJournal class");
        WriteLine("--------------------------------");
        WriteLine(journal1);
        WriteLine($"Late Fee: {journal1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {journal1.CalcLateFee(45):C}");
        Pause();

        //Library Music test
        WriteLine("Testing the LibraryMusic class");
        WriteLine("--------------------------------");
        WriteLine(music1);
        WriteLine($"Late Fee: {music1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {music1.CalcLateFee(45):C}");
        Pause();

        //Library Magazine test
        WriteLine("Testing the LibraryMagazine class");
        WriteLine("--------------------------------");
        WriteLine(mag1);
        WriteLine($"Late Fee: {mag1.CalcLateFee(15):C}");
        WriteLine($"Late Fee: {mag1.CalcLateFee(45):C}");
        Pause();


        WriteLine("Original list of books");
        WriteLine("----------------------");
        PrintBooks(theBooks);
        Pause();

        // Make changes
        book1.CheckOut(patron1);
        book2.Publisher = "Borrowed Books";
        try
        {
            book2.CheckOut(null); // Attempt invalid patron
        }
        catch (ArgumentNullException ex)
        {
            WriteLine("Caught invalid patron sent to CheckOut");
            WriteLine(ex.Message);
        }
        book3.CheckOut(patron2);
        book4.CallNumber = "    AB123 4A    ";
        book5.CheckOut(patron3);
        try
        {
            book5.CopyrightYear = -1234; // Attempt invalid year
        }
        catch (ArgumentOutOfRangeException ex)
        {
            WriteLine("Caught invalid CopyrightYear set:");
            WriteLine(ex.Message);
            WriteLine("Resetting to default year");
            book5.CopyrightYear = book5.DEFAULT_YEAR;
        }

        WriteLine("After changes");
        WriteLine("-------------");
        PrintBooks(theBooks);
        Pause();

        // Return the books
        book1.ReturnToShelf();
        book3.ReturnToShelf();
        book5.ReturnToShelf();

        WriteLine("After returning the books");
        WriteLine("-------------------------");
        PrintBooks(theBooks);
    }
コード例 #26
0
 protected void OnCompleted(LibraryBook libraryBook)
 {
     Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Completed), Book = libraryBook.LogFriendly() });
     Completed?.Invoke(this, libraryBook);
 }
コード例 #27
0
 protected void OnBegin(LibraryBook libraryBook)
 {
     Serilog.Log.Logger.Debug("Event fired {@DebugInfo}", new { Name = nameof(Begin), Book = libraryBook.LogFriendly() });
     Begin?.Invoke(this, libraryBook);
 }
コード例 #28
0
 public async Task <StatusHandler> TryProcessAsync(LibraryBook libraryBook)
 => Validate(libraryBook)
     ? await ProcessAsync(libraryBook)
     : new StatusHandler();
コード例 #29
0
ファイル: DownloadPdf.cs プロジェクト: rmcrackan/Libation
 private static string getdownloadUrl(LibraryBook libraryBook)
 => libraryBook?.Book?.Supplements?.FirstOrDefault()?.Url;
コード例 #30
0
ファイル: DownloadPdf.cs プロジェクト: rmcrackan/Libation
 public override bool Validate(LibraryBook libraryBook)
 => !string.IsNullOrWhiteSpace(getdownloadUrl(libraryBook)) &&
 !libraryBook.Book.PDF_Exists;
コード例 #31
0
 // this special case is obvious and ugly
 public void REPLACE_Library_Book(LibraryBook libraryBook) => this.libraryBook = libraryBook;
コード例 #32
0
 public GridEntry(LibraryBook libraryBook) => this.libraryBook = libraryBook;
コード例 #33
0
ファイル: ConvertToMp3.cs プロジェクト: rmcrackan/Libation
        public override bool Validate(LibraryBook libraryBook)
        {
            var path = AudibleFileStorage.Audio.GetPath(libraryBook.Book.AudibleProductId);

            return(path?.ToLower()?.EndsWith(".m4b") == true && !File.Exists(Mp3FileName(path)));
        }