protected void Page_Load(object sender, EventArgs e) { using (MooDB db = new MooDB()) { if (Request["id"] != null) { CollectEntityByID(db, int.Parse(Request["id"])); } if (testCase == null) { PageUtil.Redirect(Resources.Moo.FoundNothing, "~/"); return; } if (testCase.Problem.TestCaseHidden) { if (!Permission.Check("testcase.hidden.read", false)) return; } else { if (!Permission.Check("testcase.read", true)) return; } if (testCase is TranditionalTestCase) { asTranditional = testCase as TranditionalTestCase; multiView.SetActiveView(viewTranditional); } else if (testCase is SpecialJudgedTestCase) { asSpecialJudged = testCase as SpecialJudgedTestCase; multiView.SetActiveView(viewSpecialJudged); } else if (testCase is InteractiveTestCase) { asInteractive = testCase as InteractiveTestCase; multiView.SetActiveView(viewInteractive); } else if (testCase is AnswerOnlyTestCase) { asAnswerOnly = testCase as AnswerOnlyTestCase; multiView.SetActiveView(viewAnswerOnly); } else { PageUtil.Redirect("未知的测试数据类型", "~/"); return; } multiView.GetActiveView().DataBind(); linkbar.DataBind(); Header.DataBind(); } }
/// <summary> /// 创建新的 SpecialJudgedTestCase 对象。 /// </summary> /// <param name="id">ID 属性的初始值。</param> /// <param name="input">Input 属性的初始值。</param> /// <param name="answer">Answer 属性的初始值。</param> /// <param name="timeLimit">TimeLimit 属性的初始值。</param> /// <param name="memoryLimit">MemoryLimit 属性的初始值。</param> public static SpecialJudgedTestCase CreateSpecialJudgedTestCase(global::System.Int32 id, global::System.Byte[] input, global::System.Byte[] answer, global::System.Int32 timeLimit, global::System.Int32 memoryLimit) { SpecialJudgedTestCase specialJudgedTestCase = new SpecialJudgedTestCase(); specialJudgedTestCase.ID = id; specialJudgedTestCase.Input = input; specialJudgedTestCase.Answer = answer; specialJudgedTestCase.TimeLimit = timeLimit; specialJudgedTestCase.MemoryLimit = memoryLimit; return specialJudgedTestCase; }
public int CreateSpecialJudgedTestCase(string sToken, int problemID, int judgerID, byte[] input, byte[] answer, int timeLimit, int memoryLimit) { Authenticate(sToken); using (MooDB db = new MooDB()) { Problem problem = (from p in db.Problems where p.ID == problemID select p).SingleOrDefault<Problem>(); if (problem == null) throw new ArgumentException("无此题目"); if (problem.Type != "SpecialJudged") throw new ArgumentException("不是自定义测评题"); if (problem.LockTestCase) { Authorize("testcase.locked.create"); } else { Authorize("testcase.create"); } UploadedFile judger = (from f in db.UploadedFiles where f.ID == judgerID select f).SingleOrDefault<UploadedFile>(); if (judger == null) throw new ArgumentException("无此文件"); User currentUser = CurrentUser.GetDBUser(db); TestCase testCase = new SpecialJudgedTestCase() { Answer=answer, Input=input, CreatedBy=currentUser, Judger=judger, MemoryLimit=memoryLimit, Problem=problem, TimeLimit=timeLimit, }; db.TestCases.AddObject(testCase); db.SaveChanges(); return testCase.ID; } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (!Page.IsValid) return; int problemID = (int)ViewState["problemID"]; int testCaseID; using (MooDB db = new MooDB()) { problem = (from p in db.Problems where p.ID == problemID select p).Single<Problem>(); if (problem.LockTestCase) { if (!Permission.Check("testcase.locked.create", false)) return; } else { if (!Permission.Check("testcase.create", false)) return; } User currentUser = ((SiteUser)User.Identity).GetDBUser(db); TestCase testCase; if (problem.Type == "Tranditional") { testCase = new TranditionalTestCase() { Score = int.Parse(txtScore.Text), TimeLimit = int.Parse(txtTimeLimit.Text), MemoryLimit = int.Parse(txtMemoryLimit.Text), Input = fileInput.FileBytes, Answer = fileAnswer.FileBytes, Problem = problem, CreatedBy = currentUser }; } else if (problem.Type == "SpecialJudged") { int judgerID = int.Parse(txtJudger.Text); UploadedFile judger = (from f in db.UploadedFiles where f.ID == judgerID select f).Single<UploadedFile>(); testCase = new SpecialJudgedTestCase() { TimeLimit = int.Parse(txtTimeLimit.Text), MemoryLimit = int.Parse(txtMemoryLimit.Text), Input = fileInput.FileBytes, Answer = fileAnswer.FileBytes, Judger = judger, Problem = problem, CreatedBy = currentUser }; } else if (problem.Type == "Interactive") { int invokerID = int.Parse(txtInvoker.Text); UploadedFile invoker = (from f in db.UploadedFiles where f.ID == invokerID select f).Single<UploadedFile>(); testCase = new InteractiveTestCase() { Invoker = invoker, MemoryLimit = int.Parse(txtMemoryLimit.Text), TimeLimit = int.Parse(txtTimeLimit.Text), Problem = problem, TestData = fileTestData.FileBytes, CreatedBy = currentUser }; } else if (problem.Type == "AnswerOnly") { int judgerID = int.Parse(txtJudger.Text); UploadedFile judger = (from f in db.UploadedFiles where f.ID == judgerID select f).Single<UploadedFile>(); testCase = new AnswerOnlyTestCase() { Judger = judger, Problem = problem, TestData = fileTestData.FileBytes, CreatedBy = currentUser }; } else { PageUtil.Redirect("未知的题目类型", "~/"); return; } db.TestCases.AddObject(testCase); db.SaveChanges(); testCaseID = testCase.ID; Logger.Info(db, "创建测试数据#" + testCaseID); } PageUtil.Redirect("创建成功", "~/TestCase/?id=" + testCaseID); }