public static OutputProblemInfo GetProblemInfoInner(string title) { var info = ProblemDao.GetProblem(title); if (info.Title == null) { throw new MySytemException(); } var dir = problem_path + title; var result = new OutputProblemInfo { SimpleInfo = info }; using (FileStream fs = new FileStream(dir + content_path, FileMode.Open, FileAccess.Read)) { StreamReader reader = new StreamReader(fs); result.Content = reader.ReadToEnd(); } using (FileStream fs = new FileStream(dir + test_case_path, FileMode.OpenOrCreate, FileAccess.Read)) { StreamReader reader = new StreamReader(fs); result.TestCase = reader.ReadToEnd(); } using (FileStream fs = new FileStream(dir + right_result_path, FileMode.OpenOrCreate, FileAccess.Read)) { StreamReader reader = new StreamReader(fs); result.RightResult = reader.ReadToEnd(); } return(result); }
public static void Judge(string code, int user_id, string problem_title, string lang) { OutputProblemInfo info = ProblemServices.GetProblemInfoInner(problem_title); var uuid = Guid.NewGuid().ToString("N"); var l = GetLanguage(lang); Submission submission = new Submission { Code = code, ProblemId = info.SimpleInfo.ProblemId, Uuid = uuid, UserId = user_id, Lang = l.ToString() }; SubmissionDao.AddSubmission(submission); Task task = new Task(() => { submission.Status = JudgeCore.JudgeStatus.Running.ToString(); SubmissionDao.ChangeSubmissionStatus(submission); var simple_info = info.SimpleInfo; JudgeCore.ProblemInfo judge_info = new JudgeCore.ProblemInfo() { code = submission.Code, max_mem = simple_info.MaxMemory, max_time = simple_info.MaxTime, uuid = uuid, right_result = info.RightResult, test_case = info.TestCase, language = l }; var result = JudgeCore.Judger.judge(judge_info); submission.Status = result.status.ToString(); submission.Time = result.time; submission.Memory = result.memory; SubmissionDao.SetResult(submission); }); task.Start(); }