public static void StartJudge() { loop2: 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; ThreadPool.QueueUserWorkItem(Run, pp); } } catch (Exception e) { LogService.Insert(2, e); } }
public static 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(reXSS(solution.SourceCode))) : reXSS(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); bool ok = false; List <int> order = ojs[index].MatchOrder; int sid = Choose(index); if (index == 1) { CookieContainer cookieContainer = HttpHelper.GetCooKie(ojs[index].UrlLogin, ojs[index].UrlLoginPart1 + ojs[index].Senders[0].Username + ojs[index].UrlLoginPart2 + ojs[index].Senders[0].Password, header); HttpHelper.Submit(ojs[index].UrlSubmit, ojs[index].UrlSubmitPart1 + pid + ojs[index].UrlSubmitPart2 + solution.OJCompilerID + ojs[index].UrlSubmitPart3 + HttpUtility.UrlEncode(code) + ojs[index].UrlSubmitPart4, cookieContainer, header); } else { 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); } 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.IsJudged = true; solution.IsAccepted = false; if (status == "Accepted") { solution.IsAccepted = true; ContestProblemService.UpdateAccepted(solution.ContestProblemID); } SolutionService.Update(solution); Console.WriteLine(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); } }