Exemplo n.º 1
0
Arquivo: OJer.cs Projeto: chteam/choj
        public void Start(Object stateInfo)
        {
            //检查
            if (CheckCode())
            {
                //编译
                AnswerType = AnswerType.Compiling;
                if (CompileExecutable())
                {
                    //编译完成
                    //测试
                    AnswerType = AnswerType.Testing;
                    Test();
                }
                else
                {
                    AnswerType = AnswerType.CompileError;
                }
            }
            else
            {
                AnswerType = AnswerType.DangerCode;
            }
            var db = new DataBaseExecutor(new OleDbDataOpener(ConfigurationManager.ConnectionStrings["AccessFileName"].ConnectionString));

            AnswerHelper.SaveAnswer(db,
                                    Question.Field <int>("id"),
                                    Username,
                                    (int)AnswerType,
                                    Compiler.Name,
                                    UseTime,
                                    UseMemory,
                                    Guid
                                    );
            db.Dispose();
            if (!Directory.Exists(RootPath + @"SourceCode\"))
            {
                Directory.CreateDirectory(RootPath + @"SourceCode\");
            }
            File.WriteAllText(RootPath + string.Format(@"SourceCode\{0}.sc", Guid)
                              , Code);
            if (AnswerType == AnswerType.CompileError)
            {
                if (!Directory.Exists(RootPath + @"CompilerInfo\"))
                {
                    Directory.CreateDirectory(RootPath + @"CompilerInfo\");
                }
                File.WriteAllText(RootPath + string.Format(@"CompilerInfo\{0}.txt", Guid), Log.ToString());
            }
            if (!Directory.Exists(RootPath + @"temp\"))
            {
                Directory.CreateDirectory(RootPath + @"temp\");
            }
            File.Delete(ExeFile);
        }
Exemplo n.º 2
0
Arquivo: OJer.cs Projeto: chteam/choj
        public OJer(string username, string code, Guid guid, long questionId, string siteRoot)
        {
            var db =
                new DataBaseExecutor(
                    new OleDbDataOpener(ConfigurationManager.ConnectionStrings["AccessFileName"].ConnectionString));

            Guid       = Guid.NewGuid();
            Username   = username;
            Code       = code;
            Compiler   = ConfigSerializer.Load <List <Compiler> >("Compiler").Where(c => c.Guid == guid).FirstOrDefault();
            Question   = QuestionHelper.Question(db, questionId);
            RootPath   = siteRoot;
            AnswerType = AnswerType.Queuing;
            ExeFile    = RootPath + string.Format(@"temp\{0}.exe", guid);
            db.Dispose();
        }