예제 #1
0
        protected override int Run()
        {
            using (MooDB db = new MooDB())
            {
                Contest contest = (from c in db.Contests
                                   where c.Status == "Before" && c.StartTime <= DateTime.Now
                                   select c).FirstOrDefault<Contest>();
                if (contest != null)
                {
                    contest.Status = "During";
                    foreach (Problem problem in contest.Problem)
                    {
                        problem.EnableTesting = contest.EnableTestingOnStart;
                        problem.TestCaseHidden = contest.HideTestCaseOnStart;
                        problem.PostLocked = contest.LockPostOnStart;
                        problem.TestCaseLocked = contest.LockTestCaseOnStart;
                        problem.Locked = contest.LockProblemOnStart;
                        problem.Hidden = contest.HideProblemOnStart;
                        problem.RecordLocked = contest.LockRecordOnStart;
                        problem.JudgeInfoHidden = contest.HideJudgeInfoOnStart;
                        problem.ArticleLocked = contest.LockArticleOnStart;
                    }
                    db.SaveChanges();
                    return 0;
                }

                contest = (from c in db.Contests
                           where c.Status == "During" && c.EndTime <= DateTime.Now
                           select c).FirstOrDefault<Contest>();
                if (contest != null)
                {
                    contest.Status = "After";
                    foreach (Problem problem in contest.Problem)
                    {
                        problem.EnableTesting = contest.EnableTestingOnEnd;
                        problem.TestCaseHidden = contest.HideTestCaseOnEnd;
                        problem.PostLocked = contest.LockPostOnEnd;
                        problem.TestCaseLocked = contest.LockTestCaseOnEnd;
                        problem.Locked = contest.LockProblemOnEnd;
                        problem.Hidden = contest.HideProblemOnEnd;
                        problem.RecordLocked = contest.LockRecordOnEnd;
                        problem.JudgeInfoHidden = contest.HideJudgeInfoOnEnd;
                        problem.ArticleLocked = contest.LockArticleOnEnd;
                    }
                    db.SaveChanges();
                    return 0;
                }

                return 30 * 1000;
            }
        }
예제 #2
0
 static void AddRoles(MooDB db)
 {
     db.Roles.AddObject(Organizer);
     db.Roles.AddObject(Worker);
     db.Roles.AddObject(NormalUser);
     db.Roles.AddObject(Reader);
     db.SaveChanges();
 }
예제 #3
0
 protected override int Run()
 {
     using (MooDB db = new MooDB())
     {
         Record record = (from r in db.Records
                          where r.JudgeInfo == null && r.Problem.EnableTesting
                          select r).FirstOrDefault<Record>();
         var a = (from r in db.Records
                  where r.JudgeInfo == null
                  select r);
         if (record == null)
         {
             return 5 * 1000;
         }
         else
         {
             record.JudgeInfo = new JudgeInfo()
             {
                 Record = record,
                 Score = -1,
                 Info = "<color:blue>*正在评测*</color>"
             };
             db.SaveChanges();
             if (TestStart != null)
             {
                 TestStart(this, record);
             }
             Test(db, record);
             db.SaveChanges();
             if (TestComplete != null)
             {
                 TestComplete(this, record);
             }
             return 0;
         }
     }
 }
예제 #4
0
        public void AddContestProblem(string id, int problemID)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Contest contest = (from c in db.Contests
                                   where c.ID == iid
                                   select c).SingleOrDefault<Contest>();
                if (contest == null) throw new ArgumentException("无此比赛");

                Problem problem = (from p in db.Problems
                                   where p.ID == problemID
                                   select p).SingleOrDefault<Problem>();
                if (problem == null) throw new ArgumentException("无此题目");

                Access.Required(db, contest, Function.ModifyContest);

                contest.Problem.Add(problem);
                db.SaveChanges();
            }
        }
예제 #5
0
        public int CreateTestCase(string problemID, CreateTestCaseData testCase)
        {
            int iproblemID = int.Parse(problemID);
            using (MooDB db = new MooDB())
            {
                Problem problem = (from p in db.Problems
                                   where p.ID == iproblemID
                                   select p).SingleOrDefault<Problem>();
                if (problem == null) throw new ArgumentException("无此题目");

                TestCase newTestCase = testCase.ToTestCase(db);
                newTestCase.CreatedBy = Security.CurrentUser.GetDBUser(db);
                newTestCase.Problem = problem;
                newTestCase.CreateTime = DateTime.Now;

                Access.Required(db, newTestCase, Function.CreateTestCase);

                db.TestCases.AddObject(newTestCase);
                db.SaveChanges();
                return newTestCase.ID;
            }
        }
