Esempio n. 1
0
 /// <summary>
 /// 修改Problem内容 把 Name OriginRating Content Comparer DataChecker Owner DataCheckerLanguage ComparerLanguage 更新
 /// </summary>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="PermissionDeniedException"></exception>
 /// <exception cref="UserNotFoundException"></exception>
 /// <exception cref="ProblemNameExistedException"></exception>
 public void Change()
 {
     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())
     {
         Name = Helper.GetLegalName(Name);
         var pro = (from p in db.PROBLEMs
                    where p.ID==ID
                    select p).Single();
         var owner = (from u in db.USERs
                      where u.Name == Owner
                      select u).SingleOrDefault();
         if (null == owner)
             throw new UserNotFoundException();
         if (pro.Name != Name && (from p in db.PROBLEMs
                                  where p.Name == Name && p.CONTEST1.ID == contest.ID
                                  select p).Any())
             throw new ProblemNameExistedException();
         pro.Name = Name;
         pro.OriginRating = OriginRating;
         pro.Content = Content;
         pro.Comparer = Comparer;
         pro.DataChecker = DataChecker;
         pro.OWNER = owner;
         pro.DataCheckerLanguage = (int)DataCheckerLanguage;
         pro.ComparerLanguage = (int)ComparerLanguage;
         db.SaveChanges();
     }
 }
