123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584 |
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.Models;
- using TEAMModelOS.SDK.DI;
- using System.Text.Json;
- using TEAMModelOS.SDK.Models;
- using Microsoft.AspNetCore.Http;
- using TEAMModelOS.SDK.Extension;
- using Azure.Cosmos;
- using System.Text;
- using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
- using Microsoft.Extensions.Options;
- using Azure.Messaging.ServiceBus;
- using Microsoft.Extensions.Configuration;
- using HTEXLib.COMM.Helpers;
- using TEAMModelOS.SDK;
- using System.IdentityModel.Tokens.Jwt;
- using TEAMModelOS.Services;
- using TEAMModelOS.SDK.Models.Service;
- using System.IO;
- using System.Dynamic;
- using Microsoft.AspNetCore.Authorization;
- using Azure.Storage.Blobs.Models;
- using static TEAMModelOS.SDK.Models.Teacher;
- using System.Web;
- using static TEAMModelOS.Controllers.FixDataController;
- using static TEAMModelOS.SDK.SchoolService;
- using Microsoft.AspNetCore.Hosting;
- using TEAMModelOS.Filter;
- using TEAMModelOS.Controllers.Third.Xkw;
- using Microsoft.Extensions.Primitives;
- using System.Net.Http;
- using TEAMModelOS.Controllers.Third.Xkw.Sdk;
- using TEAMModelOS.SDK.Models.Table;
- using System.Text.RegularExpressions;
- using HtmlAgilityPack;
- using TEAMModelOS.SDK.Helper.Security.ShaHash;
- namespace TEAMModelOS.Controllers.Third.Xkw
- {
- // <summary>
- /// 标准OAuth2
- /// </summary>
- ///
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- //
- //[Route("")]
- [Route("xkw")]
- [ApiController]
- public class XkwServiceController: ControllerBase
- {
- private readonly SnowflakeId _snowflakeId;
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly AzureServiceBusFactory _serviceBus;
- private readonly AzureRedisFactory _azureRedis;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly ThirdApisService _scsApisService;
- private readonly HttpTrigger _httpTrigger;
- private readonly IWebHostEnvironment _environment;
- private readonly XkwAPIHttpService _xkwAPIHttpService;
- /// <summary>
- /// 全角
- /// </summary>
- string[] aza = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
- /// <summary>
- /// 半角
- /// </summary>
- string[] azh = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
- public IConfiguration _configuration { get; set; }
- public XkwServiceController(XkwAPIHttpService xkwAPIHttpService, IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
- AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, ThirdApisService scsApisService, HttpTrigger httpTrigger)
- {
- _azureCosmos = azureCosmos;
- _snowflakeId = snowflakeId;
- _dingDing = dingDing;
- _option = option?.Value;
- _azureStorage = azureStorage;
- _serviceBus = serviceBus;
- _configuration = configuration;
- _azureRedis = azureRedis;
- _coreAPIHttpService = coreAPIHttpService;
- _scsApisService = scsApisService;
- _httpTrigger = httpTrigger;
- _environment = environment;
- _xkwAPIHttpService=xkwAPIHttpService;
- }
- [HttpGet("get-xkw-baseinfo")]
- //[Authorize(Roles = "IES")]
- //[AuthToken(Roles = "teacher,admin,area,student")]
- public async Task<IActionResult> GetXkwBaseInfo([FromQuery] OAuthCode authCode)
- {
- //var courses = _xkwAPIHttpService.Get<JsonElement>("/xopqbm/courses/all", null);
- List<XkwQuestionType> questionTypes = new List<XkwQuestionType>();
- XkwConstant.xkwCourses.ForEach(x =>
- {
- Dictionary<string, string> dict = new Dictionary<string, string>() { { "course_id", $"{x.id}" } };
- var question_types = _xkwAPIHttpService.Get<JsonElement>($"/xopqbm/question-types", dict);
- if (question_types.TryGetProperty("code", out JsonElement code) && $"{code}".Equals("2000000"))
- {
- questionTypes.AddRange(question_types.GetProperty("data").ToObject<List<XkwQuestionType>>());
- }
- });
- return Ok(questionTypes);
- }
- [HttpGet("paper-notice")]
- //[Authorize(Roles = "IES")]
- //[AuthToken(Roles = "teacher,admin,area,student")]
- public async Task<IActionResult> PaperNotice([FromQuery] OAuthCode authCode)
- {
- await _dingDing.SendBotMsg($"学科网推送消息:{authCode.ToJsonString()}", GroupNames.成都开发測試群組);
- return Ok(authCode);
- }
- //paperid=85602892&openid=open-322-TPllGeMdvY 包含填空题 综合题,判断题
- // paperid=85621779&openid=open-322-TPllGeMdvY 综合题
- [HttpPost("get-paper-items")]
- #if DEBUG
- #else
- [Authorize(Roles = "IES")]
- [AuthToken(Roles = "teacher,admin,area,student")]
- #endif
- public async Task<IActionResult> GetPaperItems(JsonElement json)
- {
- try
- {
- if (!json.TryGetProperty("paperid", out JsonElement paperid)) { return BadRequest(); }
- if (!json.TryGetProperty("openid", out JsonElement openid)) { return BadRequest(); }
- Dictionary<string, string> dict = new Dictionary<string, string>() { { "id", $"{paperid}" }, { "user_id", $"{openid}" } };
- var paper = _xkwAPIHttpService.Get<JsonElement>("/xopqbm/zj-saas/users/download-papers/details", dict);
- List<XkwItem> items = new List<XkwItem>();
- string ps = paper.ToJsonString();
- XkwDto course = null;
- List<XkwPaperPart> xkwPapers = new List<XkwPaperPart>();
- if (paper.TryGetProperty("code", out JsonElement code) && $"{code}".Equals("2000000"))
- {
- if (paper.TryGetProperty("data", out JsonElement data) && data.TryGetProperty("course_id", out JsonElement course_id))
- {
- course = XkwConstant.xkwCourses.Find(x => $"{course_id}".Equals($"{x.id}"));
- if (course != null)
- {
- if (data.TryGetProperty("body", out JsonElement body))
- {
- List<XkwPaperPart> paperParts = body.ToObject<List<XkwPaperPart>>();
- xkwPapers.AddRange(paperParts);
- items.AddRange(paperParts.SelectMany(x => x.part_body).SelectMany(z => z.questions));
- }
- }
- }
- }
- List<XkwItemInfo> itemInfos = new List<XkwItemInfo>();
- List<XkwDto> xkw_points = new List<XkwDto>();
- var kpoint_ids = items.Where(z=>z.kpoint_ids!=null).SelectMany(x => x.kpoint_ids).ToHashSet();
- if (kpoint_ids.Any())
- {
- Dictionary<string, string> dict_pointids = new Dictionary<string, string>() { { "ids", String.Join(",", kpoint_ids.Select(x => x)) } };
- var points = _xkwAPIHttpService.Get<JsonElement>("/xopqbm/knowledge-points", dict_pointids);
- if (points.TryGetProperty("code", out JsonElement pcode) && $"{pcode}".Equals("2000000"))
- {
- if (points.TryGetProperty("data", out JsonElement pdata))
- {
- xkw_points = pdata.ToObject<List<XkwDto>>();
- }
- }
- }
- int index = 1;
- items.ForEach(x => {
- //x.kpoint_ids
- //设置默认难度,和默认认知层次
- int field = 1;
- int level = 3;
- List<string> gradeNames = new List<string>();
- List<string> knowledge = new List<string>();
- bool objective = false;
- string tag = "";
- foreach (var difct in XkwConstant.xkwDifficulties)
- {
- if (x.difficulty < difct.ceiling && x.difficulty >= difct.flooring)
- {
- level = difct.level;
- }
- }
- var grades = XkwConstant.xkwGrades.FindAll(g =>x.grade_ids!=null && x.grade_ids.Contains(g.id));
- if (grades.IsNotEmpty())
- {
- gradeNames = grades.Select(g => g.name).ToList();
- }
- if (x.kpoint_ids.IsNotEmpty())
- {
- var points = xkw_points.FindAll(p => x.kpoint_ids.Contains(p.id));
- if (points.Any())
- {
- knowledge.AddRange(points.Select(x => x.name));
- }
- }
- var type = XkwConstant.xkwQuestionTypes.Find(t => t.id == x.type_id);
- //判断是否 主客观题
- if (type != null)
- {
- objective = type.objective;
- tag = type.name;
- }
- else
- {
- objective = false;
- }
- string classpattern = "class=\"([^\"]*)\"";
- string pattern = "<span([^>]{0,})>";
- string table_pattern = "<table([^>]{0,})>";
- string apattern = "<a([^>]{0,})></a>";
- string rg_qml_sq = "<div[^>]{0,}\\s*qml-sq[^>]{0,}>";
- //string stem = x.stem.Replace("</table>", "");
- string[] questiones = Regex.Split(x.stem, rg_qml_sq);
- string rg_qml_an_sq = "\\d+\\s*\\.\\s*<span[^>]{0,}\\s*qml-an-sq[^>]{0,}>" +
- "|(\\d+\\s*)\\s*<span[^>]{0,}\\s*qml-an-sq[^>]{0,}>" +
- "|\\d+\\s*<span[^>]{0,}\\s*qml-an-sq[^>]{0,}>" +
- "|(\\d+\\s*)\\s*<span[^>]{0,}\\s*qml-an-sq[^>]{0,}>";
- var answers = Regex.Split(x.answer, rg_qml_an_sq);
- string rg_qml_exps_sq = "<div[^>]{0,}\\s*exps-sq[^>]{0,}>";
- var explains = Regex.Split(x.explanation, rg_qml_exps_sq);
- if (questiones.Length > 1)
- {
- index += 1;
- XkwItemInfo itemInfo = new XkwItemInfo
- {
- source = 3,
- shaCode = ShaHashHelper.GetSHA1(x.stem),
- id = x.id,
- order = index,
- subjectName = course?.subject_name,
- periodName = course?.stage_name,
- field = field,
- level = level,
- gradeNames = gradeNames,
- knowledge = knowledge,
- objective = objective,
- tag = tag,
- question = questiones[0],
- type = "compose",
- };
- itemInfos.Add(itemInfo);
- for (int i = 1; i < questiones.Length; i++)
- {
- index += 1;
- XkwItemInfo child_itemInfo = new XkwItemInfo
- {
- pid = x.id,
- source = 3,
- id = $"{x.id}-{i}",
- order = index,
- subjectName = course?.subject_name,
- periodName = course?.stage_name,
- field = field,
- level = level,
- gradeNames = gradeNames,
- knowledge = knowledge,
- objective = objective,
- tag = "",
- };
- questiones[i] = questiones[i].Replace("<div class=\"qml-stem\"><br/>", "");
- if (questiones[i].Contains("qml-og"))
- {
- child_itemInfo.objective = true;
- string shtml = questiones[i];
- //去除class 以及span标签"
- // shtml = Regex.Replace(shtml, table_pattern, "").Replace("</table>", "").Replace("<tr>", "").Replace("<td>", "").Replace("</td>", "").Replace("</tr>", "");
-
-
- //shtml = Regex.Replace(shtml, classpattern, "");
- //shtml = Regex.Replace(shtml, pattern, "");
- //shtml = Regex.Replace(shtml, apattern, "");
- //shtml = shtml.Replace(" close=\"\" separators=\" | \">", "");
- //shtml = shtml.Replace("\t", " ").Replace("<span>", "").Replace("</span>", "").Replace("dir=\"ltr\"", "");
- //处理 标签中包含的空格字符
- //处理题干
- (List<CodeValue> options, string question) = OptionProcess(shtml);
- child_itemInfo.option = options;
- child_itemInfo.opts = options.Count;
- child_itemInfo.question = question;
- //处理答案
- //去除class 以及span标签"
- if (answers.Length - 1 >= i)
- {
- string ahtml = answers[i];
- ahtml = Regex.Replace(ahtml, classpattern, "");
- ahtml = Regex.Replace(ahtml, pattern, "");
- ahtml = Regex.Replace(ahtml, apattern, "");
- ahtml = ahtml.Replace(" close=\"\" separators=\" | \">", "");
- ahtml = ahtml.Replace("\t", " ").Replace("<span>", "").Replace("</span>", "").Replace("dir=\"ltr\"", "");
- HashSet<string> ans = new HashSet<string>();
- var anstr = BlankTag(ahtml);
- for (int idx = 0; idx < 26; idx++)
- {
- anstr = anstr.Replace(aza[idx], azh[idx]);
- }
- anstr.Select(s => s.ToString()).ToList().ForEach(x =>
- {
- ans.Add(x);
- });
- child_itemInfo.answerHtml = answers[0];
- child_itemInfo.answer = ans.ToList();
- child_itemInfo.objective = true;
- if (child_itemInfo.opts > 0)
- {
- if (ans.Count > 1)
- {
- child_itemInfo.type = "multiple";
- }
- else
- {
- child_itemInfo.type = "single";
- }
- }
- else
- {
- if (child_itemInfo.answer.Any()
- &&(child_itemInfo.answer.First().Equals("√") || child_itemInfo.answer.First().Equals("×")
- || child_itemInfo.answer.First().Equals("对") || child_itemInfo.answer.First().Equals("错")
- || child_itemInfo.answer.First().Equals("正确") || child_itemInfo.answer.First().Equals("错误")))
- {
- child_itemInfo.type = "judge";
- child_itemInfo.opts = 2;
- child_itemInfo.option = new List<CodeValue>() { new CodeValue { code = "A", value = "对" }, new CodeValue { code = "B", value = "错" } };
- child_itemInfo.answer = itemInfo.answer.First().Equals("√") || child_itemInfo.answer.First().Equals("对")|| child_itemInfo.answer.First().Equals("正确") ? new List<string> { "A" } : new List<string> { "B" };
- }
- else
- {
- child_itemInfo.objective = false;
- child_itemInfo.type = "subjective";
- }
- }
- }
- //处理解析
- if (explains.Length - 1 >= i)
- {
- child_itemInfo.explain = explains[i];
- }
- }
- else
- {
- child_itemInfo.type = "subjective";
- child_itemInfo.objective = false;
- if (explains.Length - 1 >= i)
- {
- child_itemInfo.explain = explains[i];
- }
- string ansstr = "";
- if (answers.Length - 1 >= i)
- {
- child_itemInfo.answer = new List<string> { answers[i] };
- ansstr = HtmlHelper.DoUselessTag(answers[i]);
- }
- child_itemInfo.question = questiones[i];
- if (ansstr.Equals("√") || ansstr.Equals("×")
- || ansstr.Equals("对") || ansstr.Equals("错")
- || ansstr.Equals("正确") || ansstr.Equals("错误"))
- {
- child_itemInfo.objective = true;
- child_itemInfo.type = "judge";
- child_itemInfo.opts = 2;
- child_itemInfo.option = new List<CodeValue>() { new CodeValue { code = "A", value = "对" }, new CodeValue { code = "B", value = "错" } };
- child_itemInfo.answer = ansstr.Equals("√") || ansstr.Equals("对") || ansstr.Equals("正确") ? new List<string> { "A" } : new List<string> { "B" };
- }
- }
- string rg_ques_no = "<span[^>]{0,}\\s*ques-no[^>]{0,}>[\\s\\S]*?</span>";
- child_itemInfo.question = Regex.Replace(child_itemInfo.question, rg_ques_no, "");
- child_itemInfo.shaCode = ShaHashHelper.GetSHA1(child_itemInfo.question);
- itemInfo.children.Add(child_itemInfo);
- //itemInfos.Add(child_itemInfo);
- }
- }
- else
- {
- XkwItemInfo itemInfo = new XkwItemInfo
- {
- source = 3,
- shaCode = ShaHashHelper.GetSHA1(x.stem),
- id = x.id,
- order = index,
- explain = x.explanation,
- subjectName = course?.subject_name,
- periodName = course?.stage_name,
- // explain = x.explanation.Replace("【分析】", "分析:").Replace("【详解】", "详解:")
- field = field,
- level = level,
- gradeNames = gradeNames,
- knowledge = knowledge,
- objective = objective,
- tag = tag
- };
- index += 1;
- //如果是客观题,则需要处理选项和答案。
- if (itemInfo.objective)
- {
- string shtml = x.stem;
- //去除class 以及span标签"
- // shtml = Regex.Replace(shtml, table_pattern, "").Replace("</table>", "").Replace("<tr>", "").Replace("<td>", "").Replace("</td>", "").Replace("</tr>", "");
-
-
-
- //shtml = Regex.Replace(shtml, classpattern, "");
- //shtml = Regex.Replace(shtml, pattern, "");
- //shtml = Regex.Replace(shtml, apattern, "");
- //shtml = shtml.Replace(" close=\"\" separators=\" | \">", "");
- //shtml = shtml.Replace("\t", " ").Replace("<span>", "").Replace("</span>", "").Replace("dir=\"ltr\"", "");
- //处理 标签中包含的空格字符
- //处理题干
- (List<CodeValue> options, string question) = OptionProcess(shtml);
- itemInfo.option = options;
- itemInfo.opts = options.Count;
- itemInfo.question = question;
- itemInfo.objective = true;
- //处理答案
- //去除class 以及span标签"
- string ahtml = x.answer;
- ahtml = Regex.Replace(ahtml, classpattern, "");
- ahtml = Regex.Replace(ahtml, pattern, "");
- ahtml = Regex.Replace(ahtml, apattern, "");
- ahtml = ahtml.Replace(" close=\"\" separators=\" | \">", "");
- ahtml = ahtml.Replace("\t", " ").Replace("<span>", "").Replace("</span>", "").Replace("dir=\"ltr\"", "");
- HashSet<string> ans = new HashSet<string>();
- var anstr = BlankTag(ahtml);
- for (int idx = 0; idx < 26; idx++)
- {
- anstr = anstr.Replace(aza[idx], azh[idx]);
- }
- anstr.Select(s => s.ToString()).ToList().ForEach(x =>
- {
- ans.Add(x);
- });
- itemInfo.answerHtml = x.answer;
- itemInfo.answer = ans.ToList();
- if (itemInfo.opts > 0)
- {
- if (ans.Count > 1)
- {
- itemInfo.type = "multiple";
- }
- else
- {
- itemInfo.type = "single";
- }
- }
- else {
- if (itemInfo.answer.Any()
- && (itemInfo.answer.First().Equals("√") || itemInfo.answer.First().Equals("×")
- || itemInfo.answer.First().Equals("对") || itemInfo.answer.First().Equals("错")
- || itemInfo.answer.First().Equals("正确") || itemInfo.answer.First().Equals("错误")))
- {
- itemInfo.type = "judge";
- itemInfo.opts = 2;
- itemInfo.option = new List<CodeValue>() { new CodeValue { code = "A", value = "对" }, new CodeValue { code = "B", value = "错" } };
- itemInfo.answer = itemInfo.answer.First().Equals("√") || itemInfo.answer.First().Equals("对") || itemInfo.answer.First().Equals("正确") ? new List<string> { "A" } : new List<string> { "B" };
- }
- else
- {
- itemInfo.objective = false;
- itemInfo.type = "subjective";
- }
- }
-
- }
- else
- {
- itemInfo.type = "subjective";
- itemInfo.question = x.stem;
- itemInfo.answer = new List<string>() { HtmlHelper.DoUselessTag(x.answer.ToString()) };
- if (itemInfo.answer.First().Equals("√") || itemInfo.answer.First().Equals("×")
- || itemInfo.answer.First().Equals("对") || itemInfo.answer.First().Equals("错")
- || itemInfo.answer.First().Equals("正确") || itemInfo.answer.First().Equals("错误"))
- {
- itemInfo.objective = true;
- itemInfo.type = "judge";
- itemInfo.opts = 2;
- itemInfo.option = new List<CodeValue>() { new CodeValue { code = "A", value = "对" }, new CodeValue { code = "B", value = "错" } };
- itemInfo.answer = itemInfo.answer.First().Equals("√") || itemInfo.answer.First().Equals("对") || itemInfo.answer.First().Equals("正确") ? new List<string> { "A" } : new List<string> { "B" };
- }
- }
- itemInfos.Add(itemInfo);
- }
- });
- HashSet<string> gradeNames = new HashSet<string>();
- gradeNames = itemInfos.SelectMany(x => x.gradeNames).ToHashSet();
- // await _dingDing.SendBotMsg($"学科网推送消息:{authCode.ToJsonString()}", GroupNames.成都开发測試群組);
- return Ok(new { xkwPapers, periodName = course.stage_name, subjectName = course.subject_name, gradeNames, knowledge = xkw_points.Select(x => x.name), itemInfos, paper });
- } catch (Exception ex) {
- if (ex.Message.Contains("客户已关闭") || ex.Message.Contains("403")||ex.Message.Contains("参数无效"))
- {
- return Ok(new { error = 403, message="学科网该账号授权已到期!" });
- }
- else
- {
- await _dingDing.SendBotMsg($"学科网组卷错误:{ex.Message}\n{ex.StackTrace}\n{json.ToJsonString()}", GroupNames.成都开发測試群組);
- return BadRequest($"学科网组卷错误:{ex.Message}\n{ex.StackTrace}\n{json.ToJsonString()}");
- }
-
- }
- }
- private string BlankTag(string tagHtml)
- {
- //去掉标签中的Html
- HtmlDocument doc = new HtmlDocument();
- doc.LoadHtml(tagHtml);
- var tagValue = doc.DocumentNode.InnerText.Replace("{", "").Replace("}", "")
- .Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "")
- .Replace(" ", "").Replace(" ", "").Replace(" ", "");
- // tagValue = Regex.Replace(tagValue, @"\d", "");
- tagValue = Regex.Replace(tagValue, @"\s", "");
- return tagValue;
- }
- public (List<CodeValue> options, string question) OptionProcess(string question) {
- string Options = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- string[] optionsKeys = Options.Select(s => s.ToString()).ToArray();
- for (int idx = 0; idx < 26; idx++)
- {
- question = question.Replace(aza[idx], azh[idx]);
- }
- List<CodeValue> options = new List<CodeValue>();
- string optsRgex = optionsKeys[0] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?).*"; ;
- string optsHtml = Regex.Match(question, optsRgex).Value;
- StringBuilder textImg = new StringBuilder();
- for (int i = 0; i < optionsKeys.Length - 1; i++)
- {
- string optRgex = optionsKeys[i] + "\\s*(\\.|\\.|\\、|\\:|\\:)([\\s\\S]*?)" + optionsKeys[i + 1] + "\\s*(\\.|\\.|\\、|\\:|\\:)";
- string optHtml = Regex.Match(optsHtml, optRgex).Value;
- if (string.IsNullOrWhiteSpace(optHtml))
- {
- optRgex = optionsKeys[i] + "\\s*(\\.|\\.|\\、|\\:|\\:).*";
- optHtml = Regex.Match(optsHtml, optRgex).Value;
- }
- if (!string.IsNullOrEmpty(optHtml))
- {
- optHtml = Regex.Replace(optHtml, optionsKeys[i + 1] + "\\s*(\\.|\\.|\\、|\\:|\\:)", "");
- optHtml = optHtml.Substring(2, optHtml.Length - 2);
- optHtml = HtmlHelper.DoUselessTag(optHtml);
- optHtml = optHtml.TrimStart().TrimEnd();
- textImg.Append(HtmlHelper.DoTextImg(optHtml));
- string table_pattern = "<table([^>]{0,})>";
- optHtml = Regex.Replace(optHtml, table_pattern, "").Replace("</table>", "").Replace("<tr>", "").Replace("<td>", "").Replace("</td>", "").Replace("</tr>", "");
- options.Add(new CodeValue { code = optionsKeys[i], value = optHtml });
- }
- }
- if (!string.IsNullOrWhiteSpace(optsHtml))
- { question = question.Replace(optsHtml, "").Replace("<table class=\"qml-og\" style=\"width:100%\"><tr><td>", "");
- return (options, question);
- }
- else
- {
- question= question.Replace("<table class=\"qml-og\" style=\"width:100%\"><tr><td>","");
- return (new List<CodeValue>(), question);
- }
- }
- }
- }
|