Exemplo n.º 1
0
 /// <summary>
 /// 增加一组测试数据
 /// </summary>
 /// <param name="testcase"></param>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="PermissionDeniedException"></exception>
 public Guid AddTestCase(TestCase testCase)
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     if (!contest.Owner.Contains(User.CurrentUser.name) &&
         !User.CurrentUser.IsAdmin)
         throw new PermissionDeniedException();
     using (var db = new CHDB())
     {
         var result = db.TESTDATAs.Add(new TESTDATA()
         {
             ID = Guid.NewGuid(),
             Input = testCase._Input,
             Data = testCase._Data,
             TimeLimit = testCase.TimeLimit,
             MemoryLimit = testCase.MemoryLimit,
             PROBLEM1 = (from p in db.PROBLEMs
                         where p.ID == ID
                         select p).Single(),
             Available = testCase.Available
         });
         db.SaveChanges();
         return result.ID;
     }
 }
 TestCaseInfo TestCase2Info(TestCase t)
 {
     return new TestCaseInfo
     {
         ID = t.ID,
         Memory = t.MemoryLimit / (double)(1024 * 1024),
         Time = t.TimeLimit / 1000.0,
         InputSize = (int)t.InputLen,
         OutputSize = (int)t.DataLen,
         Input = Encoding.ASCII.GetString(t.InputPreview(0, 100) ?? new byte[0]),
         Output = Encoding.ASCII.GetString(t.DataPreview(0, 100) ?? new byte[0]),
         Enabled = t.Available
     };
 }