123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- using DocumentFormat.OpenXml.Packaging;
- using HtmlAgilityPack;
- using Microsoft.AspNetCore.Http;
- using OpenXmlPowerTools;
- using System;
- using System.Collections.Generic;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using TEAMModelOS.Model.Core.Dtos;
- using TEAMModelOS.Model.Core.Models;
- using TEAMModelOS.Model.Evaluation.Dtos.Own;
- using TEAMModelOS.Model.Evaluation.Models;
- using TEAMModelOS.SDK.Context.Configuration;
- using TEAMModelOS.SDK.Context.Constant;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
- using TEAMModelOS.SDK.Extension.SnowFlake;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.SDK.Helper.Common.FileHelper;
- using TEAMModelOS.SDK.Helper.Common.JsonHelper;
- using TEAMModelOS.SDK.Helper.Common.StringHelper;
- using TEAMModelOS.SDK.Helper.Network.HttpHelper;
- using TEAMModelOS.SDK.Helper.Security.ShaHash;
- using TEAMModelOS.SDK.Module.AzureBlob.Container;
- using TEAMModelOS.SDK.Module.AzureBlob.Implements;
- using TEAMModelOS.SDK.Module.AzureBlob.Interfaces;
- using TEAMModelOS.SDK.Module.AzureTable.Interfaces;
- using TEAMModelOS.SDK.Module.PowerPointX;
- using TEAMModelOS.SDK.Module.PowerPointX.Model;
- using TEAMModelOS.Service.Core.Implements;
- using TEAMModelOS.Service.Evaluation.Interfaces;
- namespace TEAMModelOS.Service.Evaluation.Implements
- {
- public class ImportExerciseService : BaseService, 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 IHttpContextAccessor httpContextAccessor;
- private readonly IAzureBlobDBRepository azureBlobDBRepository;
- public ImportExerciseService(IHttpContextAccessor _httpContextAccessor, IAzureBlobDBRepository _azureBlobDBRepository)
- {
- azureBlobDBRepository = _azureBlobDBRepository;
- httpContextAccessor = _httpContextAccessor;
-
- }
- public async Task<Dictionary<string, object>> UploadPPTX(IFormFile file) {
- Dictionary<string, object> resdict = new Dictionary<string, object>();
- PresentationConvert convert = new PresentationConvert();
- PPTXInfo info= convert.LoadPresentation(file.OpenReadStream());
- resdict.Add("pptx", info);
- return resdict;
- }
- public async Task<Dictionary<string, object>> UploadWord(IFormFile file)
- {
- Dictionary<string, object> resdict = new Dictionary<string, object>();
- string shaCode = ShaHashHelper.GetSHA1(file.OpenReadStream());
- long length = file.Length;
- Dictionary<string, object> dict = new Dictionary<string, object> { { "Sha1Code", shaCode } };
- List<AzureBlobModel> models = await FindListByDict<AzureBlobModel>(dict);
-
- //if (models.IsNotEmpty())
- //{
- // resdict.Add("HtmlString", HttpHelper.HttpGet(models[0].BlobUrl));
- // resdict.Add("Sha1Code", models[0].Sha1Code);
- // 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);
- model.Sha1Code = shaCode;
- await Save<AzureBlobModel>(model);
- FileHelper.DeleteDirAndFiles(BaseConfigModel.ContentRootPath + "/Upload");
- resdict.Add("HtmlString", htmlInfo.htmlString);
- resdict.Add("Sha1Code", shaCode);
- return resdict;
- }
- public dynamic ConvertDocxToHtml(string filePath, string folder)
- {
- string FolderName = DateTime.Now.ToString("yyyyMMdd");
- byte[] byteArray = File.ReadAllBytes(filePath);
- //byte[] bytes = new byte[stream.Length];
- using (MemoryStream memoryStream = new MemoryStream())
- {
- memoryStream.Write(byteArray, 0, byteArray.Length);
- using (WordprocessingDocument doc = WordprocessingDocument.Open(memoryStream, true))
- {
- int imageCounter = 0;
- WmlToHtmlConverterSettings settings = new WmlToHtmlConverterSettings()
- {
- PageTitle = "",
- AdditionalCss = "body { margin: 1cm auto; max-width: 20cm; padding: 0; }",
- FabricateCssClasses = true,
- CssClassPrefix = "pt-",
- RestrictToSupportedLanguages = false,
- RestrictToSupportedNumberingFormats = false,
- ImageHandler = imageInfo =>
- {
- ++imageCounter;
- string extension = imageInfo.ContentType.Split('/')[1].ToLower();
- ImageFormat imageFormat = null;
- if (extension.Equals("png")) imageFormat = ImageFormat.Png;
- else if (extension.Equals("gif")) imageFormat = ImageFormat.Gif;
- else if (extension.Equals("bmp")) imageFormat = ImageFormat.Bmp;
- else if (extension.Equals("jpeg")) imageFormat = ImageFormat.Jpeg;
- else if (extension.Equals("tiff"))
- {
- extension = "gif";
- imageFormat = ImageFormat.Gif;
- }
- else if (extension.Equals( "x-wmf"))
- {
- extension = "wmf";
- imageFormat = ImageFormat.Wmf;
- }
- if (imageFormat == null) return null;
- string base64 = null;
- string mimeType = null;
- string shaCode = null;
- try
- {
- if (extension.Equals("wmf"))
- {
- var buffer = Encoding.Default.GetBytes(imageInfo.Mathxml);
- base64 = System.Convert.ToBase64String(buffer);
- mimeType = "image/svg+xml";
- shaCode = ShaHashHelper.GetSHA1( new MemoryStream(buffer));
- }
- else {
- ImageFormat format = imageInfo.Bitmap.RawFormat;
- ImageCodecInfo codec = ImageCodecInfo.GetImageDecoders()
- .First(c => c.FormatID == format.Guid);
- mimeType = codec.MimeType;
- using (MemoryStream ms = new MemoryStream())
- {
-
- imageInfo.Bitmap.Save(ms, imageFormat);
- var ba = ms.ToArray();
- base64 = System.Convert.ToBase64String(ba);
- shaCode = ShaHashHelper.GetSHA1(ms);
- }
- }
- }
- catch (System.Runtime.InteropServices.ExternalException)
- { return null; }
- string imageSource =
- string.Format("data:{0};base64,{1}", mimeType, base64);
- #region 处理图片存到Bolb
- string[] strs = imageSource.Split(',');
- string fileExt = StringHelper.SubMidString(strs[0], ":", ";");
- if (ContentTypeDict.extdict.TryGetValue(fileExt, out string ext))
- {
- fileExt = ext;
- }
- else
- {
- //解决多种扩展名不能获取的
- string[] sp = StringHelper.SubMidString(strs[0], "/", ";").Split("-");
- fileExt = sp[sp.Length - 1];
- sp = fileExt.Split("+");
- fileExt = "." + sp[sp.Length - 1];
- }
- Stream stream = new MemoryStream(Convert.FromBase64String(strs[1]));
- // long bizno = IdWorker.getInstance().NextId();
- string filename = shaCode + fileExt;
- AzureBlobModel model = azureBlobDBRepository.UploadFileByFolderNAsyn(stream, FolderName, filename, "exercise", false);
- #endregion
- XElement img = new XElement(Xhtml.img,
- new XAttribute(NoNamespace.src, model.BlobUrl),
- imageInfo.ImgStyleAttribute,
- imageInfo.AltText != null ?
- new XAttribute(NoNamespace.alt, imageInfo.AltText) : null);
- stream.Close();
- return img;
- }
- };
- // XElement html = HtmlConverter.ConvertToHtml(doc, settings);
- // File.WriteAllText(@"E:\document\kk.html", html.ToStringNewLineOnAttributes());
- XElement htmlElement = WmlToHtmlConverter.ConvertToHtml(doc, settings);
- var htmls = new XDocument(new XDocumentType("html", null, null, null), htmlElement);
- 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" };
- };
- }
- }
-
-
- public async Task<List<ExerciseDto>> AnalyzeWordAsync(DocInfoDto dict, string Lang)
- {
- List<ContentVerify> contents = await this.FindListByKey<ContentVerify>("DigestCode", dict.ShaCode);
- string html="";
- if (contents.IsNotEmpty())
- {
- html = contents[0].Content;
- }
- else
- {
-
-
- }
- //String url = "https://teammodelstorage.blob.core.chinacloudapi.cn/teammodelcontest/20190517/%E6%A8%A1%E6%9D%BF%E6%A0%B7%E4%BE%8B.doc";
- Dictionary<string, string> TestInType = new Dictionary<string, string>();
- html = html.Replace("\t", " ").Replace("<span>", "").Replace("</span>", "");
- //去除class
- string classpattern = "class=\"([^\"]*)\"";
- html = Regex.Replace(html, classpattern, "");
- string pattern = "<span([^>]{0,})>";
- html = Regex.Replace(html, pattern, "");
- foreach (string key in TestType.Keys)
- {
- string[] tags = TestType[key].Split("|");
- string RegexStr = tags[0] + "([\\s\\S]*?)" + tags[1];
- Match mt = Regex.Match(html, RegexStr);
- TestInType.Add(key, mt.Value);
- }
- List<ExerciseDto> tests = new List<ExerciseDto>();
- ///解析几种题型的题目
- foreach (string key in TestInType.Keys)
- {
- switch (key)
- {
- case "Single":
- List<ExerciseDto> exercisesSingle = SingleConvert(key, TestInType[key]);
- tests.AddRange(exercisesSingle); break;
- case "Multiple":
- List<ExerciseDto> exercisesMultiple = MultipleConvert(key, TestInType[key]);
- tests.AddRange(exercisesMultiple); break;
- case "Judge":
- List<ExerciseDto> exercisesJudge = JudgeConvert(key, TestInType[key]);
- tests.AddRange(exercisesJudge); break;
- case "Complete":
- List<ExerciseDto> exercisesComplete = CompleteConvert(key, TestInType[key]);
- tests.AddRange(exercisesComplete); break;
- case "Subjective":
- List<ExerciseDto> exercisesSubjective = SubjectiveConvert(key, TestInType[key]);
- tests.AddRange(exercisesSubjective); break;
- default: break;
- }
- }
- ///SaveExercise(tests, Lang);
- return tests;
- }
- //public async void SaveExercise(List<ExerciseDto> exercises, string Lang)
- //{
- // string tmdid = "";
- // List<string> ids = HttpContextHelper.GetLoginUser(httpContextAccessor, "id");
- // if (ids.IsNotEmpty())
- // {
- // tmdid = ids[0];
- // }
- // List<ExerciseVerify> exerciseVerifies = new List<ExerciseVerify>();
- // exercises.ForEach(x =>
- // {
- // ExerciseVerify exercise0 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode, Type = 0, PartitionKey = Lang, Content = x.Question, SummaryCode = x.ShaCode, Status = 1 };
- // exerciseVerifies.Add(exercise0);
- // if (x.Option.IsNotEmpty())
- // {
- // string opt = MessagePackHelper.ObjectToJson(x.Option);
- // ExerciseVerify exercise1 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(opt), Type = 1, PartitionKey = Lang, Content = opt, SummaryCode = x.ShaCode, Status = 1 };
- // exerciseVerifies.Add(exercise1);
- // }
- // if (x.Answer.IsNotEmpty())
- // {
- // string ans = MessagePackHelper.ObjectToJson(x.Answer);
- // ExerciseVerify exercise2 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(ans), Type = 2, PartitionKey = Lang, Content = ans, SummaryCode = x.ShaCode, Status = 1 };
- // exerciseVerifies.Add(exercise2);
- // }
- // ExerciseVerify exercise3 = new ExerciseVerify { TeamModelId = tmdid, RowKey = x.ShaCode + "-" + ShaHashHelper.GetSHA1(x.Explain), Type = 3, PartitionKey = Lang, Content = x.Explain, SummaryCode = x.ShaCode, Status = 1 };
- // exerciseVerifies.Add(exercise3);
- // });
- // await this.SaveOrUpdateAll(exerciseVerifies);
- //}
- public static List<ExerciseDto> SingleConvert(string TypeKey, string testHtml)
- {
- List<ExerciseDto> testInfos = OptionProcess(TypeKey, testHtml);
- return testInfos;
- }
- public static List<ExerciseDto> MultipleConvert(string TypeKey, string testHtml)
- {
- List<ExerciseDto> testInfos = OptionProcess(TypeKey, testHtml);
- return testInfos;
- }
- public static List<ExerciseDto> JudgeConvert(string TypeKey, string testHtml)
- {
- List<ExerciseDto> testInfos = OptionProcess(TypeKey, testHtml);
- return testInfos;
- }
- public static List<ExerciseDto> CompleteConvert(string TypeKey, string testHtml)
- {
- List<ExerciseDto> testInfos = CompleteProcess(TypeKey, testHtml);
- return testInfos;
- }
- public static List<ExerciseDto> SubjectiveConvert(string TypeKey, string testHtml)
- {
- List<string> tests = ConvertTest(testHtml);
- List<ExerciseDto> testInfos = ConvertTestInfo(tests, TypeKey);
- foreach (ExerciseDto testInfo in testInfos)
- {
- testInfo.Question = testInfo.Question.Replace(AnalysisTag, "").Replace(SummaryTag, "").Replace(AnswerTag, "");
- testInfo.Question = HtmlHelper.DoUselessTag(testInfo.Question);
- StringBuilder textImg = new StringBuilder(HtmlHelper.DoTextImg(testInfo.Question));
- testInfo.ShaCode = ShaHashHelper.GetSHA1(textImg.ToString());
- for (int i = 0; i < testInfo.Answer.Count; i++)
- {
- testInfo.Answer[i] = testInfo.Answer[i].Replace(AnswerTag, "").Replace(AnalysisTag, "");
- testInfo.Answer[i] = HtmlHelper.DoUselessTag(testInfo.Answer[i]);
- }
- testInfo.Explain = testInfo.Explain.Replace(AnalysisTag, "").Replace(EndedTag, "");
- testInfo.Explain = HtmlHelper.DoUselessTag(testInfo.Explain);
- }
- return testInfos;
- }
- public static List<ExerciseDto> CompleteProcess(string TypeKey, string testHtml)
- {
- List<string> tests = ConvertTest(testHtml);
- List<ExerciseDto> testInfos = ConvertTestInfo(tests, TypeKey);
- HtmlDocument doc = new HtmlDocument();
- foreach (ExerciseDto testInfo in testInfos)
- {
- List<string> ans = new List<string>();
- testInfo.Question = testInfo.Question.Replace(AnalysisTag, "").Replace(SummaryTag, "").Replace(AnswerTag, "");
- string regRex = CompleteStart + "([\\s\\S]*?)" + CompleteEnd;
- List<ReplaceDto> replaces = new List<ReplaceDto>();
- var m = Regex.Match(testInfo.Question, regRex);
- int index = 1;
- while (m.Success)
- {
- string an = m.Groups[1].ToString();
- doc.LoadHtml(an);
- string anstr = doc.DocumentNode.InnerText;
- string nbsp = "";
- int length = System.Text.Encoding.Default.GetBytes(anstr).Length;
- for (int i = 0; i < length * 3; i++)
- {
- nbsp += " ";
- }
- ReplaceDto replaceDto = new ReplaceDto { oldstr = "【" + an + "】", newstr = "<underline data=\"" + index + "\"><u>" + nbsp + "</u></underline>" };
- replaces.Add(replaceDto);
- ans.Add(an);
- m = m.NextMatch();
- index++;
- }
- string textImg = testInfo.Question;
- //消除答案
- foreach (ReplaceDto replace in replaces)
- {
- testInfo.Question = testInfo.Question.Replace(replace.oldstr, replace.newstr);
- testInfo.Question = HtmlHelper.DoUselessTag(testInfo.Question);
- //只要题干文字和图片
- //不加underline标记
- textImg = testInfo.Question.Replace(replace.oldstr, "");
- }
- textImg = HtmlHelper.DoTextImg(textImg);
- testInfo.ShaCode = ShaHashHelper.GetSHA1(textImg);
- //处理解析
- testInfo.Explain = testInfo.Explain.Replace(AnalysisTag, "").Replace(EndedTag, "");
- testInfo.Explain = HtmlHelper.DoUselessTag(testInfo.Explain);
- testInfo.Answer.AddRange(ans);
- }
- return testInfos;
- }
- /// <summary>
- /// 选择题处理
- /// </summary>
- /// <param name="TypeKey"></param>
- /// <param name="testHtml"></param>
- /// <returns></returns>
- public static List<ExerciseDto> OptionProcess(string TypeKey, string testHtml)
- {
- //处理 \t
- List<string> tests = ConvertTest(testHtml);
- string[] optionsKeys = Options.Select(s => s.ToString()).ToArray();
- List<ExerciseDto> testInfos = ConvertTestInfo(tests, TypeKey);
- foreach (ExerciseDto testInfo in testInfos)
- {
- string optsRgex = optionsKeys[0] + "(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?)" + AnswerTag;
- string optsHtml = Regex.Match(testInfo.Question, optsRgex).Value;
- //HtmlDocument doc = new HtmlDocument();
- //doc.LoadHtml(optsHtml);
- //optsHtml = doc.DocumentNode.InnerText;
- //处理选项
- StringBuilder textImg = new StringBuilder();
- for (int i = 0; i < optionsKeys.Length - 1; i++)
- {
- string optRgex = optionsKeys[i] + "(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?)" + optionsKeys[i + 1] + "(\\.|\\.|\\、|\\:|\\:)";
- string optHtml = Regex.Match(optsHtml, optRgex).Value;
- if (!string.IsNullOrEmpty(optHtml))
- {
- optHtml = optHtml.Substring(2, optHtml.Length - 4);
- optHtml = HtmlHelper.DoUselessTag(optHtml);
- textImg.Append(HtmlHelper.DoTextImg(optHtml));
- testInfo.Option.Add(new CodeValue { Code = optionsKeys[i], Value = optHtml });
- //testInfo.Option.Add(new Dictionary<string, string> { { "code", optionsKeys[i] },{ "value", optHtml } });
- //testInfo.Option.TryAdd(optionsKeys[i], optHtml);
- }
- else
- {
- optRgex = optionsKeys[i] + "(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?)" + AnswerTag;
- optHtml = Regex.Match(optsHtml, optRgex).Value;
- if (!string.IsNullOrEmpty(optHtml))
- {
- optHtml = optHtml.Substring(2, optHtml.Length - 6);
- optHtml = HtmlHelper.DoUselessTag(optHtml);
- textImg.Append(HtmlHelper.DoTextImg(optHtml));
- testInfo.Option.Add(new CodeValue { Code = optionsKeys[i], Value = optHtml });
- //testInfo.Option.Add(new Dictionary<string, string> { { "code", optionsKeys[i] }, { "value", optHtml } });
- //testInfo.Option.TryAdd(optionsKeys[i], optHtml);
- }
- }
- }
- //处理题干
- testInfo.Question = testInfo.Question.Replace(optsHtml, "").Replace(SummaryTag, "").Replace(AnswerTag, "");
- testInfo.Question = HtmlHelper.DoUselessTag(testInfo.Question);
- textImg.Append(HtmlHelper.DoTextImg(testInfo.Question));
- testInfo.ShaCode = ShaHashHelper.GetSHA1(textImg.ToString());
- List<string> answers = testInfo.Answer;
- HashSet<string> ans = new HashSet<string>();
- //处理答案
- for (int i = 0; i < answers.Count; i++)
- {
- string Answer = answers[i].Replace(AnswerTag, "").Replace(AnalysisTag, "").TrimStart().TrimEnd();
- Answer.Select(s => s.ToString()).ToList().ForEach(x =>
- {
- ans.Add(x);
- });
- }
- testInfo.Answer = ans.ToList();
- //处理解析
- testInfo.Explain = testInfo.Explain.Replace(AnalysisTag, "").Replace(EndedTag, "");
- testInfo.Explain = HtmlHelper.DoUselessTag(testInfo.Explain);
- }
- return testInfos;
- }
- public static List<ExerciseDto> ConvertTestInfo(List<string> tests, string TypeKey)
- {
- List<ExerciseDto> testInfos = new List<ExerciseDto>();
- foreach (string html in tests)
- {
- Dictionary<string, string> regex = new Dictionary<string, string>();
- Dictionary<string, string> question = new Dictionary<string, string> { { "Summary", SummaryTag + "|" + AnswerTag }, { "Answer", AnswerTag + "|" + AnalysisTag }, { "Analysis", AnalysisTag + "|" + EndedTag } };
- Dictionary<string, string> compquestion = new Dictionary<string, string> { { "Summary", SummaryTag + "|" + AnalysisTag }, { "Analysis", AnalysisTag + "|" + EndedTag } };
- ExerciseDto test = new ExerciseDto();
- test.Type = TypeKey;
- List<string> keys = new List<string>();
- if (TypeKey.Equals("Complete"))
- {
- keys = compquestion.Keys.ToList();
- regex = compquestion;
- }
- else
- {
- keys = question.Keys.ToList();
- regex = question;
- }
- foreach (string key in keys)
- {
- string[] tags = regex[key].Split("|");
- string RegexStr = tags[0] + "([\\s\\S]*?)" + tags[1];
- Match mt = Regex.Match(html, RegexStr);
- switch (key)
- {
- case "Summary":
- test.Question = mt.Value; break;
- case "Answer":
- string Answer = mt.Value;
- ///单选或多选,判断答案 脱html标签
- if (TypeKey.Equals("Single") || TypeKey.Equals("Multiple") || TypeKey.Equals("Judge"))
- {
- HtmlDocument doc = new HtmlDocument();
- doc.LoadHtml(mt.Value);
- Answer = doc.DocumentNode.InnerText;
- }
- test.Answer = new List<string>() { Answer }; break;
- case "Analysis":
- test.Explain = mt.Value; break;
- default: break;
- }
- }
- testInfos.Add(test);
- }
- return testInfos;
- }
- public static List<string> ConvertTest(string testHtml)
- {
- string start = SummaryTag;
- string end = EndedTag;
- List<string> tests = new List<string>();
- while (testHtml.IndexOf(start) > 0)
- {
- int indexStart = testHtml.IndexOf(start);
- int indexEnd = testHtml.IndexOf(end);
- string test = testHtml.Substring(indexStart, indexEnd - indexStart + start.Length);
- tests.Add(test);
- testHtml = testHtml.Substring(indexEnd + end.Length);
- }
- return tests;
- }
- }
- class ReplaceDto
- {
- public string oldstr { get; set; }
- public string newstr { get; set; }
- }
- }
|