/// <summary> /// 编译SPJ程序 /// </summary> /// <returns>是否编译并写出成功</returns> private bool CompileSpecialJudgeProgram() { Compiler compiler = new Compiler(SpjContext); string compileResult = compiler.Compile(); if (compileResult != "") { throw new CompileException("Can not compile special judge program!" + Environment.NewLine + compileResult); } string spjProgramPath = Path.Combine(SpjContext.TempDirectory, LangConfig.ProgramFileName); if (!File.Exists(spjProgramPath)) { throw new CompileException("Special judge program not found!"); } SpecialJudgeProgram spjProgram = new SpecialJudgeProgram { LangConfiguration = LangConfig, Program = File.ReadAllBytes(spjProgramPath) }; TestDataManager.WriteSpecialJudgeProgramFile(JudgeTask.ProblemId, spjProgram); return(TestDataManager.GetSpecialJudgeProgramFile(JudgeTask.ProblemId) != null); }
/// <summary> /// 构建并写出供Judger使用的SPJ程序 /// </summary> private void BuildSpecialJudgeProgram() { File.WriteAllText( Path.Combine(SpjContext.TempDirectory, SpjLangConfig.SourceCodeFileName), SpjTask.SourceCode); if (!LangConfig.NeedCompile) { return; } // 构建SPJ程序 if (TestDataManager.GetSpecialJudgeProgramFile(JudgeTask.ProblemId) == null) { if (!CompileSpecialJudgeProgram()) { throw new CompileException("Can not build special judge program!"); } } SpecialJudgeProgram spjProgram = TestDataManager.GetSpecialJudgeProgramFile(JudgeTask.ProblemId); File.WriteAllBytes( Path.Combine(SpjContext.TempDirectory, spjProgram.LangConfiguration.ProgramFileName), spjProgram.Program); }
/// <summary> /// 写出SPJ可执行程序 /// </summary> /// <param name="problemId">问题ID</param> /// <param name="programFile">SPJ程序</param> public static void WriteSpecialJudgeProgramFile(int problemId, SpecialJudgeProgram programFile) { lock (GetDataLock(problemId)) { string programPath = SpjManager.GetSpjProgramPathInTestData(problemId, programFile.LangConfiguration); if (File.Exists(programPath)) { File.Delete(programPath); } File.WriteAllBytes(programPath, programFile.Program); } }