public async Task BuildChapter(CommonDbContext dbContext, string categoryName) { var category = await dbContext.Categories.Include("ContentList").Include("ContentList.MediaResource").FirstOrDefaultAsync(x => x.Name == categoryName); var PDFFiles = Directory.EnumerateFiles(DirectoryPath); var chapterIndex = 1; foreach (var pdfItem in PDFFiles) { var streamStreamList = PDFTool.PDFToImage(pdfItem); //chapter level var chapterName = $"第{chapterIndex}话"; var chapterContent = await prepareChapter(dbContext, category, chapterName, chapterIndex); var imgIndex = 1; foreach (var imgStream in streamStreamList) { var imgName = "cartoon/" + chapterName + "/img" + imgIndex + ".jpg"; await prepareImage(dbContext, chapterContent, imgStream, imgName); imgIndex++; } chapterIndex++; } }
static string ProcessFile(string filePath, string dirName) { var extention = Path.GetExtension(filePath); var fileName = "cartoon/" + Path.GetRandomFileName(); switch (extention) { case ".zip": var outpuDirPaht = ZipTool.Exact(filePath); AnalyseDic(outpuDirPaht, dirName); break; case ".pdf": var outpuStream = PDFTool.PDFToImage(filePath); //QiniuTool.UploadImage(outpuStream, fileName).Wait(); break; case ".jpg": case ".jpeg": QiniuTool.UploadImage(filePath, fileName).Wait(); break; } return(fileName); }
string ProcessFile(string filePath, string dirName, int contentOrder) { var extention = Path.GetExtension(filePath); var fileName = string.Empty; switch (extention) { case ".zip": var outpuDirPahtZip = ZipTool.Exact(filePath); CreateContentAndUploadImage(outpuDirPahtZip, dirName, contentOrder); Directory.Delete(outpuDirPahtZip, true); break; case ".rar": var outpuDirPahtRar = ZipTool.Exact(filePath); CreateContentAndUploadImage(outpuDirPahtRar, dirName, contentOrder); Directory.Delete(outpuDirPahtRar, true); break; case ".pdf": var outpuStreamList = PDFTool.PDFToImage(filePath).Result; CreateContentAndUploadImage(filePath, dirName, outpuStreamList, contentOrder); break; } return(fileName); }