using Entities.DTO; using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace TechHelper.Client.Exam { // --- 新增错误处理相关类 --- public class ParseError { public ParseErrorType Type { get; } public string Message { get; } public int? Index { get; } // 错误发生的文本索引或匹配项索引 public string MatchedText { get; } // 如果与某个匹配项相关,记录其文本 public Exception InnerException { get; } // 捕获到的原始异常 public ParseError(ParseErrorType type, string message, int? index = null, string matchedText = null, Exception innerException = null) { Type = type; Message = message; Index = index; MatchedText = matchedText; InnerException = innerException; } public override string ToString() { var sb = new System.Text.StringBuilder(); sb.Append($"[{Type}] {Message}"); if (Index.HasValue) sb.Append($" (Index: {Index.Value})"); if (!string.IsNullOrEmpty(MatchedText)) sb.Append($" (MatchedText: '{MatchedText}')"); if (InnerException != null) sb.Append($" InnerException: {InnerException.Message}"); return sb.ToString(); } } public enum ParseErrorType { Validation = 1, // 输入验证失败 DataParsing = 2, // 数据解析失败(如数字转换) Structural = 3, // 结构性问题(如选项没有对应的问题) RegexMatchIssue = 4, // 正则表达式匹配结果不符合预期 UnexpectedError = 5 // 未预料到的通用错误 } public class ExamPaper { public string AssignmentTitle { get; set; } = "未识别试卷标题"; public string Description { get; set; } = "未识别试卷描述"; public string SubjectArea { get; set; } = "试卷类别"; public List QuestionGroups { get; set; } = new List(); public List TopLevelQuestions { get; set; } = new List(); public List Errors { get; set; } = new List(); } public class MajorQuestionGroup { public string Title { get; set; } = string.Empty; public string Descript { get; set; } = string.Empty; public float Score { get; set; } public List SubQuestionGroups { get; set; } = new List(); public List SubQuestions { get; set; } = new List(); public int Priority { get; set; } public bool bGroup { get; set; } = true; } public class PaperQuestion { public string Number { get; set; } = string.Empty; public string Stem { get; set; } = string.Empty; public float Score { get; set; } public List