12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System.Collections.Generic;
- using GxPress.Request.Media;
- using GxPress.Result.Category;
- using GxPress.Result.Media;
- using GxPress.Service.Interface.Epub;
- using VersOne.Epub;
- namespace GxPress.Service.Implement.Epub
- {
- public class EpubService : IEpubService
- {
- /// <summary>
- /// 获取书籍目录
- /// </summary>
- public List<BookCatalogResult> GetCatalog(string path)
- {
- var result = new List<BookCatalogResult>();
- EpubBook epubBook = EpubReader.ReadBook(path);
- int i = 1;
- // 目录
- //列举章节
- foreach (EpubNavigationItem chapter in epubBook.Navigation)
- {
- //本章标题
- var bookCatalog = new BookCatalogResult();
- bookCatalog.Id = i;
- bookCatalog.CatalogNameg = chapter.Title;
- bookCatalog.CatalogId = chapter.HtmlContentFile.FileName;
- result.Add(bookCatalog);
- //嵌套章节
- List<EpubNavigationItem> subChapters = chapter.NestedItems;
- foreach (var item in subChapters)
- {
- bookCatalog = new BookCatalogResult();
- bookCatalog.CatalogNameg = item.Title;
- bookCatalog.CatalogId = item.HtmlContentFile.FileName;
- bookCatalog.ParentId = i;
- result.Add(bookCatalog);
- }
- i++;
- }
- return result;
- }
- /// <summary>
- /// 获取章节内容
- /// </summary>
- /// <returns></returns>
- public string GetBookCatalogContext(BookCatalogRequest request)
- {
- if (string.IsNullOrEmpty(request.Path))
- return string.Empty;
- EpubBook epubBook = EpubReader.ReadBook(request.Path);
- string htmlContent = string.Empty;
- foreach (EpubTextContentFile textContentFile in epubBook.ReadingOrder)
- {
- if (textContentFile.FileName.Equals(request.CatalogId) || textContentFile.FileName.Equals(request.CatalogNameg))
- {
- //当前文本内容文件的HTML
- htmlContent = textContentFile.Content;
- break;
- }
- }
- return htmlContent;
- }
- }
- }
|