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); }
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)); }
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()); }
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() ); }
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); }
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); }
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(); }
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); }
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); }
static public DataRow Question(DataBaseExecutor db, long id) { return(AllQuestion(db).AsEnumerable().Where(c => c.Field <int>("ID") == id).FirstOrDefault()); }
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); }
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); }