예제 #6
0
        public int CreateRecord(FullRecord record)
        {
            if (!new[] { "c", "c++", "pascal", "java", "plaintext" }.Contains(record.Language))
            {
                throw new ArgumentException("不支持的语言:" + record.Language);
            }
            using (MooDB db = new MooDB())
            {
                Problem problem = (from p in db.Problems
                                   where p.ID == record.Problem
                                   select p).SingleOrDefault<Problem>();

                if (problem == null) throw new ArgumentException("无此题目");

                User currentUser = Security.CurrentUser.GetDBUser(db);
                Record newRecord = new Record()
                {
                    Code = record.Code,
                    CreateTime = DateTime.Now,
                    Language = record.Language,
                    Problem = problem,
                    PublicCode = (bool)record.PublicCode,
                    User = currentUser,
                };

                problem.SubmissionTimes++;
                if (!(from r in db.Records
                      where r.Problem.ID == problem.ID && r.User.ID == Security.CurrentUser.ID
                      select r).Any())
                {
                    problem.SubmissionUser++;
                }

                Access.Required(db, newRecord, Function.CreateRecord);

                db.Records.AddObject(newRecord);
                db.SaveChanges();
                return newRecord.ID;
            }
        }
예제 #7
0
        public int CreateTag(CreateTagData tag)
        {
            using (MooDB db = new MooDB())
            {
                Tag newTag = new Tag
                {
                    Name = tag.Name,
                };

                Access.Required(db, newTag, Function.CreateTag);
                db.Tags.AddObject(newTag);
                db.SaveChanges();
                return newTag.ID;
            }
        }
예제 #8
0
        public void DeleteMessage()
        {
            int? with = OptionalIntParameter("with");
            using (MooDB db = new MooDB())
            {
                if (with == null)
                {
                    Access.Required(db, new Message(), Function.DeletePublicMessage);

                    var toDelete = from m in db.Messages
                                   where m.To == null
                                   select m;
                    foreach (Message msg in toDelete)
                    {
                        db.Messages.DeleteObject(msg);
                    }
                }
                else
                {
                    Access.Required(db, new Message(), Function.DeletePrivateMessage);

                    var fromMe = from m in db.Messages
                                 where m.From.ID == Security.CurrentUser.ID && m.To.ID == with
                                 select m;
                    foreach (Message msg in fromMe)
                    {
                        msg.DeletedByFrom = true;
                        if (msg.DeletedByTo)
                        {
                            db.Messages.DeleteObject(msg);
                        }
                    }

                    var toMe = from m in db.Messages
                               where m.To.ID == Security.CurrentUser.ID && m.From.ID == with
                               select m;
                    foreach (Message msg in toMe)
                    {
                        msg.DeletedByTo = true;
                        if (msg.DeletedByFrom)
                        {
                            db.Messages.DeleteObject(msg);
                        }
                    }
                }

                db.SaveChanges();
            }
        }
예제 #9
0
        public void ModifyRecord(string id, FullRecord record)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Record theRecord = (from r in db.Records
                                    where r.ID == iid
                                    select r).SingleOrDefault<Record>();
                if (record == null) throw new ArgumentException("无此记录");

                Access.Required(db, theRecord, Function.ModifyRecord);

                if (record.PublicCode != null)
                {
                    theRecord.PublicCode = (bool)record.PublicCode;
                }

                db.SaveChanges();
            }
        }
예제 #10
0
        public void DeleteArticleTag(string articleID, string id)
        {
            int iarticleID = int.Parse(articleID);
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Article article = (from a in db.Articles
                                   where a.ID == iarticleID
                                   select a).SingleOrDefault<Article>();
                if (article == null) throw new ArgumentException("无此文章");

                Tag tag = (from t in article.Tag
                           where t.ID == iid
                           select t).SingleOrDefault<Tag>();
                if (tag == null) throw new ArgumentException("无此标签");

                Access.Required(db, article, Function.ModifyArticle);
                article.Tag.Remove(tag);
                db.SaveChanges();
            }
        }
