Пример #1
0
    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();
        }
    }
Пример #2
0
 /// <summary>
 /// 创建新的 TranditionalTestCase 对象。
 /// </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>
 /// <param name="score">Score 属性的初始值。</param>
 public static TranditionalTestCase CreateTranditionalTestCase(global::System.Int32 id, global::System.Byte[] input, global::System.Byte[] answer, global::System.Int32 timeLimit, global::System.Int32 memoryLimit, global::System.Int32 score)
 {
     TranditionalTestCase tranditionalTestCase = new TranditionalTestCase();
     tranditionalTestCase.ID = id;
     tranditionalTestCase.Input = input;
     tranditionalTestCase.Answer = answer;
     tranditionalTestCase.TimeLimit = timeLimit;
     tranditionalTestCase.MemoryLimit = memoryLimit;
     tranditionalTestCase.Score = score;
     return tranditionalTestCase;
 }
Пример #3
0
        public int CreateTranditionalTestCase(string sToken, int problemID, byte[] input, byte[] answer, int timeLimit, int memoryLimit, int score)
        {
            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 != "Tranditional") throw new ArgumentException("不是传统题");

                if (problem.LockTestCase)
                {
                    Authorize("testcase.locked.create");
                }
                else
                {
                    Authorize("testcase.create");
                }

                User currentUser = CurrentUser.GetDBUser(db);

                TestCase testCase = new TranditionalTestCase()
                {
                    Answer = answer,
                    CreatedBy = currentUser,
                    Input = input,
                    MemoryLimit = memoryLimit,
                    TimeLimit = timeLimit,
                    Problem = problem,
                    Score = score
                };

                db.TestCases.AddObject(testCase);
                db.SaveChanges();

                return testCase.ID;
            }
        }
Пример #4
0
    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);
    }