public static async Task <PDFBook> OpenBookAsync(string filePath) { if (UrlUtils.FileIsUrl(filePath)) { var localFilePath = await UrlUtils.UrlToFile(filePath); if (string.IsNullOrEmpty(localFilePath)) { throw new FileNotFoundException("Specified remote PDF file could not be downloaded to local filesystem.", filePath); } filePath = localFilePath; } //filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath); if (!File.Exists(filePath)) { throw new FileNotFoundException("Specified local PDF file not found.", filePath); } var book = new PDFBook(filePath); return(book); }
/// <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 (UrlUtils.FileIsUrl(filePath)) { var localFilePath = await UrlUtils.UrlToFile(filePath); if (string.IsNullOrEmpty(localFilePath)) { throw new FileNotFoundException("Specified remote ePub file could not be downloaded to local filesystem.", filePath); } filePath = localFilePath; } if (!File.Exists(filePath)) { throw new FileNotFoundException("Specified local 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); }