예제 #11
0
        public void DeleteFile(string id)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                UploadedFile file = (from f in db.UploadedFiles
                                     where f.ID == iid
                                     select f).SingleOrDefault<UploadedFile>();
                if (file == null) throw new ArgumentException("无此文件");

                var spj = from t in db.TestCases.OfType<SpecialJudgedTestCase>()
                          where t.Judger.ID == file.ID
                          select t;
                var interactive = from t in db.TestCases.OfType<InteractiveTestCase>()
                                  where t.Invoker.ID == file.ID
                                  select t;
                var answerOnly = from t in db.TestCases.OfType<AnswerOnlyTestCase>()
                                 where t.Judger.ID == file.ID
                                 select t;
                if (spj.Any() || interactive.Any() || answerOnly.Any())
                {
                    throw new ArgumentException("尚有测试点使用此文件");
                }

                Access.Required(db, file, Function.DeleteFile);

                File.Delete(Config.UploadFileDirectory + file.FileName);

                db.UploadedFiles.DeleteObject(file);
                db.SaveChanges();
            }
        }
예제 #12
0
        public void AttendContest(string id)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Contest contest = (from c in db.Contests
                                   where c.ID == iid
                                   select c).SingleOrDefault<Contest>();
                if (contest == null) throw new ArgumentException("无此比赛");

                Access.Required(db, contest, Function.AttendContest);

                if (contest.EndTime < DateTime.Now)
                {
                    throw new InvalidOperationException("比赛已结束");
                }

                User currentUser = Security.CurrentUser.GetDBUser(db);
                if (contest.User.Contains(currentUser))
                {
                    throw new InvalidOperationException("早已参加比赛");
                }

                contest.User.Add(currentUser);
                db.SaveChanges();
            }
        }
예제 #13
0
        public void DeleteArticle(string id)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Article article = (from a in db.Articles
                                   where a.ID == iid
                                   select a).SingleOrDefault<Article>();
                if (article == null) throw new ArgumentException("无此文章");

                Access.Required(db, article, Function.DeleteArticle);

                article.Tag.Clear();
                db.Articles.DeleteObject(article);
                db.SaveChanges();
            }
        }
예제 #14
0
        public int CreateFile(CreateFileData file)
        {
            using (MooDB db = new MooDB())
            {
                string fileName = Path.GetFileName(Config.UploadFileDirectory + file.Name);
                if (File.Exists(Config.UploadFileDirectory + fileName))
                {
                    fileName = Rand.RAND.Next() + fileName;
                    if (File.Exists(Config.UploadFileDirectory + fileName))
                    {
                        throw new ArgumentException("文件名称冲突");
                    }
                }
                UploadedFile newFile = new UploadedFile
                {
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    Description = file.Description,
                    FileName = fileName,
                    Name = file.Name
                };

                Access.Required(db, newFile, Function.CreateFile);

                File.WriteAllBytes(Config.UploadFileDirectory + fileName, Binary.Get(file.BlobID, true));

                db.SaveChanges();
                return newFile.ID;
            }
        }
예제 #15
0
        public int CreateMessage(CreateMessageData message)
        {
            using (MooDB db = new MooDB())
            {
                User to = null;
                if (message.ToID != null)
                {
                    to = (from u in db.Users
                          where u.ID == message.ToID
                          select u).SingleOrDefault<User>();
                    if (to == null) throw new Exception("无此用户");
                }

                Message newMessage = new Message
                {
                    Content = message.Content,
                    CreateTime = DateTime.Now,
                    From = Security.CurrentUser.GetDBUser(db),
                    To = to,
                    HasRead = to == null ? true : false
                };

                Access.Check(db, newMessage, Function.CreateMessage);

                db.Messages.AddObject(newMessage);
                db.SaveChanges();

                WebSockets.WebSocketsAPIHandler.NotifyNewMessage(to);

                return newMessage.ID;
            }
        }
