/// <summary> /// opens a new comic book for reading /// </summary> /// <param name="comicToOpen"></param> public void OpenComicBook(ComicBook comicToOpen) { //start of background thread stuff progDialog = new ProgressDialog(); backgroundProcessDone = false; bgWorker = new BackgroundWorker { WorkerReportsProgress = true, WorkerSupportsCancellation = true }; comicReader.ReportProgress += ComicReader_ReportProgress; bgWorker.DoWork += delegate(object s, DoWorkEventArgs args) { comicReader.OpenComicBook(comicToOpen.GetArchivePath()); }; bgWorker.RunWorkerAsync(); progDialog.ShowDialog(); //end of background thread stuff //wait for comic book to load while (!backgroundProcessDone) { ; } IsReadingComic = true; }
private void ComicInfo_SetValues(ComicBook cb) { txtBxComicTitle.Text = cb.ComicTitle; txtBxComicSubTitle.Text = cb.ComicSubTitle; txtBxComicIssue.Text = cb.ComicIssue; txtBxDateAdded.Text = cb.ComicDateAdded.ToShortDateString(); txtBxDateReleased.Text = cb.ComicDateReleased.ToShortDateString(); richTxtBxSynopsis.Text = cb.ComicSynopsis; if (cb.ComicAuthors != null) { txtBxAuthors.ResetText(); txtBxAuthors.Text = string.Join(",", cb.ComicAuthors); } if (cb.ComicGenres != null) { txtBxGenre.ResetText(); txtBxGenre.Text = string.Join(",", cb.ComicGenres); } txtBxPublisher.Text = cb.Publisher; lblViewCount.Text = "# of Views: " + cb.ViewCount.ToString(); lblAvgRating.Text = "Average Rating: " + cb.Rating.ToString(); lblNumPages.Text = "# of Pages: " + cb.PageCount.ToString() + " Pages"; if (picBxComicCover.Image != null) { picBxComicCover.Image.Dispose(); } picBxComicCover.Image = comicManager.GetComicFrontCover(cb.GetArchivePath()); }
private void btnRemove_Click(object sender, EventArgs e) { string fileName = lstBxSavedComics.SelectedItem.ToString(); //get comic book ComicBook importedCb = comicManager.GetComicBook(Path.Combine(cbResourceDirectory, fileName)); //remove from user library loggedInUser.MyComicLibrary.RemoveComicBook(importedCb.GetArchivePath()); //write changes accountManager.WriteComicLibrary(loggedInUser.Id, loggedInUser.MyComicLibrary); //refresh to reflect changes ReloadLibrary(); btnRemove.Enabled = false; }
/// <summary> /// updates the comic book based on the archivePath in the comic book records XML file /// </summary> /// <param name="updatedComicBook"></param> /// <returns> /// true if successful, false otherwise /// </returns> public bool UpdateComicBookRecord(ComicBook updatedComicBook) { if (PathIsValid()) { //load the comic book record xml file XDocument xDocument = XDocument.Load(filePath); foreach (XElement bookRecord in xDocument.Descendants("ComicBook")) { //get metadata information //this is the path w/filename to the .cbz/.cbr, NOT THE CACHE XElement archivePathRead = bookRecord.Element("ArchivePath"); //get required elements for comic book information XElement titleRead = bookRecord.Element("Title"); XElement subtitleRead = bookRecord.Element("Subtitle"); XElement issueRead = bookRecord.Element("Issue"); XElement dateAddedRead = bookRecord.Element("Date_Added"); XElement dateReleasedRead = bookRecord.Element("Date_Released"); XElement synopsisRead = bookRecord.Element("Synopsis"); XElement publisherRead = bookRecord.Element("Publisher"); XElement viewCountRead = bookRecord.Element("View_Count"); XElement avgRatingRead = bookRecord.Element("Avg_Rating"); XElement pgCountRead = bookRecord.Element("PageCount"); XElement genresRead = bookRecord.Element("Genres"); XElement AuthorsRead = bookRecord.Element("Authors"); List <string> AuthorRead = new List <string>(); List <string> genreRead = new List <string>(); //have to go down the genres, there could be multiple genres //do so if there are any if (genresRead.Descendants().Count() != 0) { foreach (XElement genre in genresRead.Descendants()) { genreRead.Add(genre.Value); } } //have to go down the authors, there could be multiple authors //do so if there are any if (AuthorsRead.Descendants().Count() != 0) { foreach (XElement author in AuthorsRead.Descendants()) { AuthorRead.Add(author.Value); } } //check if matching archive path if (archivePathRead.Value == updatedComicBook.GetArchivePath()) { //update contents titleRead.Value = updatedComicBook.ComicTitle; subtitleRead.Value = updatedComicBook.ComicSubTitle; issueRead.Value = updatedComicBook.ComicIssue; dateAddedRead.Value = updatedComicBook.ComicDateAdded.ToShortDateString(); dateReleasedRead.Value = updatedComicBook.ComicDateReleased.ToShortDateString(); synopsisRead.Value = updatedComicBook.ComicSynopsis; publisherRead.Value = updatedComicBook.Publisher; viewCountRead.Value = updatedComicBook.ViewCount.ToString(); avgRatingRead.Value = updatedComicBook.Rating.ToString(); pgCountRead.Value = updatedComicBook.PageCount.ToString(); //remove genres, if not empty if (genresRead.Descendants().Count() != 0) { genresRead.Descendants().Remove(); } //re-add genres, if any if (updatedComicBook.ComicGenres != null) { foreach (string newGenre in updatedComicBook.ComicGenres) { genresRead.Add(new XElement("Genre", newGenre)); } } //remove authors, if not empty if (AuthorsRead.Descendants().Count() != 0) { AuthorsRead.Descendants().Remove(); } //re-add authors, if any if (updatedComicBook.ComicAuthors != null) { foreach (string newAuthor in updatedComicBook.ComicAuthors) { AuthorsRead.Add(new XElement("Author", newAuthor)); } } //save changes in XML document xDocument.Save(filePath); //re-update current records to reflect changes ReadComicBookRecords(); return(true); } } return(false); } else { Trace.WriteLine("Set Path = " + "<" + filePath + ">" + " is invalid, cannot proceed with comic book records access."); FileNotFoundException exc = new FileNotFoundException ( "Set Path = " + "<" + filePath + ">" + " cannot proceed with comic book records access." ); throw exc; } }
/// <summary> /// writes a new comic book record to the comic book records XML file, /// if it doesn't exist yet, based on its archivePath /// </summary> public void WriteComicBookRecord(ComicBook newComicBook) { if (PathIsValid()) { //check if it already exists, ignore write if it does if (ComicBookRecordExists(newComicBook.GetArchivePath())) { return; } //load the comic book record XML file XDocument xDocument = XDocument.Load(filePath); //Genres has child nodes XElement newGenres = new XElement("Genres"); //Check if comic book has set list, add to Genres if true if (newComicBook.ComicGenres != null) { foreach (var genre in newComicBook.ComicGenres) { newGenres.Add(new XElement("Genre", genre)); } } //Authors has child nodes XElement newAuthors = new XElement("Authors"); //Check if comic book has set list, add to Authors if true if (newComicBook.ComicAuthors != null) { foreach (var author in newComicBook.ComicAuthors) { newAuthors.Add(new XElement("Author", author)); } } XElement newComicBookRecord = new XElement( "ComicBook", new XElement("ArchivePath", newComicBook.GetArchivePath()), new XElement("Title", newComicBook.ComicTitle), new XElement("Subtitle", newComicBook.ComicSubTitle), new XElement("Issue", newComicBook.ComicIssue), new XElement("PageCount", newComicBook.PageCount), new XElement("Date_Added", newComicBook.ComicDateAdded.ToShortDateString()), new XElement("Date_Released", newComicBook.ComicDateReleased.ToShortDateString()), new XElement("Synopsis", newComicBook.ComicSynopsis), newGenres, new XElement("Publisher", newComicBook.Publisher), new XElement("View_Count", newComicBook.ViewCount.ToString()), new XElement("Avg_Rating", newComicBook.Rating.ToString()), newAuthors ); //add to root of comic book record XML file xDocument.Root.Add(newComicBookRecord); //save the changes made to the comic book record XML file xDocument.Save(filePath); //update current records to reflect changes ComicBookCount++; comicBookList.Add(newComicBook); ExtractCoversToCache(); } else { Trace.WriteLine("Set Path = " + "<" + filePath + ">" + " is invalid, cannot proceed with comic book records write operation."); FileNotFoundException exc = new FileNotFoundException ( "Set Path = " + "<" + filePath + ">" + " cannot proceed with comic book records access." ); throw exc; } }
/// <summary> /// deletes the existing comic book /// </summary> /// <param name="comicBookToDelete"></param> /// <returns></returns> public bool DeleteComicBook(ComicBook comicBookToDelete) { return(comicManager.RemoveComicBookRecord(comicBookToDelete.GetArchivePath())); }