public void StartJudge() { loop2: if (IsWork == false) { return; } try { RunIDService.Update(RunID); List <Solution> solutions = SolutionService.SelectByIsJudged(RunID); solCount = (uint)solutions.Count(); if (solCount == 0) { goto loop2; } foreach (Solution solution in solutions) { ParaPair pp = new ParaPair(); pp.dlg = StartJudge; pp.slt = solution; if (ojs[(int)solution.OJID - 1].IsWork) { ThreadPool.QueueUserWorkItem(Run, pp); } //Run(solution); } } catch (Exception e) { LogService.Insert(2, e); } }
public void Run(object obj) { try { ParaPair pp = (ParaPair)obj; Solution solution = pp.slt; int index = (int)solution.OJID - 1; string code = (index == 2 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(solution.SourceCode)) : solution.SourceCode); string pid = (index == 3 ? (Convert.ToUInt32(solution.OJProblemID) - 1000).ToString() : solution.OJProblemID); string status = "Pending"; string time = "", memory = "", compiler = "", runid = ""; string pattern = ojs[index].PatternStatus; Regex regex = new Regex(pattern); List <int> order = ojs[index].MatchOrder; int sid = Choose(index); HttpHelper.Submit(ojs[index].UrlSubmit, ojs[index].UrlSubmitPart1 + pid + ojs[index].UrlSubmitPart2 + solution.OJCompilerID + ojs[index].UrlSubmitPart3 + HttpUtility.UrlEncode(code) + ojs[index].UrlSubmitPart4, ojs[index].CookieContainers[sid], header); loop3: bool ok = false; while (ok == false) { string html = HttpHelper.GetHtml( ojs[index].UrlStatus + ojs[index].Senders[sid].Username, new CookieContainer(), header); Match m = regex.Match(html); status = m.Groups[order[0]].ToString(); if (ojs[index].Statuses.Contains(status)) { runid = m.Groups[order[1]].ToString(); time = m.Groups[order[2]].ToString(); memory = m.Groups[order[3]].ToString(); compiler = m.Groups[order[5]].ToString(); ok = true; } } solution.Status = status; solution.CompilerName = compiler; solution.RunTime = (index == 3 ? time + "MS" : time); solution.RunTime = solution.RunTime.Replace(" ", ""); solution.RunMemory = (index == 3 ? memory + "K" : memory); solution.RunMemory = solution.RunMemory.Replace(" ", ""); solution.OJRunID = runid; solution.IsJudged = true; solution.IsAccepted = (status == "Accepted"); if (SolutionService.SelectByOJRunID((int)solution.OJID, solution.OJRunID)) { UpdateStatus(ojs[index].OJName + " " + solution.OJRunID + " is Existing"); goto loop3; } else { SolutionService.Update(solution); UpdateStatus(ojs[index].OJName + " " + solution.OJRunID + " " + status); } lock (RunID as object) { RunID = Math.Max(RunID, solution.SolutionID); } lock (solCount as object) { solCount--; if (solCount == 0) { pp.dlg(); } } ojs[index].QSenders.Enqueue(sid); } catch (Exception e) { LogService.Insert(2, e); } }