예제 #16
0
        public int CreateContest(CreateContestData contest)
        {
            using (MooDB db = new MooDB())
            {
                Contest newContest = new Contest
                {
                    Description = contest.Description,
                    Name = contest.Name,
                    StartTime = contest.StartTime,
                    EndTime = contest.EndTime,
                    Status = "Before",

                    EnableTestingOnEnd = true,
                    EnableTestingOnStart = true,
                    HideProblemOnEnd = false,
                    HideProblemOnStart = false,
                    HideTestCaseOnEnd = false,
                    HideTestCaseOnStart = true,
                    LockArticleOnEnd = false,
                    LockArticleOnStart = true,
                    LockPostOnEnd = false,
                    LockPostOnStart = true,
                    LockProblemOnEnd = false,
                    LockProblemOnStart = true,
                    LockRecordOnEnd = false,
                    LockRecordOnStart = false,
                    LockTestCaseOnEnd = false,
                    LockTestCaseOnStart = true,
                    HideJudgeInfoOnEnd = false,
                    HideJudgeInfoOnStart = true,
                    ViewResultAnyTime = false
                };

                Access.Required(db, newContest, Function.CreateContest);

                db.Contests.AddObject(newContest);
                db.SaveChanges();
                return newContest.ID;
            }
        }
예제 #17
0
        public int CreateArticleRevision(string articleID, CreateArticleRevisionData revision)
        {
            int iarticleID = int.Parse(articleID);
            using (MooDB db = new MooDB())
            {
                Article article = (from a in db.Articles
                                   where a.ID == iarticleID
                                   select a).SingleOrDefault<Article>();
                if (article == null) throw new ArgumentException("无此文章");

                ArticleRevision newRevision = new ArticleRevision
                {
                    Article = article,
                    Content = revision.Content,
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    CreateTime = DateTime.Now,
                    Reason = revision.Reason
                };
                article.LatestRevision = newRevision;

                Access.Required(db, newRevision, Function.CreateArticleRevision);

                db.ArticleRevisions.AddObject(newRevision);
                db.SaveChanges();
                return newRevision.ID;
            }
        }
예제 #18
0
        public void ModifyUser(string id, ModifyUserData user)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                User theUser = (from u in db.Users
                                where u.ID == iid
                                select u).SingleOrDefault<User>();
                if (theUser == null) throw new ArgumentException("无此用户");

                Access.Required(db, theUser, Function.ModifyUser);

                if (user.BriefDescription != null)
                {
                    theUser.BriefDescription = user.BriefDescription;
                }
                if (user.Description != null)
                {
                    theUser.Description = user.Description;
                }
                if (user.Email != null)
                {
                    theUser.Email = user.Email;
                }
                if (user.Name != null)
                {
                    theUser.Name = user.Name;
                }
                if (user.Password != null)
                {
                    if (Converter.ToSHA256Hash(user.PasswordCheck) != theUser.Password)
                        throw new InvalidOperationException("旧有密码不正确");
                    theUser.Password = Converter.ToSHA256Hash(user.Password);
                }
                if (user.Role != null)
                {
                    Access.Required(db, theUser, Function.ModifyUserRole);
                    SiteRoles roles = new SiteRoles(db);
                    switch (user.Role)
                    {
                        case "Organizer":
                            theUser.Role = roles.Organizer;
                            break;
                        case "Worker":
                            theUser.Role = roles.Worker;
                            break;
                        case "NormalUser":
                            theUser.Role = roles.NormalUser;
                            break;
                        case "Reader":
                            theUser.Role = roles.Reader;
                            break;
                        default:
                            throw new ArgumentException("无效的角色");
                    }
                }

                db.SaveChanges();

                if (SiteUsers.ByID.ContainsKey(theUser.ID))
                {
                    SiteUsers.ByID[theUser.ID].Initialize(theUser);
                }
            }
        }
