示例#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);

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

                result.Chapters = await ReadChapters(chapterRefs).ConfigureAwait(false);
            }
            return(result);
        }
示例#2
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);
                result.Content    = await Task.Run(() => ContentReader.ParseContentMap(result)).ConfigureAwait(false);

                return(result);
            }
            catch
            {
                result?.Dispose();
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Opens the book asynchronously and reads all of its content into the memory.
        /// </summary>
        /// <param name="filePath">path to 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));
        }
示例#4
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));
        }
 public EpubTextContentFileRef(EpubBookRef epubBookRef)
     : base(epubBookRef)
 {
 }
 public EpubByteContentFileRef(EpubBookRef epubBookRef)
     : base(epubBookRef)
 {
 }