private async Task <CBookEntity> CreateBook(FileInfo file) { CBookEntity book = await bookService.FindByNameAsync(file.DirectoryName, file.Name); if (book != null) { Console.WriteLine("文件已存在..."); return(book); } book = new CBookEntity(); book.Path = file.DirectoryName; book.Name = file.Name; book.Author = ComicUtils.ParseAuthor(book.Name); book.Title = ComicUtils.ParseTitle(book.Name); book.Language = ComicUtils.ParseLanguage(book.Name); book.Length = file.Length; book.XInsert_ = file.CreationTime; book.XUpdate_ = file.LastWriteTime; book = await bookService.SaveAsync(book); return(book); }
protected override async Task OnInitializedAsync() { bookId = base.Options; bookEntity = await bookService.FindAsync(bookId); await base.OnInitializedAsync(); }
protected override async Task OnInitializedAsync() { bookId = base.Options; bookEntity = await bookService.FindAsync(bookId); bookTagEntities = await bookTagService.ListByBookAsync(bookId); authorEntity = await authorService.FindByNameAsync(bookEntity.Author); await base.OnInitializedAsync(); }
private IEnumerable <IArchiveEntry> Open(CBookEntity book, List <string> secrets) { string file = Path.Combine(book.Path, book.Name); FileInfo f = new FileInfo(file); if (!f.Exists) { Console.WriteLine("文件不存在..."); return(null); } IArchive archive = null; IEnumerable <IArchiveEntry> entries = null; foreach (var _secret in secrets) { try { if (StringUtils.IsBlank(_secret)) { archive = ArchiveFactory.Open(f); } else { archive = ArchiveFactory.Open(f, new ReaderOptions { Password = _secret }); } entries = archive.Entries; } catch (ArchiveException ex) { Console.WriteLine("压缩包存在问题."); Console.WriteLine(ex); break; } catch (CryptographicException ex) { Console.WriteLine("解压密码不正确."); Console.WriteLine(ex); } } if (entries != null) { } return(entries); }
protected override async Task OnInitializedAsync() { bookId = base.Options ?? null; if (StringUtils.IsBlank(bookId)) { bookEntity = new CBookEntity(); } else { bookEntity = await bookService.FindCloneAsync(bookId); } await base.OnInitializedAsync(); }
public async Task Cover(string id) { byte[] cover = coverService.GetCached(id); if (cover == null) { CBookEntity book = await bookService.FindAsync(id); cover = await coverService.GetAsync(book); } if (cover == null || cover.Length == 0) { return; } using (Stream stream = this.Response.BodyWriter.AsStream()) { await stream.WriteAsync(cover, 0, cover.Length); } }
public async Task <byte[]> GetAsync(CBookEntity book) { //lock(this); if (cache.ContainsKey(book.Id)) { return(cache[book.Id]); } //string cover = ""; byte[] c = await ReadAsync(Path.Combine(book.Path, book.Name), book.Cover); cache.Add(book.Id, c); if (c == null || c.Length == 0) { book.Note = "err:拾取封面失败."; } return(cache[book.Id]); }
private async Task DiscoveryComic(string path, bool children) { DirectoryInfo root = new DirectoryInfo(path); if (!root.Exists) { Console.WriteLine("目录不存在"); // 文件目录不存在 // TODO: 这里应该有个报警. return; } if (children) { DirectoryInfo[] dirs = root.GetDirectories(); foreach (var dir in dirs) { await DiscoveryComic(dir.FullName, children); } } FileInfo[] files = root.GetFiles(); foreach (var file in files) { if (!ComicUtils.IsArchive(file.Name)) { // 如果当前文件不是漫画档案 continue; } CBookEntity book = await CreateBook(file); BAuthorEntity author = await CreateAuthor(book.Author); } }
protected override async Task OnInitializedAsync() { Console.WriteLine("读取漫画详情"); book = await bookService.FindAsync(Id); }