예제 #19
0
        public void ModifyTestCase(string problemID, string id, FullTestCase testCase)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                TestCase theTestCase = (from t in db.TestCases
                                        where t.ID == iid
                                        select t).SingleOrDefault<TestCase>();
                if (theTestCase == null) throw new ArgumentException("无此测试数据");

                Access.Required(db, theTestCase, Function.ModifyTestCase);

                if (theTestCase is TraditionalTestCase && testCase is FullTraditionalTestCase)
                {
                    TraditionalTestCase oldT = theTestCase as TraditionalTestCase;
                    FullTraditionalTestCase newT = testCase as FullTraditionalTestCase;
                    if (newT.Answer != null)
                    {
                        oldT.Answer = newT.Answer;
                    }
                    if (newT.Input != null)
                    {
                        oldT.Input = newT.Input;
                    }
                    if (newT.MemoryLimit != null)
                    {
                        oldT.MemoryLimit = (int)newT.MemoryLimit;
                    }
                    if (newT.TimeLimit != null)
                    {
                        oldT.TimeLimit = (int)newT.TimeLimit;
                    }
                    if (newT.Score != null)
                    {
                        oldT.Score = (int)newT.Score;
                    }
                }
                else if (theTestCase is SpecialJudgedTestCase && testCase is FullSpecialJudgedTestCase)
                {
                    SpecialJudgedTestCase oldT = theTestCase as SpecialJudgedTestCase;
                    FullSpecialJudgedTestCase newT = testCase as FullSpecialJudgedTestCase;
                    if (newT.Answer != null)
                    {
                        oldT.Answer = newT.Answer;
                    }
                    if (newT.Input != null)
                    {
                        oldT.Input = newT.Input;
                    }
                    if (newT.MemoryLimit != null)
                    {
                        oldT.MemoryLimit = (int)newT.MemoryLimit;
                    }
                    if (newT.TimeLimit != null)
                    {
                        oldT.TimeLimit = (int)newT.TimeLimit;
                    }
                    if (newT.Judger != null)
                    {
                        UploadedFile judger = (from f in db.UploadedFiles
                                               where f.ID == newT.Judger
                                               select f).SingleOrDefault<UploadedFile>();
                        if (judger == null) throw new ArgumentException("无此文件");
                        oldT.Judger = judger;
                    }
                }
                else if (theTestCase is InteractiveTestCase && testCase is FullInteractiveTestCase)
                {
                    InteractiveTestCase oldT = theTestCase as InteractiveTestCase;
                    FullInteractiveTestCase newT = testCase as FullInteractiveTestCase;
                    if (newT.TestData != null)
                    {
                        oldT.TestData = newT.TestData;
                    }
                    if (newT.MemoryLimit != null)
                    {
                        oldT.MemoryLimit = (int)newT.MemoryLimit;
                    }
                    if (newT.TimeLimit != null)
                    {
                        oldT.TimeLimit = (int)newT.TimeLimit;
                    }
                    if (newT.Invoker != null)
                    {
                        UploadedFile invoker = (from f in db.UploadedFiles
                                                where f.ID == newT.Invoker
                                                select f).SingleOrDefault<UploadedFile>();
                        if (invoker == null) throw new ArgumentException("无此文件");
                        oldT.Invoker = invoker;
                    }
                }
                else if (theTestCase is AnswerOnlyTestCase && testCase is FullAnswerOnlyTestCase)
                {
                    AnswerOnlyTestCase oldT = theTestCase as AnswerOnlyTestCase;
                    FullAnswerOnlyTestCase newT = testCase as FullAnswerOnlyTestCase;
                    if (newT.TestData != null)
                    {
                        oldT.TestData = newT.TestData;
                    }
                    if (newT.Judger != null)
                    {
                        UploadedFile judger = (from f in db.UploadedFiles
                                               where f.ID == newT.Judger
                                               select f).SingleOrDefault<UploadedFile>();
                        if (judger == null) throw new ArgumentException("无此文件");
                        oldT.Judger = judger;
                    }
                }
                else
                {
                    throw new InvalidOperationException("类型未知或不匹配");
                }
                db.SaveChanges();
            }
        }
예제 #20
0
        public void ModifyTag(string id, ModifyTagData tag)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Tag theTag = (from t in db.Tags
                              where t.ID == iid
                              select t).SingleOrDefault<Tag>();
                if (theTag == null) throw new ArgumentException("无此标签");

                Access.Required(db, theTag, Function.ModifyTag);

                if (tag.Name != null)
                {
                    theTag.Name = tag.Name;
                }

                db.SaveChanges();
            }
        }
예제 #21
0
        public int CreateUser(CreateUserData user)
        {
            using (MooDB db = new MooDB())
            {
                User newUser = new User()
                {
                    BriefDescription = "我很懒,什么都没留下~",
                    Description = "我真的很懒,真的什么也没留下。",
                    Email = user.Email,
                    Name = user.Name,
                    Password = Converter.ToSHA256Hash(user.Password),
                    CreateTime = DateTime.Now,
                    Role = new SiteRoles(db).NormalUser,
                    Score = 0,
                };

                if (Security.Authenticated)
                {
                    Access.Required(db, newUser, Function.CreateUser);
                }

                db.Users.AddObject(newUser);
                db.SaveChanges();

                return newUser.ID;
            }
        }
