Ejemplo n.º 1
0
        private static async Task <EpubBook> ReadBookAsync(EpubBookRef epubBookRef)
        {
            EpubBook result = new EpubBook();

            using (epubBookRef)
            {
                result.FilePath   = epubBookRef.FilePath;
                result.Schema     = epubBookRef.Schema;
                result.Title      = epubBookRef.Title;
                result.AuthorList = epubBookRef.AuthorList;
                result.Author     = epubBookRef.Author;
                result.Content    = await ReadContent(epubBookRef.Content).ConfigureAwait(false);

                result.CoverImage = await epubBookRef.ReadCoverAsync().ConfigureAwait(false);

                result.Description = epubBookRef.Description;
                List <EpubTextContentFileRef> htmlContentFileRefs = await epubBookRef.GetReadingOrderAsync().ConfigureAwait(false);

                result.ReadingOrder = ReadReadingOrder(result, htmlContentFileRefs);
                List <EpubNavigationItemRef> navigationItemRefs = await epubBookRef.GetNavigationAsync().ConfigureAwait(false);

                result.Navigation = ReadNavigation(result, navigationItemRefs);
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens the book asynchronously without reading its content. Holds the handle to the EPUB file.
        /// </summary>
        /// <param name="filePath">path to the EPUB file</param>
        /// <returns></returns>
        public static async Task <EpubBookRef> OpenBookAsync(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Specified epub file not found.", filePath);
            }
            ZipArchive  epubArchive = ZipFile.OpenRead(filePath);
            EpubBookRef bookRef     = new EpubBookRef(epubArchive);

            bookRef.FilePath = filePath;
            bookRef.Schema   = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false);

            bookRef.Title      = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty;
            bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
            bookRef.Author     = String.Join(", ", bookRef.AuthorList);
            bookRef.Content    = await Task.Run(() => ContentReader.ParseContentMap(bookRef)).ConfigureAwait(false);

            return(bookRef);
        }
Ejemplo n.º 3
0
        private static async Task <EpubBook> ReadBookAsync(EpubBookRef epubBookRef)
        {
            EpubBook result = new EpubBook();

            using (epubBookRef)
            {
                result.FilePath   = epubBookRef.FilePath;
                result.Schema     = epubBookRef.Schema;
                result.Title      = epubBookRef.Title;
                result.AuthorList = epubBookRef.AuthorList;
                result.Author     = epubBookRef.Author;
                result.Content    = await ReadContent(epubBookRef.Content).ConfigureAwait(false);

                result.CoverImage = await epubBookRef.ReadCoverAsync().ConfigureAwait(false);

                List <EpubChapterRef> chapterRefs = await epubBookRef.GetChaptersAsync().ConfigureAwait(false);

                result.Chapters = await ReadChapters(chapterRefs).ConfigureAwait(false);
            }
            return(result);
        }
Ejemplo n.º 4
0
        private static async Task <EpubBookRef> OpenBookAsync(ZipArchive zipArchive, string filePath = null)
        {
            EpubBookRef result = null;

            try
            {
                result          = new EpubBookRef(zipArchive);
                result.FilePath = filePath;
                result.Schema   = await SchemaReader.ReadSchemaAsync(zipArchive).ConfigureAwait(false);

                result.Title      = result.Schema.Package.Metadata.Titles.FirstOrDefault() ?? string.Empty;
                result.AuthorList = result.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
                result.Author     = string.Join(", ", result.AuthorList);
                return(result);
            }
            catch
            {
                result?.Dispose();
                throw;
            }
        }
Ejemplo n.º 5
0
 public EpubContentFileRef(EpubBookRef epubBookRef)
 {
     this.epubBookRef = epubBookRef;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Opens the book asynchronously and reads all of its content into the memory. Does not hold the handle to the EPUB file.
        /// </summary>
        /// <param name="filePath">path to the EPUB file</param>
        /// <returns></returns>
        public static async Task <EpubBook> ReadBookAsync(string filePath)
        {
            EpubBookRef epubBookRef = await OpenBookAsync(filePath).ConfigureAwait(false);

            return(await ReadBookAsync(epubBookRef).ConfigureAwait(false));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Opens the book asynchronously and reads all of its content into the memory.
        /// </summary>
        /// <param name="stream">seekable stream containing the EPUB file</param>
        /// <returns></returns>
        public static async Task <EpubBook> ReadBookAsync(Stream stream)
        {
            EpubBookRef epubBookRef = await OpenBookAsync(stream).ConfigureAwait(false);

            return(await ReadBookAsync(epubBookRef).ConfigureAwait(false));
        }
Ejemplo n.º 8
0
 public EpubTextContentFileRef(EpubBookRef epubBookRef)
     : base(epubBookRef)
 {
 }
Ejemplo n.º 9
0
 public EpubByteContentFileRef(EpubBookRef epubBookRef)
     : base(epubBookRef)
 {
 }