Exemple #1
0
        public void JudgeFeedBack(JudgeFeedback jfb)
        {
            if (Online.FindIndex(x => x.Token == Context.ConnectionId) < 0)
            {
                return;
            }
            var jt = DbContext.JudgeTasks.Find(jfb.ID);

            jt.Hint        = jfb.Hint;
            jt.MemoryUsage = jfb.MemoryUsage;
            jt.TimeUsage   = jfb.TimeUsage;
            jt.Result      = jfb.Result;
            DbContext.SaveChanges();
            ThreadFree();
            if (jt.Status.JudgeTasks.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Running || x.ResultAsInt == (int)Entity.JudgeResult.Pending).Count() == 0)
            {
                jt.Status.ResultAsInt = jt.Status.JudgeTasks.Max(x => x.ResultAsInt);
                DbContext.SaveChanges();
                var contest = jt.Status.Problem.Contest;
                if (DateTime.Now >= contest.Begin && DateTime.Now < contest.End)
                {
                    SignalR.CodeCombHub.context.Clients.All.onStandingsChanged(contest.ID, new Models.View.Standing(jt.Status.User, contest));
                }
            }
            else
            {
                jt.Status.Result = Entity.JudgeResult.Running;
                DbContext.SaveChanges();
            }
            SignalR.CodeCombHub.context.Clients.All.onStatusChanged(new Models.View.Status(jt.Status));//推送新状态
        }
