Exemple #1
0
        static public IEnumerable <DataRow> QuestionList(DataBaseExecutor db, long groupid, int p)
        {
            string key = string.Format(QUESTIONLIST, groupid);

            return(AllQuestion(db).AsEnumerable().Where(c => c.Field <int>("GroupID") == groupid).OrderBy(c => c.Field <int>("ID")));
            //.Skip(20 * (p - 1)).Take(20);
        }
Exemple #2
0
        static public IEnumerable <DataRow> Status(DataBaseExecutor db, int p)
        {
            return(db.GetTable(@"SELECT Answer.QuestionID, Answer.Username, 
Answer.Status, Answer.Addtime, Answer.Complier, Answer.UseTime, 
Answer.UseMemory, Question.Title, Answer.ID,Answer.Guid
FROM Answer INNER JOIN Question ON Answer.QuestionID = Question.ID 
order by answer.id desc").AsEnumerable().Skip(20 * (p - 1)).Take(20));
        }
Exemple #3
0
        static public IEnumerable <DataRow> MySatus(DataBaseExecutor db, string username)
        {
            return(db.GetTable(@"SELECT Answer.QuestionID, Answer.Username, 
Answer.Status, Answer.Addtime, Answer.Complier, Answer.UseTime, 
Answer.UseMemory, Question.Title, Answer.ID,Answer.Guid
FROM Answer INNER JOIN Question ON Answer.QuestionID = Question.ID 
where answer.username=@un
order by answer.id desc", "@un", username).AsEnumerable().ToList());
        }
Exemple #4
0
        static public void SaveAnswer(DataBaseExecutor db, long qid, string username, int st,
                                      string CompilerName, long UseTime, long UseMemory, Guid Guid)
        {
            db.Execute(@"INSERT INTO Answer 
(QuestionID, Username, Status, Addtime, Complier, Type, UseTime, UseMemory,[Guid] )
values(@qid,@un,@st, Now(),@cn,0,@UseTime,@UseMemory,@Guid)", "@qid", qid, "@un", username, "@st", st,
                       "@cn", CompilerName, "@UseTime", UseTime, "@UseMemory", UseMemory
                       , "@Guid", Guid.ToString()
                       );
        }
Exemple #5
0
        static public DataRow GetGroup(DataBaseExecutor db, long id)
        {
            var rets = GroupTable(db).AsEnumerable().Where(c => c.Field <int>("id") == id).FirstOrDefault();

            if (rets != null)
            {
                return(rets);
            }
            return(null);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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();
        }
Exemple #8
0
        static DataTable AllQuestion(DataBaseExecutor db)
        {
            string    key = QUESTIONLIST;
            DataTable dt  = null;

            if (CHCache.Contains(key))
            {
                dt = CHCache.Get <DataTable>(key);
            }
            else
            {
                dt = db.GetTable(@"SELECT * FROM [Question]");                // where istrue=1
                CHCache.Add(key, dt);
            }
            return(dt);
        }
Exemple #9
0
        static DataTable GroupTable(DataBaseExecutor db)
        {
            string    key = GROUP;
            DataTable dt  = null;

            if (CHCache.Contains(key))
            {
                dt = CHCache.Get <DataTable>(key);
            }
            else
            {
                dt = db.GetTable(@"SELECT * FROM [Group]");
                CHCache.Add(key, dt);
            }
            return(dt);
        }
Exemple #10
0
 static public DataRow Question(DataBaseExecutor db, long id)
 {
     return(AllQuestion(db).AsEnumerable().Where(c => c.Field <int>("ID") == id).FirstOrDefault());
 }
Exemple #11
0
        public static void Create(DataBaseExecutor db, string Username)
        {
            db.Execute(@"INSERT INTO [User]([Username],[NickName],[Name],[Sex],[Birthday],[Grade],[School],[SchoolDetails],[Submit],[Accepted])
VALUES(@Username,@Username,'',0,Now(),2008,'','',0,0)", "@Username", Username);
        }
Exemple #12
0
        static public IEnumerable <DataRow> GroupList(DataBaseExecutor db)
        {
            var rows = GroupTable(db).AsEnumerable().Where(c => c.Field <int>("type") == 0).OrderBy(c => c.Field <int>("order"));

            return(rows);
        }