예제 #22
0
        public int CreatePost(FullPost post)
        {
            using (MooDB db = new MooDB())
            {
                Problem problem;
                if (post.Problem == null)
                {
                    problem = null;
                }
                else
                {
                    problem = (from p in db.Problems
                               where p.ID == post.Problem
                               select p).SingleOrDefault<Problem>();
                    if (problem == null) throw new ArgumentException("无此题目");
                }

                Post newPost = new Post()
                {
                    Name = post.Name,
                    OnTop = false,
                    Problem = problem,
                    Locked = false,
                    ReplyTime = DateTime.Now
                };

                Access.Required(db, newPost, Function.CreatePost);

                db.Posts.AddObject(newPost);
                db.SaveChanges();
                return newPost.ID;
            }
        }
예제 #23
0
        public void DeleteArticleRevision(string articleID, string id)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                ArticleRevision revision = (from r in db.ArticleRevisions
                                            where r.ID == iid
                                            select r).SingleOrDefault<ArticleRevision>();
                if (revision == null) throw new ArgumentException("无此文章版本");

                Access.Required(db, revision, Function.DeleteArticleRevision);

                Article article = revision.Article;
                if (article.LatestRevision.ID == revision.ID)
                {
                    throw new InvalidOperationException("不可删除最新版本");
                }

                db.ArticleRevisions.DeleteObject(revision);
                db.SaveChanges();
            }
        }
예제 #24
0
        public int CreatePostItem(string postID, FullPostItem postItem)
        {
            int ipostID = int.Parse(postID);
            using (MooDB db = new MooDB())
            {
                Post post = (from p in db.Posts
                             where p.ID == ipostID
                             select p).SingleOrDefault<Post>();
                if (post == null) throw new ArgumentException("无此帖子");

                PostItem newPostItem = new PostItem()
                {
                    Content = postItem.Content,
                    CreateTime = DateTime.Now,
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    Post = post,
                };
                post.ReplyTime = DateTime.Now;

                Access.Required(db, newPostItem, Function.CreatePostItem);

                db.PostItems.AddObject(newPostItem);
                db.SaveChanges();
                return newPostItem.ID;
            }
        }
예제 #25
0
        public void DeleteContest(string id)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Contest contest = (from c in db.Contests
                                   where c.ID == iid
                                   select c).SingleOrDefault<Contest>();
                if (contest == null) throw new ArgumentException("无此比赛");

                Access.Required(db, contest, Function.DeleteContest);

                contest.Problem.Clear();
                contest.User.Clear();

                db.Contests.DeleteObject(contest);
                db.SaveChanges();
            }
        }
예제 #26
0
        public int CreateProblem(CreateProblemData problem)
        {
            if (!new[] { "Traditional", "SpecialJudged", "Interactive", "AnswerOnly" }.Contains(problem.Type))
            {
                throw new NotSupportedException("不支持的题目类型:" + problem.Type);
            }

            using (MooDB db = new MooDB())
            {
                User currentUser = Security.CurrentUser.GetDBUser(db);
                Problem newProblem = new Problem()
                {
                    Name = problem.Name,
                    Type = problem.Type,
                    CreateTime = DateTime.Now,
                    CreatedBy = currentUser,
                    ArticleLocked = false,
                    EnableTesting = true,
                    Hidden = false,
                    Locked = false,
                    PostLocked = false,
                    RecordLocked = false,
                    TestCaseHidden = false,
                    TestCaseLocked = false,
                };
                Access.Required(db, newProblem, Function.CreateProblem);
                db.Problems.AddObject(newProblem);

                ProblemRevision revision = new ProblemRevision()
                {
                    Content = problem.Content,
                    CreatedBy = currentUser,
                    CreateTime = DateTime.Now,
                    Problem = newProblem,
                    Reason = "创建题目",
                };
                newProblem.LatestRevision = revision;
                Access.Required(db, revision, Function.CreateProblemRevision);
                db.ProblemRevisions.AddObject(revision);

                db.SaveChanges();
                return newProblem.ID;
            }
        }