Esempio n. 2
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;
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 获得所有用户组
 /// </summary>
 /// <returns></returns>
 /// <exception cref="PermissionDeniedException"></exception>
 public static List<Group> All()
 {
     CheckPriviledge();
     using(var db = new CHDB())
     {
         return (from g in db.GROUPs
                 select new Group
                 {
                     Name = g.Name,
                     ID = g.ID
                 }).ToList();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 增加用户组 需要填充 Name
 /// </summary>
 /// <param name="name"></param>
 /// <exception cref="PermissionDeniedException"></exception>
 public static void Add(Group group)
 {
     CheckPriviledge();
     using (var db = new CHDB())
     {
         db.GROUPs.Add(new GROUP()
         {
             ID = Guid.NewGuid(),
             Name =group.Name
         });
         db.SaveChanges();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// 获取公共聊天区内容
 /// </summary>
 /// <param name="Before"></param>
 /// <param name="top"></param>
 /// <returns></returns>
 public static List<Message> GetHistory(Session Session, DateTime Before, int top)
 {
     using (var db = new CHDB())
     {
         return (from r in db.MESSAGEs
                 where r.Session == Session.ID
                 && r.Time < Before
                 orderby r.Time descending
                 select new Message()
                 {
                     Content = r.Content,
                     Time = r.Time,
                     Username = r.USER1.Name
                 }).Take(top).ToList();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 返回指定名称的用户组
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="PermissionDeniedException"></exception>
        /// <exception cref="GroupNotFoundException"></exception>
        public static Group ByName(string name)
        {
            CheckPriviledge();
            using (var db = new CHDB())
            {
                var result = (from g in db.GROUPs
                              where g.Name == name
                              select new Group
                              {
                                  Name = g.Name,
                                  ID = g.ID
                              }).SingleOrDefault();
                if (null == result)
                    throw new GroupNotFoundException();

                return result;
            }
        }
 protected override int Run()
 {
     bool flg = false;
     var testers = (from t in Framework.tester
                    where t.HuntList.Count < 3 && t.RecList.Count < 3
                    select t).ToArray();
     for (int i = 0; i < testers.Length; i++)
     {
         var x = testers[i];
         int p = rand.Next(testers.Length);
         testers[i] = testers[p];
         testers[p] = x;
     }
     using (var db = new CHDB())
     {
         foreach (var tester in testers)
         {
             var rec = (from r in db.RECORDs
                        where r.Status == (int)Record.StatusType.Pending
                        select r).FirstOrDefault();
             if (null != rec)
             {
                 flg = true;
                 rec.Status = (int)Record.StatusType.Running;
                 db.SaveChanges();
                 tester.RecList.Add(rec.ID);
             }
             var hu = (from h in db.HUNTs
                       where h.Status == (int)Hunt.StatusType.Pending
                       select h).FirstOrDefault();
             if (null != hu)
             {
                 flg = true;
                 hu.Status = (int)Hunt.StatusType.Running;
                 db.SaveChanges();
                 tester.HuntList.Add(hu.ID);
             }
         }
     }
     if (flg)
         return 0;
     return 3000;
 }
Esempio n. 8
0
 /// <summary>
 /// 获取私聊会话
 /// </summary>
 /// <param name="name">要私聊用户名称</param>
 /// <returns></returns>
 public static Session GetPrivateSession(string name)
 {
     using (var db = new CHDB())
     {
         var u1 = (from u in db.USERs
                   where u.Name == name
                   select u).Single();
         var u2 = (from u in db.USERs
                   where u.ID == User.CurrentUser.ID
                   select u).Single();
         var ret = (from s in u2.SESSIONs
                    where s.USERs.Select(x => x.Name).Contains(name)
                    && s.Type == (int)SessionType.PrivateChat
                    select new Session()
                              {
                                  ID = s.ID,
                                  Name = s.Name,
                                  Type = SessionType.PrivateChat
                              }).FirstOrDefault();
         if (null == ret)
         {
             var session = db.SESSIONs.Add(new SESSION()
             {
                 ID = Guid.NewGuid(),
                 Name = "",
                 Type = (int)SessionType.PrivateChat
             });
             session.USERs.Add(u1);
             session.USERs.Add(u2);
             db.SaveChanges();
             return new Session()
             {
                 ID = session.ID,
                 Type = SessionType.PrivateChat
             };
         }
         return ret;
     }
 }
Esempio n. 9
0
 public static void DomainStart()
 {
     using (var db = new CHDB())
     {
         HuntBadWating(db);
         RecordBadWating(db);
         Group.AdministratorID = (from g in db.GROUPs
                                  where g.Name == "Administrators"
                                  select g.ID).Single();
     }
     contest.Start();
     foreach (var akinfo in AllKorrectDaemon.aks)
     {
         var ak = new AllKorrectDaemon()
         {
             _ak = akinfo
         };
         ak.Start();
         tester.Add(ak);
     }
     dispatcher.Start();
     email.Start();
 }
Esempio n. 10
0
 public static void DomainInstallation()
 {
     using (var db = new CHDB())
     {
         db.GROUPs.Add(new GROUP()
         {
             ID = Guid.NewGuid(),
             Name = "Administrators"
         });
         using (var sha = SHA256.Create())
         {
             db.USERs.Add(new USER()
             {
                 ID = Guid.NewGuid(),
                 Name = "Administrator",
                 Email = "*****@*****.**",
                 Password = sha.ComputeHash(Encoding.Unicode.GetBytes("07070078899"))
             });
         }
         db.SaveChanges();
         (from u in db.USERs
          where u.Name == "Administrator"
          select u).Single().GROUPs.Add
         (
         (from g in db.GROUPs
             where g.Name == "Administrators"
             select g).Single()
         );
         db.SESSIONs.Add(new SESSION()
         {
             ID = Guid.Empty,
             Name = "公共版聊",
             Type = (int)Chat.SessionType.CommonChat
         });
         db.SaveChanges();
     }
 }
Esempio n. 11
0
 /// <summary>
 /// 取消参加比赛
 /// </summary>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="NotAttendedContestException"></exception>
 /// <exception cref="ContestStartedException"></exception>
 public void Disattended()
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     if (!IsAttended())
         throw new NotAttendedContestException();
     using (var db = new CHDB())
     {
         var con = (from c in db.CONTESTs
                    where c.ID==ID
                    select c).Single();
         var con_att = (from u in con.CONTEST_ATTEND
                        where u.USER1.Name == User.CurrentUser.name
                        select u).Single();
         if (DateTime.Now > RelativeStartTime)
             throw new ContestStartedException();
         con.CONTEST_ATTEND.Remove(con_att);
         db.SaveChanges();
     }
 }
Esempio n. 12
0
 /// <summary>
 /// 修改Contest信息
 /// </summary>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="PermissionDeniedException"></exception>
 /// <exception cref="ContestNameExistedException"></exception>
 public void Change()
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     if (!Owner.Contains(User.CurrentUser.name) &&
         !User.CurrentUser.IsAdmin)
         throw new PermissionDeniedException();
     using (var db = new CHDB())
     {
         var con = (from c in db.CONTESTs
                    where c.ID==ID
                    select c).Single();
         if (IsOfficial != con.IsOfficial && !User.CurrentUser.IsAdmin &&
             User.ByName(User.CurrentUser.name).Rating < 2100)
             throw new PermissionDeniedException();
         Name = Helper.GetLegalName(Name);
         if (con.Name != Helper.GetLegalName(Name))
         {
             if ((from c in db.CONTESTs
                  where c.Name == Name
                  select c).Any())
                 throw new ContestNameExistedException();
             con.Name = Name;
         }
         con.Description = Description;
         if (Owner != Owners)
         {
             con.OWNERs.Clear();
             foreach (var name in Owners)
             {
                 con.OWNERs.Add((from u in db.USERs
                                 where u.Name == name
                                 select u).Single());
             }
         }
         con.IsOfficial = IsOfficial;
         con.StartTime = AbsoluteStartTime;
         con.EndTime = AbsoluteEndTime;
         con.Type = (int)Type;
         if (User.CurrentUser.IsAdmin)
             con.Weight = Weight;
         db.SaveChanges();
     }
 }
Esempio n. 13
0
 public void SendEamil(string message)
 {
     if(null == User.CurrentUser)
         throw new UserNotLoginException();
     if(!User.CurrentUser.IsAdmin && !Owner.Contains(User.CurrentUserName))
         throw new PermissionDeniedException();
     using (var db = new CHDB())
     {
         var Info = (from u in db.USERs
                   where u.AcceptEmail
                   select new
                   {
                       u.Name,
                       u.Email
                   }).ToArray();
         string Subject = "ContestHunter将举办 " + Name + " ,欢迎参加!";
         string link = ConfigurationManager.AppSettings["WebSite"] + "Contest/Show/" + Name;
         lock (SendMailDaemon.EmailList)
         {
             foreach (var info in Info)
             {
                 try
                 {
                     string Body = info.Name + ":<br />&nbsp;&nbsp;&nbsp;&nbsp;您好。" + HttpUtility.HtmlEncode(Name) + " 将于 " + AbsoluteStartTime + " 在ContestHunter举办。欢迎您访问 <a href=\"" + HttpUtility.HtmlAttributeEncode(link) + "\">" + HttpUtility.HtmlEncode(link) + "</a> 报名参加。<br />" +
                         "本次比赛持续 " + (AbsoluteEndTime - AbsoluteStartTime) + " ,采用 " + Type + " 赛制,由 " + string.Join(",", Owner) + " 举办,<b>" + (IsOfficial ? "" : "不") + "计入</b>能力排名。<br />" +
                         "<br />&nbsp;&nbsp;&nbsp;&nbsp;诚邀您及时报名参加本场比赛。如果您不希望再收到此类邮件,可以在修改个人资料页面取消。" +
                         (string.IsNullOrWhiteSpace(message) ? "" : HttpUtility.HtmlEncode(message));
                     SendMailDaemon.EmailList.Add(new SendMailDaemon.Email()
                     {
                         subject = Subject,
                         to = info.Email,
                         content = Body
                     });
                 }
                 catch { }
             }
         }
     }
 }
Esempio n. 14
0
 /// <summary>
 /// 删除本比赛,只有 Administrators 组有此权限
 /// </summary>
 /// <exception cref="PermissionDeniedException"></exception>
 public void Remove()
 {
     if (!User.CurrentUser.IsAdmin)
         throw new PermissionDeniedException();
     using (var db = new CHDB())
     {
         db.CONTESTs.Remove((from c in db.CONTESTs
                             where c.ID == ID
                             select c).Single());
         db.SaveChanges();
     }
 }
Esempio n. 15
0
        /// <summary>
        /// 获取比赛题目名称列表
        /// </summary>
        /// <returns></returns>
        /// <exception cref="UserNotLoginException"></exception>
        /// <exception cref="NotAttendedContestException"></exception>
        public List<string> Problems()
        {
            if (null == User.CurrentUser)
                throw new UserNotLoginException();
            if (!Owner.Contains(User.CurrentUser.name) && !User.CurrentUser.IsAdmin)
            {
                if (!IsAttended())
                    throw new NotAttendedContestException();
            }

            using (var db = new CHDB())
            {

                return (from p in db.PROBLEMs
                        where p.CONTEST1.ID==ID
                        orderby p.OriginRating,p.Name ascending
                        select p.Name).ToList();
            }
        }
Esempio n. 16
0
 /// <summary>
 /// 判断是否报名比赛
 /// </summary>
 /// <returns></returns>
 /// <exception cref="UserNotLoginException"></exception>
 public bool IsAttended()
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     using (var db = new CHDB())
     {
         return (from u in
                     (from c in db.CONTESTs
                      where c.ID==ID
                      select c).Single().CONTEST_ATTEND
                 where u.USER1.Name == User.CurrentUser.name
                 select u).Any();
     }
 }
Esempio n. 17
0
        /// <summary>
        /// 返回CF比赛Standing
        /// </summary>
        /// <param name="skip"></param>
        /// <param name="top"></param>
        /// <param name="HasVirtual"></param>
        /// <returns></returns>
        /// <exception cref="ContestTypeMismatchException"></exception>
        public List<CFStanding> GetCFStanding(int skip, int top, bool HasVirtual,bool HasNotSubmit)
        {
            if (Type != ContestType.CF)
                throw new ContestTypeMismatchException();
            List<CFStanding> ret=new List<CFStanding>();
            var Probs=Problems();
            using (var db = new CHDB())
            {
                var raw = db.GetCFStanding(ID, RelativeNow,skip, top, HasVirtual, HasNotSubmit).ToArray();

                for (int i = 0; i < raw.Length; i += Probs.Count())
                {
                    var desp = new List<CFStanding.DescriptionClass>();
                    for (int jj = 0; jj < Probs.Count(); jj++)
                    {
                        int j = i + jj;
                        desp.Add(new CFStanding.DescriptionClass()
                        {
                            _huntFailed=(int)raw[j].FailedHunt,
                            _huntSuccessfully=(int)raw[j].SuccessfulHunt,
                            ACTime=raw[j].ACTime,
                            isAC=(bool)raw[j].IsAC,
                            FailedTimes=(int)raw[j].FailedTimes,
                            Rating=(int)raw[j].Rating
                        });
                    }
                    var entity = new CFStanding()
                    {
                        Description = desp,
                        FailedHack = desp.Sum(x => x._huntFailed),
                        SuccessHack = desp.Sum(x => x._huntSuccessfully),
                        User = raw[i].User,
                        TotalRating = desp.Sum(x => x.Rating),
                        IsVirtual = raw[i].Type == (int)AttendType.Virtual
                    };
                    entity.TotalRating = entity.TotalRating + 100 * entity.SuccessHack - 25 * entity.FailedHack;
                    ret.Add(entity);
                }

            }
            return ret;
        }
Esempio n. 18
0
 /*
 public override bool Equals(object obj)
 {
     if (obj is Contest)
         return Name == ((Contest)obj).Name;
     return base.Equals(obj);
 }
 */
 /// <summary>
 /// 返回ACM比赛Standing
 /// </summary>
 /// <param name="skip"></param>
 /// <param name="top"></param>
 /// <param name="HasVirtual"></param>
 /// <returns></returns>
 /// <exception cref="ContestTypeMismatchException"></exception>
 public List<ACMStanding> GetACMStanding(int skip, int top,bool HasVirtual,bool HasNotSubmit)
 {
     if (Type != ContestType.ACM)
         throw new ContestTypeMismatchException();
     using (var db = new CHDB())
     {
         var lst = db.GetACMStanding(ID, RelativeNow, skip, top, HasVirtual, HasNotSubmit).ToArray();
         int count = Problems().Count();
         var ret = new List<ACMStanding>();
         for (int i = 0; i < lst.Length; i += count)
         {
             var desp = new List<ACMStanding.DescriptionClass>();
             for (int jj = 0; jj < count; jj++)
             {
                 int j = i + jj;
                 desp.Add(new ACMStanding.DescriptionClass()
                 {
                     ACTime = lst[j].ACTime,
                     FailedTimes = (int)lst[j].FailedTimes,
                     isAC = (bool)lst[j].IsAC
                 });
             }
             ret.Add(new ACMStanding()
             {
                 CountAC = desp.Sum(x => x.isAC ? 1 : 0),
                 Description = desp,
                 IsVirtual = lst[i].Type == (int)AttendType.Virtual,
                 TotalTime = desp.Sum(x => x.isAC ? (int)x.ACTime + 20 * x.FailedTimes : 0),
                 User = lst[i].User
             });
         }
         return ret;
     }
 }
Esempio n. 19
0
 /// <summary>
 /// 判断是否为虚拟报名此比赛
 /// </summary>
 /// <returns></returns>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="NotAttendedContestException"></exception>
 public AttendType GetAttendType()
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     if (!IsAttended())
         throw new NotAttendedContestException();
     using (var db = new CHDB())
     {
         var con_att = (from c in db.CONTESTs
                        where c.ID==ID
                        select c.CONTEST_ATTEND).Single();
         return (AttendType)(from u in con_att
                 where u.USER1.Name == User.CurrentUser.name
                 select u.Type).Single();
     }
 }
Esempio n. 20
0
 /// <summary>
 /// 返回 Pending 比赛个数
 /// </summary>
 /// <returns></returns>
 public static int PendingCount()
 {
     using (var db = new CHDB())
     {
         return (from c in db.CONTESTs
                 where c.StartTime > DateTime.Now
                 select c).Count();
     }
 }
Esempio n. 21
0
 /// <summary>
 /// 返回OI比赛Standing
 /// </summary>
 /// <param name="skip"></param>
 /// <param name="top"></param>
 /// <param name="HasVirtual"></param>
 /// <returns></returns>
 /// <exception cref="ContestTypeMismatchException"></exception>
 /// <exception cref="ContestNotEndedException"></exception>
 public List<OIStanding> GetOIStanding(int skip, int top,bool HasVirtual,bool HasNotSubmit)
 {
     if (Type != ContestType.OI)
         throw new ContestTypeMismatchException();
     using (var db = new CHDB())
     {
         var con = (from c in db.CONTESTs
                    where c.ID==ID
                    select c).Single();
         if (DateTime.Now <= RelativeEndTime && !User.CurrentUser.IsAdmin && !Owner.Contains(User.CurrentUserName))
             throw new ContestNotEndedException();
         int count = Problems().Count();
         var lst = db.GetOIStanding(ID, RelativeNow, skip, top, HasVirtual, HasNotSubmit).ToArray();
         var ret = new List<OIStanding>();
         for (int i = 0; i < lst.Length; i+=count)
         {
             var desp=new List<OIStanding.DescriptionClass>();
             for (int jj = 0; jj < count; jj++)
             {
                 int j = i + jj;
                 desp.Add(new OIStanding.DescriptionClass()
                 {
                     ExecTime = lst[j].ExecuteTime ?? 0,
                     Score = lst[j].Score ?? 0,
                     IsScored = null != lst[j].Score
                 });
             }
             ret.Add(new OIStanding()
             {
                 IsVirtual = lst[i].Type == (int)AttendType.Virtual,
                 desp = desp,
                 TotalScore = desp.Sum(x => x.Score),
                 TotalTime = desp.Sum(x => x.ExecTime),
                 User = lst[i].User
             });
         }
         return ret;
     }
 }
Esempio n. 22
0
 /// <summary>
 /// 返回正在进行的比赛列表
 /// </summary>
 /// <param name="skip"></param>
 /// <param name="top"></param>
 /// <returns></returns>
 public static List<Contest> Testing(int skip, int top)
 {
     using (var db = new CHDB())
     {
         var cons = (from contest in db.CONTESTs
                     where contest.StartTime <= DateTime.Now && contest.EndTime >= DateTime.Now
                     select contest
                         ).OrderBy(x => x.StartTime).Skip(skip).Take(top).ToList();
         List<Contest> Ret=new List<Contest>();
         foreach (var c in cons)
         {
             var Own = (from u in c.OWNERs
                        select u.Name).ToList();
             Ret.Add(new Contest
                     {
                         ID = c.ID,
                         Name = c.Name,
                         Description = c.Description,
                         Type = (ContestType)c.Type,
                         RelativeStartTime = c.StartTime,
                         RelativeEndTime = c.EndTime,
                         IsOfficial = c.IsOfficial,
                         Owner = Own,
                         Owners = Own
                     });
         }
         return Ret;
     }
 }
Esempio n. 23
0
        /// <summary>
        /// 获得相应比赛的指定名称的题目
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        /// <exception cref="ProblemNotFoundException"></exception>
        public Problem ProblemByName(string name)
        {
            bool privillege = true;
            bool Admin = false;
            using (var db = new CHDB())
            {
                if (null == User.CurrentUser)
                {
                    privillege = false;
                }
                else
                {
                    if (!Owner.Contains(User.CurrentUser.name) && !User.CurrentUser.IsAdmin)
                    {
                        var con = (from c in db.CONTESTs
                                   where c.ID == ID
                                   select c).Single();
                        if (!IsAttended())
                        {
                            privillege = false;
                        }
                        else
                        {
                            if (DateTime.Now < RelativeStartTime)
                                privillege = false;
                        }
                    }
                    else
                        Admin = true;
                }
                var result = (from p in db.PROBLEMs
                              where p.Name == name && p.CONTEST1.ID==ID
                              select p).SingleOrDefault();
                if (null == result)
                    throw new ProblemNotFoundException();

                return new Problem()
                              {
                                  Name = result.Name,
                                  Content = privillege ? result.Content : null,
                                  Comparer = Admin ? result.Comparer : null,
                                  ID = result.ID,
                                  Contest = result.CONTEST1.Name,
                                  OriginRating = result.OriginRating,
                                  DataChecker = Admin ? result.DataChecker : null,
                                  DataCheckerLanguage = Admin ? ((Record.LanguageType?)result.DataCheckerLanguage) : null,
                                  ComparerLanguage = Admin ? ((Record.LanguageType?)result.ComparerLanguage) : null,
                                  Owner = result.OWNER.Name,
                                  contest = this,
                                  privillege = privillege
                              };
            }
        }
Esempio n. 24
0
 /// <summary>
 /// 返回 Testing 比赛个数
 /// </summary>
 /// <returns></returns>
 public static int TestingCount()
 {
     using (var db = new CHDB())
     {
         return (from c in db.CONTESTs
                 where c.StartTime <= DateTime.Now && c.EndTime >= DateTime.Now
                 select c).Count();
     }
 }
Esempio n. 25
0
        /// <summary>
        /// 重新计算Rating
        /// </summary>
        /// <exception cref="UserNotLoginException"></exception>
        /// <exception cref="PermissionDeniedException"></exception>
        public void ReCalcRating()
        {
            if (null == User.CurrentUser)
                throw new UserNotLoginException();
            if (!User.CurrentUser.IsAdmin && !Owner.Contains(User.CurrentUserName))
                throw new PermissionDeniedException();
            using (var db = new CHDB())
            {

                foreach (var r in (from r in db.RATINGs
                                   where r.CONTEST1.ID == ID
                                   select r))
                    db.RATINGs.Remove(r);
                (from c in db.CONTESTs
                 where c.ID == ID
                 select c).Single().Status = (int)StatusType.BeforeFinalTest;
                db.SaveChanges();
            }
        }
Esempio n. 26
0
 /// <summary>
 /// 添加题目 所有赛制必须填充 Name,Content,Comparer,Owner,DataChecker CF赛制还须填充OriginRating
 /// </summary>
 /// <param name="problem"></param>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="PermissionDeniedException"></exception>
 /// <exception cref="ProblemNameExistedException"></exception>
 /// <exception cref="UserNotFoundException"></exception>
 public void AddProblem(Problem problem)
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     if (!Owner.Contains(User.CurrentUser.name)
         && !User.CurrentUser.IsAdmin)
         throw new PermissionDeniedException();
     using (var db = new CHDB())
     {
         problem.Name = Helper.GetLegalName(problem.Name);
         if ((from p in db.PROBLEMs
              where p.Name == problem.Name && p.CONTEST1.ID==ID
              select p).Any())
             throw new ProblemNameExistedException();
         var owner = (from u in db.USERs
                      where u.Name == problem.Owner
                      select u).SingleOrDefault();
         if (null == owner)
             throw new UserNotFoundException();
         db.PROBLEMs.Add(new PROBLEM()
         {
             ID = Guid.NewGuid(),
             Name = problem.Name,
             Content = problem.Content,
             Comparer = problem.Comparer,
             ComparerLanguage = (int)problem.ComparerLanguage,
             OriginRating = problem.OriginRating,
             DataChecker = problem.DataChecker,
             DataCheckerLanguage = (int)problem.DataCheckerLanguage,
             CONTEST1 = (from c in db.CONTESTs
                         where c.ID == ID
                         select c).Single(),
             OWNER = owner
         });
         db.SaveChanges();
     }
 }
Esempio n. 27
0
        /// <summary>
        /// 删除指定名称的题目
        /// </summary>
        /// <param name="name"></param>
        /// <exception cref="ContestNotStartedException"></exception>
        /// <exception cref="UserNotLoginException"></exception>
        /// <exception cref="ProblemNotFoundException"></exception>
        public void RemoveProblem(string name)
        {
            if (null == User.CurrentUser)
                throw new UserNotLoginException();
            if (!Owner.Contains(User.CurrentUser.name)
                && !User.CurrentUser.IsAdmin)
                throw new PermissionDeniedException();

            using (var db = new CHDB())
            {
                var prob = (from p in db.PROBLEMs
                            where p.Name == name && p.CONTEST1.ID==ID
                            select p).SingleOrDefault();
                if (null == prob)
                    throw new ProblemNotFoundException();
                db.PROBLEMs.Remove(prob);
                db.SaveChanges();
            }
        }
Esempio n. 28
0
        /// <summary>
        /// 获得比赛报名名单
        /// </summary>
        /// <param name="skip"></param>
        /// <param name="top"></param>
        /// <returns></returns>
        public List<string> AttendedUsers(int skip, int top)
        {
            using (var db = new CHDB())
            {
                return (from u in
                            (from c in db.CONTESTs
                             where c.ID==ID
                             select c.CONTEST_ATTEND).Single()
                        orderby u.USER1.Name ascending
                        select u.USER1.Name).Skip(skip).Take(top).ToList();

            }
        }
Esempio n. 29
0
 /// <summary>
 /// 虚拟报名比赛
 /// </summary>
 /// <param name="startTime"></param>
 /// <exception cref="UserNotLoginException"></exception>
 /// <exception cref="AlreadyAttendedContestException"></exception>
 /// <exception cref="ContestNotStartedException"></exception>
 /// <exception cref="VirtualStartTooEarlyException"></exception>
 public void VirtualAttend(DateTime startTime)
 {
     if (null == User.CurrentUser)
         throw new UserNotLoginException();
     if (IsAttended())
         throw new AlreadyAttendedContestException();
     if (DateTime.Now <= RelativeStartTime)
         throw new ContestNotStartedException();
     if (DateTime.Now > startTime)
         throw new VirtualStartTooEarlyException();
     using (var db = new CHDB())
     {
         var con = (from c in db.CONTESTs
                    where c.ID==ID
                    select c).Single();
         con.CONTEST_ATTEND.Add(new CONTEST_ATTEND()
         {
             USER1 = (from u in db.USERs
                      where u.ID == User.CurrentUser.ID
                      select u).Single(),
             Type = (int)AttendType.Virtual,
             Time = startTime
         });
         db.SaveChanges();
     }
 }
Esempio n. 30
0
 /// <summary>
 /// 获得报名人数
 /// </summary>
 /// <returns></returns>
 public int AttendedUsersCount()
 {
     using (var db = new CHDB())
     {
         return (from c in db.CONTESTs
                 where c.ID==ID
                 select c.CONTEST_ATTEND).Single().Count();
     }
 }