|
@@ -30,17 +30,8 @@ namespace TEAMModelOS.Service.Services.Evaluation.Implements
|
|
|
{
|
|
|
public class ImportExerciseService : IImportExerciseService
|
|
|
{
|
|
|
- private static string SummaryTag = "【题文】";
|
|
|
- private static string AnswerTag = "【答案】";
|
|
|
- private static string AnalysisTag = "【解析】";
|
|
|
- private static string EndedTag = "【结束】";
|
|
|
- private static string Options = "ABCDEFGHIJ";
|
|
|
- private static string CompleteStart = "【";
|
|
|
- private static string CompleteEnd = "】";
|
|
|
- Dictionary<string, string> TestType = new Dictionary<string, string> {
|
|
|
- { "Single", "单选题|多选题" }, { "Multiple", "多选题|判断题" },
|
|
|
- { "Judge", "判断题|填空题" }, { "Complete", "填空题|主观题" },
|
|
|
- { "Subjective", "主观题|【完结】" } };
|
|
|
+
|
|
|
+
|
|
|
private readonly IAzureBlobDBRepository azureBlobDBRepository;
|
|
|
private readonly IAzureTableDBRepository azureTableDBRepository;
|
|
|
public ImportExerciseService(IAzureBlobDBRepository _azureBlobDBRepository, IAzureTableDBRepository _azureTableDBRepository)
|
|
@@ -64,27 +55,27 @@ namespace TEAMModelOS.Service.Services.Evaluation.Implements
|
|
|
// return resdict;
|
|
|
//}
|
|
|
|
|
|
- string folder = BaseConfigModel.ContentRootPath + "/Upload/" + IdWorker.getInstance().NextId();
|
|
|
- System.IO.Directory.CreateDirectory(folder);
|
|
|
- var filePath = folder + "\\" + file.FileName;
|
|
|
- using (var stream = new FileStream(filePath, FileMode.Create))
|
|
|
- {
|
|
|
- await file.CopyToAsync(stream);
|
|
|
- }
|
|
|
- var htmlInfo = ConvertDocxToHtml(filePath, folder);
|
|
|
- AzureBlobModel model = await azureBlobDBRepository.UploadPath(htmlInfo.blobPath);
|
|
|
+ string folder = IdWorker.getInstance().NextId()+"";
|
|
|
+ //System.IO.Directory.CreateDirectory(folder);
|
|
|
+ // var filePath = folder + "\\" + file.FileName;
|
|
|
+ //using (var stream = new FileStream(filePath, FileMode.Create))
|
|
|
+ //{
|
|
|
+ // await file.CopyToAsync(stream);
|
|
|
+ //}
|
|
|
+ var htmlInfo = ConvertDocxToHtml(file, folder);
|
|
|
+ AzureBlobModel model = await azureBlobDBRepository.UploadTextByFolder(htmlInfo.htmlString, "",htmlInfo.blobPath, "exercise",false);
|
|
|
model.Sha1Code = shaCode;
|
|
|
await azureTableDBRepository.Save<AzureBlobModel>(model);
|
|
|
- FileHelper.DeleteDirAndFiles(BaseConfigModel.ContentRootPath + "/Upload");
|
|
|
+ // FileHelper.DeleteDirAndFiles(BaseConfigModel.ContentRootPath + "/Upload");
|
|
|
resdict.Add("HtmlString", htmlInfo.htmlString);
|
|
|
resdict.Add("Sha1Code", shaCode);
|
|
|
return resdict;
|
|
|
}
|
|
|
- public dynamic ConvertDocxToHtml(string filePath, string folder)
|
|
|
+ public dynamic ConvertDocxToHtml(IFormFile file, string folder)
|
|
|
{
|
|
|
- string FolderName = DateTime.Now.ToString("yyyyMMdd");
|
|
|
- byte[] byteArray = File.ReadAllBytes(filePath);
|
|
|
-
|
|
|
+ string FolderName = DateTime.Now.ToString("yyyyMMdd")+"/"+ folder;
|
|
|
+ byte[] byteArray = new byte[file.OpenReadStream().Length];
|
|
|
+ file.OpenReadStream().Read(byteArray, 0, byteArray.Length);
|
|
|
//byte[] bytes = new byte[stream.Length];
|
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
|
{
|
|
@@ -191,8 +182,8 @@ namespace TEAMModelOS.Service.Services.Evaluation.Implements
|
|
|
var htmlString = htmls.ToString(SaveOptions.DisableFormatting);
|
|
|
//引入MathJax插件
|
|
|
htmlString = htmlString + "<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>";
|
|
|
- File.WriteAllText(folder + "/" + "index.html", htmlString);
|
|
|
- return new { htmlString, blobPath = folder + "/" + "index.html" };
|
|
|
+ //File.WriteAllText(folder + "/" + "index.html", htmlString);
|
|
|
+ return new { htmlString, blobPath = FolderName + "/" + "index.html" };
|
|
|
};
|
|
|
}
|
|
|
}
|