Пример #1
0
        /// <summary>
        /// creates a new comic book record based on the cbz/cbr path specified
        /// </summary>
        /// <param name="archivePath">
        /// path to the cbz/cbr archive file
        /// </param>
        public void InitializeNewComicBook(string archivePath)
        {
            if (!File.Exists(archivePath))
            {
                Trace.WriteLine("Parameter archivePath = " + "<" + archivePath + ">" + " is invalid, cannot proceed with comic book records write process.");
                FileNotFoundException exc = new FileNotFoundException
                                            (
                    "Parameter archivePath = " + "<" + archivePath + ">" + " is invalid, cannot proceed with comic book records write process."
                                            );
                throw exc;
            }

            if (PathIsValid())
            {
                ComicBook newComicBook = new ComicBook();

                //set default init values for newComicBook
                newComicBook.SetArchivePath(archivePath);
                newComicBook.ComicTitle    = Path.GetFileNameWithoutExtension(archivePath);
                newComicBook.ComicSynopsis = "";
                newComicBook.Override_SetPageCount(ReadPageCount(archivePath));
                WriteComicBookRecord(newComicBook);
            }
            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;
            }
        }
Пример #2
0
        /// <summary>
        /// reads all the comic book records in the comic book records XML file
        /// </summary>
        private void ReadComicBookRecords()
        {
            if (PathIsValid())
            {
                //clear current records
                comicBookList  = new List <ComicBook>();
                ComicBookCount = 0;

                //load the comic book record xml file
                XDocument xDocument = XDocument.Load(filePath);

                //remove invalid records first if there are any
                var InvalidElement = xDocument.Descendants("ComicBook").Where(el => !File.Exists(el.Element("ArchivePath").Value)).ToList();

                foreach (var node in InvalidElement)
                {
                    node.Remove();
                }

                foreach (XElement bookRecord in xDocument.Descendants("ComicBook"))
                {
                    //get metadata information
                    //this is the path w/filename to the .cbz/.cbr, NOT THE CACHE
                    XElement archivePath = 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);
                        }
                    }

                    //set comic book read information
                    ComicBook comicBookRead = new ComicBook();
                    comicBookRead.SetArchivePath(archivePath.Value);
                    comicBookRead.ComicTitle        = titleRead.Value;
                    comicBookRead.ComicSubTitle     = subtitleRead.Value;
                    comicBookRead.ComicIssue        = issueRead.Value;
                    comicBookRead.ComicDateAdded    = DateTime.Parse(dateAddedRead.Value);
                    comicBookRead.ComicDateReleased = DateTime.Parse(dateReleasedRead.Value);
                    comicBookRead.ComicSynopsis     = synopsisRead.Value;
                    comicBookRead.Publisher         = publisherRead.Value;
                    comicBookRead.ViewCount         = int.Parse(viewCountRead.Value);
                    comicBookRead.RateComicBook(float.Parse(avgRatingRead.Value));
                    comicBookRead.Override_SetPageCount(int.Parse(pgCountRead.Value));

                    if (genreRead.Count() != 0)
                    {
                        comicBookRead.ComicGenres = genreRead.ToArray();
                    }
                    else
                    {
                        comicBookRead.ComicGenres = null;
                    }

                    if (AuthorRead.Count() != 0)
                    {
                        comicBookRead.ComicAuthors = AuthorRead.ToArray();
                    }
                    else
                    {
                        comicBookRead.ComicAuthors = null;
                    }

                    //add comic book information to list
                    comicBookList.Add(comicBookRead);

                    //increment count of comic books available
                    ComicBookCount++;
                }
            }
            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;
            }
        }