Exemple #2
0
 public static void Feedback(JudgeFeedback jfb)
 {
     Program.hubJudge.Invoke("JudgeFeedBack", jfb);
     Program.CurrentThreads--;
     try
     {
         if (System.IO.Directory.Exists(Program.TempPath + @"\" + jfb.ID))
         {
             System.IO.Directory.Delete(Program.TempPath + @"\" + jfb.ID, true);
         }
     }
     catch { }
 }
Exemple #3
0
        public void JudgeFeedBack(JudgeFeedback jfb)
        {
            if (Online.FindIndex(x => x.Token == Context.ConnectionId) < 0)
            {
                return;
            }
            var jt = DbContext.JudgeTasks.Find(jfb.ID);

            jt.Hint        = jfb.Hint;
            jt.MemoryUsage = jfb.MemoryUsage;
            jt.TimeUsage   = jfb.TimeUsage;
            jt.Result      = jfb.Result;
            DbContext.SaveChanges();
            ThreadFree();
            if (jt.Status.JudgeTasks.Where(x => x.ResultAsInt == (int)JudgeResult.Running || x.ResultAsInt == (int)JudgeResult.Pending).Count() == 0)
            {
                jt.Status.ResultAsInt = jt.Status.JudgeTasks.Max(x => x.ResultAsInt);
                jt.Status.MemoryUsage = jt.Status.JudgeTasks.Max(x => x.MemoryUsage);
                jt.Status.TimeUsage   = jt.Status.JudgeTasks.Sum(x => x.TimeUsage);
                jt.Status.Score       = jt.Status.JudgeTasks.Where(x => x.Result == JudgeResult.Accepted).Count() * 100 / jt.Status.JudgeTasks.Count;
                DbContext.SaveChanges();

                if (jt.Status.Result == JudgeResult.Accepted && jt.Status.ContestID == null)
                {
                    var aclist = Helpers.AcList.GetList(jt.Status.User.AcceptedList);
                    aclist.Add(jt.Status.ProblemID);
                    jt.Status.User.AcceptedList  = Helpers.AcList.ToString(aclist);
                    jt.Status.User.AcceptedCount = aclist.Count();
                    jt.Status.Problem.AcceptedCount++;
                    DbContext.SaveChanges();
                }
                var contest = jt.Status.Contest;
                if (contest != null && DateTime.Now >= contest.Begin && DateTime.Now < contest.End)
                {
                    SignalR.UserHub.context.Clients.Group("Standings").onStandingsChanged(contest.ID, new vStanding(jt.Status.User, contest));
                }
            }
            if (jt.Status.ContestID != null && jt.Status.Contest.Format == ContestFormat.OI && DateTime.Now >= jt.Status.Contest.Begin && DateTime.Now < jt.Status.Contest.End)
            {
                var tmp = jt.Status;
                tmp.Result = JudgeResult.Hidden;
                SignalR.UserHub.context.Clients.Group("Status").onStatusChanged(new vStatus(tmp));//推送新状态
            }
            else
            {
                SignalR.UserHub.context.Clients.Group("Status").onStatusChanged(new vStatus(jt.Status));//推送新状态
            }
            GC.Collect();
        }
Exemple #4
0
        public static void Judge(JudgeTask jt)
        {
            while (Program.CurrentThreads >= Program.MaxThreads)
            {
                System.Threading.Thread.Sleep(500);
            }

            Program.CurrentThreads++;

            JudgeFeedback jfb = new JudgeFeedback()
            {
                ID          = jt.ID,
                MemoryUsage = 0,
                TimeUsage   = 0,
                Success     = false
            };

            try
            {
                CheckPath(jt.ID);

                if (!FileExisted(jt.DataID))
                {
                    DownloadFile(jt.DataID);
                }

                //
                MakeCodeFile(jt.ID, jt.Code, (int)jt.CodeLanguage, Mode.Main);

                //编译选手程序
                if (!Compile(jt.ID, (int)jt.CodeLanguage, Mode.Main))
                {
                    return;
                }

                MakeCodeFile(jt.ID, jt.SpecialJudgeCode, (int)jt.SpecialJudgeCodeLanguage, Mode.Spj);

                //编译SPJ
                if (!string.IsNullOrEmpty(jt.SpecialJudgeCode))
                {
                    if (!Compile(jt.ID, (int)jt.SpecialJudgeCodeLanguage, Mode.Spj))
                    {
                        return;
                    }
                }
                else
                {
                    File.Copy(Program.LibPath + @"\CodeComb.Validator.exe", Program.TempPath + @"\" + jt.ID + @"\Spj.exe", true);
                }

                //准备输入数据
                File.Copy(Program.DataPath + @"\" + jt.DataID + @"\input.txt", Program.TempPath + @"\" + jt.ID + @"\input.txt", true);

                long ExitCode;

                //运行选手程序
                if (!Run(jt.ID, (int)jt.CodeLanguage, jt.TimeLimit, jt.MemoryLimit, Mode.Main, out ExitCode, ref jfb))
                {
                    return;
                }

                //准备输出数据
                File.Copy(Program.DataPath + @"\" + jt.DataID + @"\output.txt", Program.TempPath + @"\" + jt.ID + @"\output.txt", true);

                if (!string.IsNullOrEmpty(jt.SpecialJudgeCode))
                {
                    if (!Run(jt.ID, (int)jt.SpecialJudgeCodeLanguage, jt.TimeLimit, jt.MemoryLimit, Mode.Spj, out ExitCode, ref jfb))
                    {
                        return;
                    }
                }
                else
                {
                    if (!Run(jt.ID, (int)Entity.Language.Cxx, jt.TimeLimit, jt.MemoryLimit, Mode.Spj, out ExitCode, ref jfb))
                    {
                        return;
                    }
                }

                //校验结果
                Validate(jt.ID, ExitCode, jfb);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                jfb.Hint   = System.Web.HttpUtility.HtmlEncode(ex.ToString());
                jfb.Result = Entity.JudgeResult.SystemError;
                Program.CurrentThreads--;
                Feedback(jfb);
            }
        }
Exemple #5
0
 public static void Validate(int id, long ExitCode, JudgeFeedback jfb)
 {
     jfb.Result = (Entity.JudgeResult)ExitCode;
     Feedback(jfb);
 }
Exemple #6
0
        public static bool Run(int id, int language_id, int time, int memory, Mode Mode, out long ExitCode, ref JudgeFeedback JudgeFeedBack)
        {
            Process p = new Process();

            p.StartInfo.FileName               = Program.LibPath + @"\CodeComb.Core.exe";
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.WorkingDirectory       = Program.TempPath + @"\" + id;
            if (Program.LocalAuth != null)
            {
                p.StartInfo.UserName = Program.LocalAuth.Username;
                p.StartInfo.Password = Program.LocalAuth.secPassword;
            }
            if (!string.IsNullOrEmpty(Program.GccInclude))
            {
                if (p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] = Program.GccInclude;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] += ";" + Program.GccInclude;
                }
                if (p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] = Program.GccInclude;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] += ";" + Program.GccInclude;
                }
            }
            if (!string.IsNullOrEmpty(Program.GccBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.GccBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.GccBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.FpcBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.FpcBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FpcBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.JavaBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.JavaBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.JavaBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.Python27Bin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.Python27Bin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python27Bin;
                }
            }
            if (!string.IsNullOrEmpty(Program.Python33Bin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.Python33Bin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python33Bin;
                }
            }
            if (!string.IsNullOrEmpty(Program.RubyBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.RubyBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.RubyBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.Net4Bin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.Net4Bin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Net4Bin;
                }
            }
            if (!string.IsNullOrEmpty(Program.FscBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.FscBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FscBin;
                }
            }
            p.Start();
            if (Mode == JudgeHelper.Mode.Spj)
            {
                p.StandardInput.WriteLine(ExcuteArgs[language_id].Replace("{Name}", Mode.ToString()) + SpjArgs);
            }
            else
            {
                p.StandardInput.WriteLine(ExcuteArgs[language_id].Replace("{Name}", Mode.ToString()));
            }
            if (Mode == JudgeHelper.Mode.Main || Mode == JudgeHelper.Mode.Range || Mode == JudgeHelper.Mode.Std)
            {
                p.StandardInput.WriteLine("input.txt");
            }
            else if (Mode == JudgeHelper.Mode.Spj)
            {
                p.StandardInput.WriteLine("");
            }
            p.StandardInput.WriteLine(Mode.ToString() + ".out");
            if (Mode == JudgeHelper.Mode.Spj)
            {
                p.StandardInput.WriteLine(Mode.ToString() + ".err");
            }
            else
            {
                p.StandardInput.WriteLine("");
            }
            p.StandardInput.WriteLine("");
            p.StandardInput.WriteLine(time);
            p.StandardInput.WriteLine(memory);
            p.StandardInput.WriteLine(1000);
            p.StandardInput.Close();
            p.WaitForExit();
            var ResultAsString       = p.StandardOutput.ReadToEnd();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var Result      = jss.Deserialize <Result>(ResultAsString);
            var TimeUsage   = 0;
            var MemoryUsage = 0;

            TimeUsage = Result.TimeUsage;
            if ((Entity.Language)language_id == Entity.Language.Java)
            {
                MemoryUsage = Result.WorkingSet;
            }
            else
            {
                MemoryUsage = Result.PagedSize;
            }
            if (Mode == JudgeHelper.Mode.Main)
            {
                JudgeFeedBack.TimeUsage   = TimeUsage;
                JudgeFeedBack.MemoryUsage = MemoryUsage;
            }
            ExitCode = Result.ExitCode;
            if (!(Result.ExitCode == 0 || Result.ExitCode == 1 && (Entity.Language)language_id == Entity.Language.C || Mode == JudgeHelper.Mode.Spj && Result.ExitCode >= 0 && Result.ExitCode <= 3 || Mode == JudgeHelper.Mode.Range && Result.ExitCode >= -1 && Result.ExitCode <= 0))
            {
                JudgeFeedBack.Result = Entity.JudgeResult.RuntimeError;
                if (Mode != JudgeHelper.Mode.Main)
                {
                    JudgeFeedBack.Result = Entity.JudgeResult.SystemError;
                }
                JudgeFeedBack.Hint = String.Format(GetModeName(Mode) + "运行时崩溃,返回" + Result.ExitCode);
                Feedback(JudgeFeedBack);
                return(false);
            }
            if (TimeUsage > time)
            {
                JudgeFeedBack.Result = Entity.JudgeResult.TimeLimitExceeded;
                if (Mode != JudgeHelper.Mode.Main)
                {
                    JudgeFeedBack.Result = Entity.JudgeResult.SystemError;
                }
                JudgeFeedBack.Hint = String.Format(GetModeName(Mode) + "用时 {0}ms,超出了题目规定时间{1}ms", TimeUsage, time);
                Feedback(JudgeFeedBack);
                return(false);
            }
            if (MemoryUsage > memory && Mode == JudgeHelper.Mode.Main)
            {
                JudgeFeedBack.Result = Entity.JudgeResult.MemoryLimitExceeded;
                if (Mode != JudgeHelper.Mode.Main)
                {
                    JudgeFeedBack.Result = Entity.JudgeResult.SystemError;
                }
                JudgeFeedBack.Hint = String.Format(GetModeName(Mode) + "使用空间 {0}KiB,超出了题目规定空间{1}KiB", MemoryUsage, memory);
                Feedback(JudgeFeedBack);
                return(false);
            }
            if (Mode == JudgeHelper.Mode.Spj)
            {
                JudgeFeedBack.Hint = File.ReadAllText(Program.TempPath + @"\" + id + @"\Spj.out", GetType(Program.TempPath + @"\" + id + @"\Spj.out"));
            }
            return(true);
        }
Exemple #7
0
        public static bool Compile(int id, int language_id, Mode Mode)
        {
            JudgeFeedback jfb = new JudgeFeedback()
            {
                ID          = id,
                MemoryUsage = 0,
                TimeUsage   = 0,
                Result      = Entity.JudgeResult.CompileError,
                Success     = false,
            };

            if (CompileArgs[language_id] == "")
            {
                return(true);
            }
            Process p = new Process();

            p.StartInfo.FileName               = Program.LibPath + @"\CodeComb.Core.exe";
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.WorkingDirectory       = Program.TempPath + @"\" + id;
            if (Program.LocalAuth != null)
            {
                p.StartInfo.UserName = Program.LocalAuth.Username;
                p.StartInfo.Password = Program.LocalAuth.secPassword;
            }
            if (!string.IsNullOrEmpty(Program.GccInclude))
            {
                if (p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] = Program.GccInclude;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] += ";" + Program.GccInclude;
                }
                if (p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] = Program.GccInclude;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] += ";" + Program.GccInclude;
                }
            }
            if (!string.IsNullOrEmpty(Program.GccBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.GccBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.GccBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.FpcBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.FpcBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FpcBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.JavaBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.JavaBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.JavaBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.Python27Bin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.Python27Bin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python27Bin;
                }
            }
            if (!string.IsNullOrEmpty(Program.Python33Bin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.Python33Bin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python33Bin;
                }
            }
            if (!string.IsNullOrEmpty(Program.RubyBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.RubyBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.RubyBin;
                }
            }
            if (!string.IsNullOrEmpty(Program.Net4Bin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.Net4Bin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Net4Bin;
                }
            }
            if (!string.IsNullOrEmpty(Program.FscBin))
            {
                if (p.StartInfo.EnvironmentVariables["PATH"] == null)
                {
                    p.StartInfo.EnvironmentVariables["PATH"] = Program.FscBin;
                }
                else
                {
                    p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FscBin;
                }
            }
            p.Start();
            p.StandardInput.WriteLine(CompileArgs[language_id].Replace("{Name}", Mode.ToString()));
            p.StandardInput.WriteLine("");
            p.StandardInput.WriteLine("compile.out");
            p.StandardInput.WriteLine("compile.err");
            p.StandardInput.WriteLine("");
            if (language_id == (int)Entity.Language.Java)
            {
                p.StandardInput.WriteLine(Program.CompileTimeLimit + 2000);
            }
            else
            {
                p.StandardInput.WriteLine(Program.CompileTimeLimit);
            }
            p.StandardInput.WriteLine(128 * 1024);
            p.StandardInput.WriteLine(Program.CompileTimeLimit);
            p.StandardInput.Close();
            p.WaitForExit();
            var ResultAsString       = p.StandardOutput.ReadToEnd();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            var Result = jss.Deserialize <Result>(ResultAsString);

            if (Result.TimeUsage > Program.CompileTimeLimit)
            {
                if (Mode == JudgeHelper.Mode.Range)
                {
                    jfb.Hint   = "数据范围校验器编译超时";
                    jfb.Result = Entity.JudgeResult.SystemError;
                }
                else if (Mode == JudgeHelper.Mode.Spj)
                {
                    jfb.Hint   = "比较器编译超时";
                    jfb.Result = Entity.JudgeResult.SystemError;
                }
                else if (Mode == JudgeHelper.Mode.Std)
                {
                    jfb.Hint   = "标程编译超时";
                    jfb.Result = Entity.JudgeResult.SystemError;
                }
                else
                {
                    jfb.Hint = "选手程序编译超时";
                }
                Feedback(jfb);
                return(false);
            }
            else
            {
                if (Result.ExitCode != 0)
                {
                    jfb.Hint = File.ReadAllText(Program.TempPath + @"\" + jfb.ID + @"\compile.out", Encoding.GetEncoding(936)) + File.ReadAllText(Program.TempPath + @"\" + jfb.ID + @"\compile.err", Encoding.GetEncoding(936));
                    if (Mode == JudgeHelper.Mode.Range)
                    {
                        jfb.Hint   = "数据范围校验器编译失败\n" + jfb.Hint;
                        jfb.Result = Entity.JudgeResult.SystemError;
                    }
                    else if (Mode == JudgeHelper.Mode.Spj)
                    {
                        jfb.Hint   = "比较器编译失败\n" + jfb.Hint;
                        jfb.Result = Entity.JudgeResult.SystemError;
                    }
                    else if (Mode == JudgeHelper.Mode.Std)
                    {
                        jfb.Hint   = "标程编译失败\n" + jfb.Hint;
                        jfb.Result = Entity.JudgeResult.SystemError;
                    }
                    else
                    {
                        jfb.Hint = "选手程序编译失败\n" + jfb.Hint;
                    }
                    jfb.Hint = System.Web.HttpUtility.HtmlEncode(jfb.Hint);
                    Feedback(jfb);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemple #8
0
 public static bool Compile(int id, int language_id, Mode Mode)
 {
     JudgeFeedback jfb = new JudgeFeedback()
     {
         ID = id,
         MemoryUsage = 0,
         TimeUsage = 0,
         Result = Entity.JudgeResult.CompileError,
         Success = false,
     };
     if(CompileArgs[language_id] == "") return true;
     Process p = new Process();
     p.StartInfo.FileName = Program.LibPath + @"\CodeComb.Core.exe";
     p.StartInfo.CreateNoWindow = true;
     p.StartInfo.RedirectStandardInput = true;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.WorkingDirectory = Program.TempPath + @"\" + id;
     if (Program.LocalAuth != null)
     {
         p.StartInfo.UserName = Program.LocalAuth.Username;
         p.StartInfo.Password = Program.LocalAuth.secPassword;
     }
     if (!string.IsNullOrEmpty(Program.GccInclude))
     {
         if (p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] == null)
             p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] = Program.GccInclude;
         else
             p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] += ";" + Program.GccInclude;
         if (p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] == null)
             p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] = Program.GccInclude;
         else
             p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] += ";" + Program.GccInclude;
     }
     if (!string.IsNullOrEmpty(Program.GccBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.GccBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.GccBin;
     }
     if (!string.IsNullOrEmpty(Program.FpcBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.FpcBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FpcBin;
     }
     if (!string.IsNullOrEmpty(Program.JavaBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.JavaBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.JavaBin;
     }
     if (!string.IsNullOrEmpty(Program.Python27Bin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.Python27Bin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python27Bin;
     }
     if (!string.IsNullOrEmpty(Program.Python33Bin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.Python33Bin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python33Bin;
     }
     if (!string.IsNullOrEmpty(Program.RubyBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.RubyBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.RubyBin;
     }
     if (!string.IsNullOrEmpty(Program.Net4Bin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.Net4Bin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Net4Bin;
     }
     if (!string.IsNullOrEmpty(Program.FscBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.FscBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FscBin;
     }
     p.Start();
     p.StandardInput.WriteLine(CompileArgs[language_id].Replace("{Name}", Mode.ToString()));
     p.StandardInput.WriteLine("");
     p.StandardInput.WriteLine("compile.out");
     p.StandardInput.WriteLine("compile.err");
     p.StandardInput.WriteLine("");
     if (language_id == (int)Entity.Language.Java)
         p.StandardInput.WriteLine(Program.CompileTimeLimit + 2000);
     else
         p.StandardInput.WriteLine(Program.CompileTimeLimit);
     p.StandardInput.WriteLine(128 * 1024);
     p.StandardInput.WriteLine(Program.CompileTimeLimit);
     p.StandardInput.Close();
     p.WaitForExit();
     var ResultAsString = p.StandardOutput.ReadToEnd();
     JavaScriptSerializer jss = new JavaScriptSerializer();
     var Result = jss.Deserialize<Result>(ResultAsString);
     if (Result.TimeUsage > Program.CompileTimeLimit)
     {
         if (Mode == JudgeHelper.Mode.Range)
         {
             jfb.Hint = "数据范围校验器编译超时";
             jfb.Result = Entity.JudgeResult.SystemError;
         }
         else if (Mode == JudgeHelper.Mode.Spj)
         {
             jfb.Hint = "比较器编译超时";
             jfb.Result = Entity.JudgeResult.SystemError;
         }
         else if (Mode == JudgeHelper.Mode.Std)
         {
             jfb.Hint = "标程编译超时";
             jfb.Result = Entity.JudgeResult.SystemError;
         }
         else
         {
             jfb.Hint = "选手程序编译超时";
         }
         Feedback(jfb);
         return false;
     }
     else
     {
         if (Result.ExitCode != 0)
         {
             jfb.Hint = File.ReadAllText(Program.TempPath + @"\" + jfb.ID + @"\compile.out", Encoding.GetEncoding(936)) + File.ReadAllText(Program.TempPath + @"\" + jfb.ID + @"\compile.err", Encoding.GetEncoding(936));
             if (Mode == JudgeHelper.Mode.Range)
             {
                 jfb.Hint = "数据范围校验器编译失败\n" + jfb.Hint;
                 jfb.Result = Entity.JudgeResult.SystemError;
             }
             else if (Mode == JudgeHelper.Mode.Spj)
             {
                 jfb.Hint = "比较器编译失败\n" + jfb.Hint;
                 jfb.Result = Entity.JudgeResult.SystemError;
             }
             else if (Mode == JudgeHelper.Mode.Std)
             {
                 jfb.Hint = "标程编译失败\n" + jfb.Hint;
                 jfb.Result = Entity.JudgeResult.SystemError;
             }
             else
             {
                 jfb.Hint = "选手程序编译失败\n" + jfb.Hint;
             }
             jfb.Hint = System.Web.HttpUtility.HtmlEncode(jfb.Hint);
             Feedback(jfb);
             return false;
         }
         else return true;
     }
 }
Exemple #9
0
 public static void Validate(int id, long ExitCode, JudgeFeedback jfb)
 {
     jfb.Result = (Entity.JudgeResult)ExitCode;
     Feedback(jfb);
 }
Exemple #10
0
 public static bool Run(int id, int language_id,int time,int memory, Mode Mode, out long ExitCode, ref JudgeFeedback JudgeFeedBack)
 {
     Process p = new Process();
     p.StartInfo.FileName = Program.LibPath + @"\CodeComb.Core.exe";
     p.StartInfo.CreateNoWindow = true;
     p.StartInfo.RedirectStandardInput = true;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.WorkingDirectory = Program.TempPath + @"\" + id;
     if (Program.LocalAuth != null)
     {
         p.StartInfo.UserName = Program.LocalAuth.Username;
         p.StartInfo.Password = Program.LocalAuth.secPassword;
     }
     if (!string.IsNullOrEmpty(Program.GccInclude))
     {
         if (p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] == null)
             p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] = Program.GccInclude;
         else
             p.StartInfo.EnvironmentVariables["C_INCLUDE_PATH"] += ";" + Program.GccInclude;
         if (p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] == null)
             p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] = Program.GccInclude;
         else
             p.StartInfo.EnvironmentVariables["CPLUS_INCLUDE_PATH"] += ";" + Program.GccInclude;
     }
     if (!string.IsNullOrEmpty(Program.GccBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.GccBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.GccBin;
     }
     if (!string.IsNullOrEmpty(Program.FpcBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.FpcBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FpcBin;
     }
     if (!string.IsNullOrEmpty(Program.JavaBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.JavaBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.JavaBin;
     }
     if (!string.IsNullOrEmpty(Program.Python27Bin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.Python27Bin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python27Bin;
     }
     if (!string.IsNullOrEmpty(Program.Python33Bin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.Python33Bin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Python33Bin;
     }
     if (!string.IsNullOrEmpty(Program.RubyBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.RubyBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.RubyBin;
     }
     if (!string.IsNullOrEmpty(Program.Net4Bin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.Net4Bin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.Net4Bin;
     }
     if (!string.IsNullOrEmpty(Program.FscBin))
     {
         if (p.StartInfo.EnvironmentVariables["PATH"] == null)
             p.StartInfo.EnvironmentVariables["PATH"] = Program.FscBin;
         else
             p.StartInfo.EnvironmentVariables["PATH"] += ";" + Program.FscBin;
     }
     p.Start();
     if (Mode == JudgeHelper.Mode.Spj)
         p.StandardInput.WriteLine(ExcuteArgs[language_id].Replace("{Name}", Mode.ToString()) + SpjArgs);
     else
         p.StandardInput.WriteLine(ExcuteArgs[language_id].Replace("{Name}", Mode.ToString()));
     if(Mode == JudgeHelper.Mode.Main || Mode == JudgeHelper.Mode.Range || Mode == JudgeHelper.Mode.Std)
         p.StandardInput.WriteLine("input.txt");
     else if (Mode == JudgeHelper.Mode.Spj)
         p.StandardInput.WriteLine("");
     p.StandardInput.WriteLine(Mode.ToString() + ".out");
     if(Mode==JudgeHelper.Mode.Spj)
         p.StandardInput.WriteLine(Mode.ToString() + ".err");
     else
         p.StandardInput.WriteLine("");
     p.StandardInput.WriteLine("");
     p.StandardInput.WriteLine(time);
     p.StandardInput.WriteLine(memory);
     p.StandardInput.WriteLine(1000);
     p.StandardInput.Close();
     p.WaitForExit();
     var ResultAsString = p.StandardOutput.ReadToEnd();
     JavaScriptSerializer jss = new JavaScriptSerializer();
     var Result = jss.Deserialize<Result>(ResultAsString);
     var TimeUsage = 0;
     var MemoryUsage = 0;
     TimeUsage = Result.TimeUsage;
     if ((Entity.Language)language_id == Entity.Language.Java)
         MemoryUsage = Result.WorkingSet;
     else MemoryUsage = Result.PagedSize;
     if (Mode == JudgeHelper.Mode.Main)
     {
         JudgeFeedBack.TimeUsage = TimeUsage;
         JudgeFeedBack.MemoryUsage = MemoryUsage;
     }
     ExitCode = Result.ExitCode;
     if (!(Result.ExitCode == 0 || Result.ExitCode == 1 && (Entity.Language)language_id == Entity.Language.C || Mode== JudgeHelper.Mode.Spj && Result.ExitCode >=0 && Result.ExitCode <= 3 || Mode == JudgeHelper.Mode.Range && Result.ExitCode >=-1 && Result.ExitCode <=0))
     {
         JudgeFeedBack.Result = Entity.JudgeResult.RuntimeError;
         if (Mode != JudgeHelper.Mode.Main)
             JudgeFeedBack.Result = Entity.JudgeResult.SystemError;
         JudgeFeedBack.Hint = String.Format(GetModeName(Mode) + "运行时崩溃,返回"+Result.ExitCode);
         Feedback(JudgeFeedBack);
         return false;
     }
     if (TimeUsage > time )
     {
         JudgeFeedBack.Result = Entity.JudgeResult.TimeLimitExceeded;
         if(Mode != JudgeHelper.Mode.Main)
             JudgeFeedBack.Result = Entity.JudgeResult.SystemError;
         JudgeFeedBack.Hint = String.Format(GetModeName(Mode) + "用时 {0}ms,超出了题目规定时间{1}ms", TimeUsage, time);
         Feedback(JudgeFeedBack);
         return false;
     }
     if (MemoryUsage > memory && Mode == JudgeHelper.Mode.Main)
     {
         JudgeFeedBack.Result = Entity.JudgeResult.MemoryLimitExceeded;
         if (Mode != JudgeHelper.Mode.Main)
             JudgeFeedBack.Result = Entity.JudgeResult.SystemError;
         JudgeFeedBack.Hint = String.Format(GetModeName(Mode) + "使用空间 {0}KiB,超出了题目规定空间{1}KiB", MemoryUsage, memory);
         Feedback(JudgeFeedBack);
         return false;
     }
     if (Mode == JudgeHelper.Mode.Spj)
         JudgeFeedBack.Hint = File.ReadAllText(Program.TempPath + @"\" + id + @"\Spj.out", GetType(Program.TempPath + @"\" + id + @"\Spj.out"));
     return true;
 }
Exemple #11
0
        public static void Judge(JudgeTask jt)
        {
            while (Program.CurrentThreads >= Program.MaxThreads)
            {
                System.Threading.Thread.Sleep(500);
            }

            Program.CurrentThreads++;

            JudgeFeedback jfb = new JudgeFeedback()
            {
                ID = jt.ID,
                MemoryUsage = 0,
                TimeUsage = 0,
                Success = false
            };

            try
            {
                CheckPath(jt.ID);

                if (!FileExisted(jt.DataID))
                {
                    DownloadFile(jt.DataID);
                }

                //
                MakeCodeFile(jt.ID, jt.Code, (int)jt.CodeLanguage, Mode.Main);

                //编译选手程序
                if (!Compile(jt.ID, (int)jt.CodeLanguage, Mode.Main))
                    return;

                MakeCodeFile(jt.ID, jt.SpecialJudgeCode, (int)jt.SpecialJudgeCodeLanguage, Mode.Spj);

                //编译SPJ
                if (!string.IsNullOrEmpty(jt.SpecialJudgeCode))
                {
                    if (!Compile(jt.ID, (int)jt.SpecialJudgeCodeLanguage, Mode.Spj))
                    {
                        return;
                    }
                }
                else
                {
                    File.Copy(Program.LibPath + @"\CodeComb.Validator.exe", Program.TempPath + @"\" + jt.ID + @"\Spj.exe", true);
                }

                //准备输入数据
                File.Copy(Program.DataPath + @"\" + jt.DataID + @"\input.txt", Program.TempPath + @"\" + jt.ID + @"\input.txt", true);

                long ExitCode;

                //运行选手程序
                if (!Run(jt.ID, (int)jt.CodeLanguage, jt.TimeLimit, jt.MemoryLimit, Mode.Main, out ExitCode, ref jfb))
                    return;

                //准备输出数据
                File.Copy(Program.DataPath + @"\" + jt.DataID + @"\output.txt", Program.TempPath + @"\" + jt.ID + @"\output.txt", true);

                if (!string.IsNullOrEmpty(jt.SpecialJudgeCode))
                {
                    if (!Run(jt.ID, (int)jt.SpecialJudgeCodeLanguage, jt.TimeLimit, jt.MemoryLimit, Mode.Spj, out ExitCode, ref jfb))
                        return;
                }
                else
                {
                    if (!Run(jt.ID, (int)Entity.Language.Cxx, jt.TimeLimit, jt.MemoryLimit, Mode.Spj, out ExitCode, ref jfb))
                        return;
                }

                //校验结果
                Validate(jt.ID, ExitCode, jfb);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                jfb.Hint = System.Web.HttpUtility.HtmlEncode(ex.ToString());
                jfb.Result = Entity.JudgeResult.SystemError;
                Program.CurrentThreads--;
                Feedback(jfb);
            }
        }
Exemple #12
0
 public static void Feedback(JudgeFeedback jfb)
 {
     Program.hubJudge.Invoke("JudgeFeedBack", jfb);
     Program.CurrentThreads--;
     try
     {
         if (System.IO.Directory.Exists(Program.TempPath + @"\" + jfb.ID))
             System.IO.Directory.Delete(Program.TempPath + @"\" + jfb.ID, true);
     }
     catch { }
 }
Exemple #13
0
 public void JudgeFeedBack(JudgeFeedback jfb)
 {
     if (Online.FindIndex(x => x.Token == Context.ConnectionId) < 0)
         return;
     var jt = DbContext.JudgeTasks.Find(jfb.ID);
     jt.Hint = jfb.Hint;
     jt.MemoryUsage = jfb.MemoryUsage;
     jt.TimeUsage = jfb.TimeUsage;
     jt.Result = jfb.Result;
     DbContext.SaveChanges();
     ThreadFree();
     if (jt.Status.JudgeTasks.Where(x => x.ResultAsInt == (int)Entity.JudgeResult.Running || x.ResultAsInt == (int)Entity.JudgeResult.Pending).Count() == 0)
     {
         jt.Status.ResultAsInt = jt.Status.JudgeTasks.Max(x => x.ResultAsInt);
         DbContext.SaveChanges();
         var contest = jt.Status.Problem.Contest;
         if (DateTime.Now >= contest.Begin && DateTime.Now < contest.End)
         {
             SignalR.CodeCombHub.context.Clients.All.onStandingsChanged(contest.ID, new Models.View.Standing(jt.Status.User, contest));
         }
     }
     else
     {
         jt.Status.Result = Entity.JudgeResult.Running;
         DbContext.SaveChanges();
     }
     SignalR.CodeCombHub.context.Clients.All.onStatusChanged(new Models.View.Status(jt.Status));//推送新状态
 }