예제 #27
0
        public void DeleteJudgeInfo(string recordID)
        {
            int irecordID = int.Parse(recordID);
            using (MooDB db = new MooDB())
            {
                Record record = (from r in db.Records
                                 where r.ID == irecordID
                                 select r).SingleOrDefault<Record>();
                if (record == null) throw new ArgumentException("无此记录");
                //Omit
                if (record.JudgeInfo == null) return;

                JudgeInfo info = record.JudgeInfo;

                Access.Required(db, info, Function.DeleteJudgeInfo);

                CreateMessage(new CreateMessageData
                {
                    ToID = record.User.ID,
                    Content = "我对您的[Record:" + record.ID + "]进行了重测。\r\n"
                    + "原始得分为*" + info.Score + "*。\r\n"
                    + "原始测评信息为\r\n" + info.Info
                });

                record.JudgeInfo = null;
                db.JudgeInfos.DeleteObject(info);
                db.SaveChanges();
            }
        }
예제 #28
0
        public void CreateProblemTag(string id, int tagID)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Tag tag = (from t in db.Tags
                           where t.ID == tagID
                           select t).SingleOrDefault<Tag>();
                if (tag == null) throw new ArgumentException("无此标签");

                Problem problem = (from p in db.Problems
                                   where p.ID == iid
                                   select p).SingleOrDefault<Problem>();
                if (problem == null) throw new ArgumentException("无此题目");

                Access.Check(db, problem, Function.ModifyProblem);

                problem.Tag.Add(tag);
                db.SaveChanges();
            }
        }
예제 #29
0
        public int CreateProblemRevision(string problemID, FullProblemRevision revision)
        {
            int iproblemID = int.Parse(problemID);
            using (MooDB db = new MooDB())
            {
                Problem problem = (from p in db.Problems
                                   where p.ID == iproblemID
                                   select p).SingleOrDefault<Problem>();
                if (problem == null) throw new ArgumentException("无此题目");

                ProblemRevision problemRevision = new ProblemRevision()
                {
                    CreatedBy = Security.CurrentUser.GetDBUser(db),
                    Content = revision.Content,
                    Problem = problem,
                    Reason = revision.Reason,
                    CreateTime = DateTime.Now
                };
                problem.LatestRevision = problemRevision;

                Access.Required(db, problemRevision, Function.CreateProblemRevision);

                db.ProblemRevisions.AddObject(problemRevision);
                db.SaveChanges();
                return problemRevision.ID;
            }
        }
예제 #30
0
        public void ModifyProblem(string id, FullProblem problem)
        {
            int iid = int.Parse(id);
            using (MooDB db = new MooDB())
            {
                Problem theProblem = (from p in db.Problems
                                      where p.ID == iid
                                      select p).SingleOrDefault<Problem>();
                if (theProblem == null) throw new ArgumentException("无此题目");

                Access.Required(db, theProblem, Function.ModifyProblem);

                if (problem.Name != null)
                {
                    theProblem.Name = problem.Name;
                }
                if (problem.Type != null)
                {
                    if (!new[] { "Traditional", "SpecialJudged", "Interactive", "AnswerOnly" }.Contains(problem.Type))
                    {
                        throw new NotSupportedException("不支持的题目类型:" + problem.Type);
                    }
                    theProblem.Type = problem.Type;
                }
                if (problem.ArticleLocked != null)
                {
                    theProblem.ArticleLocked = (bool)problem.ArticleLocked;
                }
                if (problem.EnableTesting != null)
                {
                    theProblem.EnableTesting = (bool)problem.EnableTesting;
                }
                if (problem.Hidden != null)
                {
                    theProblem.Hidden = (bool)problem.Hidden;
                }
                if (problem.Locked != null)
                {
                    theProblem.Locked = (bool)problem.Locked;
                }
                if (problem.PostLocked != null)
                {
                    theProblem.PostLocked = (bool)problem.PostLocked;
                }
                if (problem.RecordLocked != null)
                {
                    theProblem.RecordLocked = (bool)problem.RecordLocked;
                }
                if (problem.TestCaseHidden != null)
                {
                    theProblem.TestCaseHidden = (bool)problem.TestCaseHidden;
                }
                if (problem.TestCaseLocked != null)
                {
                    theProblem.TestCaseLocked = (bool)problem.TestCaseLocked;
                }
                if (problem.JudgeInfoHidden != null)
                {
                    theProblem.JudgeInfoHidden = (bool)problem.JudgeInfoHidden;
                }
                db.SaveChanges();
            }
        }