Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }