Exemplo n.º 1
0
        public ActionResult Reply(String id, FormCollection form)
        {
            ContestEntity    contest = ViewData["Contest"] as ContestEntity;
            ForumPostEntity  post    = ForumPostManager.GetForumPostByTopicID(id);
            ForumTopicEntity topic   = ForumTopicManager.GetForumTopic(post.TopicID);

            if (topic.Type != ForumTopicType.Contest || topic.RelativeID != contest.ContestID)
            {
                return(RedirectToErrorMessagePage("This contest does not have this topic!"));
            }

            ForumPostEntity reply = new ForumPostEntity()
            {
                Title   = form["title"],
                Content = form["content"]
            };

            String userip = this.GetCurrentUserIP();
            String link   = Url.Action("Topic", "Forum", new { area = "Contest", cid = contest.ContestID, id = post.TopicID });

            if (!ForumPostManager.InsertForumPost(reply, topic, post, userip, link))
            {
                return(RedirectToErrorMessagePage("Failed to post your reply!"));
            }

            return(RedirectToAction("Topic", "Forum", new { area = "Contest", cid = contest.ContestID, id = post.TopicID }));
        }
Exemplo n.º 2
0
        public ActionResult List(Int32 id = 1)
        {
            ContestEntity contest             = ViewData["Contest"] as ContestEntity;
            PagedList <ForumTopicEntity> list = ForumTopicManager.GetForumTopicList(id, contest.ContestID.ToString(), String.Empty);

            return(ViewWithPager(list, id));
        }
Exemplo n.º 3
0
        public ActionResult Submit(Int32 id, FormCollection form)
        {
            ContestEntity contest = ViewData["Contest"] as ContestEntity;
            ProblemEntity problem = ContestProblemManager.GetProblem(contest.ContestID, id);

            SolutionEntity entity = new SolutionEntity()
            {
                ProblemID        = problem.ProblemID,
                ContestID        = contest.ContestID,
                ContestProblemID = id,
                SourceCode       = form["code"],
                LanguageType     = LanguageType.FromLanguageID(form["lang"])
            };

            Dictionary <String, Byte> supportLanguages = LanguageManager.GetSupportLanguages(contest.SupportLanguage);

            if (!supportLanguages.ContainsValue(entity.LanguageType.ID))
            {
                return(RedirectToErrorMessagePage("This contest does not support this programming language."));
            }

            String userip = this.GetCurrentUserIP();

            if (!SolutionManager.InsertSolution(entity, userip))
            {
                return(RedirectToErrorMessagePage("Failed to submit your solution!"));
            }

            return(RedirectToAction("List", "Status", new { area = "Contest", cid = contest.ContestID }));
        }
Exemplo n.º 4
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            Int32 cid = filterContext.RouteData.GetInt32("cid", -1);

            if (cid <= 0)
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            ContestEntity contest       = ContestManager.GetContest(cid);
            Boolean       hasPermission = AdminManager.HasPermission(PermissionType.ContestManage);

            if (!hasPermission && contest.IsHide)
            {
                throw new NoPermissionException("You have no privilege to view this contest!");
            }

            if (!hasPermission && contest.StartTime > DateTime.Now)
            {
                throw new NoPermissionException("This contest has not been started yet!");
            }

            if (!hasPermission && (contest.ContestType == ContestType.Private || contest.ContestType == ContestType.RegisterPrivate))
            {
                if (!ContestUserManager.ContestContainsUser(contest.ContestID, UserManager.CurrentUserName))
                {
                    throw new NoPermissionException("You have no privilege to view this contest!");
                }
            }

            filterContext.ActionParameters["Contest"] = contest;
            ViewData["Contest"] = contest;
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据ID得到一个竞赛实体
        /// </summary>
        /// <param name="id">竞赛ID</param>
        /// <returns>竞赛实体</returns>
        public static ContestEntity GetContest(Int32 id)
        {
            if (id < ContestRepository.NONECONTEST)
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            ContestEntity contest = ContestCache.GetContestCache(id);//获取缓存

            if (contest == null)
            {
                contest = ContestRepository.Instance.GetEntity(id);
                ContestCache.SetContestCache(contest);//设置缓存
            }

            if (contest == null)
            {
                throw new NullResponseException(RequestType.Contest);
            }

            if (contest.IsHide && !AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException("You have no privilege to view the contest!");
            }

            return(contest);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 根据ID得到一个需要注册的竞赛实体
        /// </summary>
        /// <param name="id">竞赛ID</param>
        /// <returns>竞赛实体</returns>
        public static ContestEntity GetRegisterContest(Int32 id)
        {
            ContestEntity contest = ContestManager.GetContest(id);

            if (contest.ContestType != ContestType.RegisterPrivate && contest.ContestType != ContestType.RegisterPublic)
            {
                if (contest.ContestType == ContestType.Public)
                {
                    throw new NoPermissionException("You don't need to register for this contest!");
                }
                else
                {
                    throw new NoPermissionException("You can not register for this contest!");
                }
            }

            if (contest.RegisterStartTime > DateTime.Now)
            {
                throw new NoPermissionException("This contest registration has not been started yet!");
            }

            if (contest.RegisterEndTime < DateTime.Now)
            {
                throw new NoPermissionException("This contest has registration ended!");
            }

            return(contest);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 向缓存中写入指定竞赛信息
 /// </summary>
 /// <param name="contest">指定竞赛信息</param>
 public static void SetContestCache(ContestEntity contest)
 {
     if (contest != null)
     {
         CacheManager.Set(GetContestCacheKey(contest.ContestID), contest);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// 使用给定的比赛实体对象创建 ContestDataProvider 类的新实例。
 /// </summary>
 /// <param name="context">数据上下文对象。</param>
 /// <param name="entity">比赛实体对象。</param>
 /// <param name="access">比赛数据底层访问对象。</param>
 /// <param name="isReadonly">一个值,该值指示当前对象是否为只读对象。</param>
 /// <exception cref="ArgumentNullException"/>
 private ContestDataProvider(ContestDataContext context, ContestEntity entity, bool isReadonly)
 {
     m_context  = context ?? throw new ArgumentNullException(nameof(context));
     m_entity   = entity ?? throw new ArgumentNullException(nameof(entity));
     m_access   = new ContestAccessHandle(entity);
     m_readonly = isReadonly;
     m_disposed = false;
 }
Exemplo n.º 9
0
        public ActionResult Register(Int32 id = -1)
        {
            ContestEntity entity = ContestManager.GetRegisterContest(id);

            ViewBag.UserName = UserManager.CurrentUserName;

            return(View(entity));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 使用指定的比赛实体对象创建 ContestEntryHandle 类的新实例。
        /// </summary>
        /// <param name="entity">比赛实体对象。</param>
        /// <exception cref="ArgumentNullException"/>
        public ContestAccessHandle(ContestEntity entity)
        {
            m_entity   = entity ?? throw new ArgumentNullException(nameof(entity));
            m_config   = null;
            m_disposed = false;

            LoadConfigurationModel();
        }
Exemplo n.º 11
0
        /// <summary>
        /// 从给定的比赛实体对象创建 ContestHandle 类的新实例。
        /// </summary>
        /// <param name="entity">比赛实体对象。</param>
        /// <returns>从给定的比赛实体对象创建的 ContestHandle 对象。</returns>
        /// <exception cref="ArgumentNullException"/>
        internal static ContestHandle FromContestEntity(ContestEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            return(new ContestHandle(entity.Id));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 从数据库中移除给定的比赛数据实体。
        /// </summary>
        /// <param name="entity">要移除的比赛实体对象。</param>
        /// <exception cref="ArgumentNullException"/>
        public void RemoveContest(ContestEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            Contests.Remove(entity);
        }
Exemplo n.º 13
0
        public ActionResult Show(Int32 id = -1)
        {
            ContestEntity contest = ViewData["Contest"] as ContestEntity;
            ProblemEntity entity  = ContestProblemManager.GetProblem(contest.ContestID, id);

            ViewBag.ContestProblemID = id.ToString();

            return(View(entity));
        }
Exemplo n.º 14
0
        /// <summary>
        /// 将给定的比赛实体数据添加至数据库中。
        /// </summary>
        /// <param name="entity">要添加的比赛实体。</param>
        /// <exception cref="ArgumentNullException"/>
        public void AddContest(ContestEntity entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }

            Contests.Add(entity);
            SaveChanges();
        }
Exemplo n.º 15
0
        /// <summary>
        /// 更新竞赛信息
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContest(ContestEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Contest title cannot be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("Contest description cannot be NULL!"));
            }

            if (entity.StartTime >= entity.EndTime)
            {
                return(MethodResult.FailedAndLog("Start time must be less than end time!"));
            }

            if (entity.ContestType == ContestType.RegisterPrivate || entity.ContestType == ContestType.RegisterPublic)
            {
                if (!entity.RegisterStartTime.HasValue || !entity.RegisterEndTime.HasValue)
                {
                    return(MethodResult.FailedAndLog("Register time cannot be NULL!"));
                }

                if (entity.RegisterStartTime >= entity.RegisterEndTime)
                {
                    return(MethodResult.FailedAndLog("Register start time must be less than register end time!"));
                }

                if (entity.RegisterEndTime >= entity.StartTime)
                {
                    return(MethodResult.FailedAndLog("Register end time must be less than contest start time!"));
                }
            }

            entity.LastDate = DateTime.Now;

            Boolean success = ContestRepository.Instance.UpdateEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No contest was updated!"));
            }

            ContestCache.RemoveContestCache(entity.ContestID); //删除缓存
            ContestCache.RemoveContestListCountCache();        //删除缓存

            return(MethodResult.SuccessAndLog("Admin update contest, id = {0}", entity.ContestID.ToString()));
        }
Exemplo n.º 16
0
        public ActionResult List()
        {
            ContestEntity contest = ViewData["Contest"] as ContestEntity;

            List <RankItem>             ranklist = ContestManager.GetContestRanklist(contest);
            List <ContestProblemEntity> problems = ContestProblemManager.GetContestProblemList(contest.ContestID);

            ViewBag.Problems = problems;

            return(View(ranklist));
        }
Exemplo n.º 17
0
        public ActionResult Submit(Int32 id = -1)
        {
            ContestEntity contest = ViewData["Contest"] as ContestEntity;
            ProblemEntity problem = ContestProblemManager.GetProblem(contest.ContestID, id);
            IEnumerable <SelectListItem> items = this.GetLanguageItems(contest.SupportLanguage);

            ViewBag.Languages        = items;
            ViewBag.ContestProblemID = id.ToString();

            return(View(problem));
        }
Exemplo n.º 18
0
        public ActionResult Set()
        {
            ContestEntity        contest = ViewData["Contest"] as ContestEntity;
            List <ProblemEntity> list    = ContestProblemManager.GetProblemSet(contest.ContestID);

            Dictionary <Int32, Int16> userSubmits = SolutionManager.GetUserContestSubmit(contest.ContestID);

            ViewBag.UserSubmits = userSubmits;

            return(View(list));
        }
Exemplo n.º 19
0
        public ActionResult Statistics()
        {
            ContestEntity contest = ViewData["Contest"] as ContestEntity;

            IDictionary <Int32, ContestProblemStatistic> statistics = SolutionManager.GetContestStatistic(contest.ContestID);
            List <ContestProblemEntity> problems = ContestProblemManager.GetContestProblemList(contest.ContestID);
            Dictionary <String, Byte>   langs    = LanguageManager.GetSupportLanguages(contest.SupportLanguage);

            ViewBag.Problems  = problems;
            ViewBag.Languages = langs;

            return(View(statistics));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 竞赛添加页面
        /// </summary>
        /// <returns>操作后的结果</returns>
        public ActionResult Add()
        {
            DateTime      now    = DateTime.Today.AddHours(DateTime.Now.Hour + 1);
            ContestEntity entity = new ContestEntity()
            {
                StartTime = now,
                EndTime   = now.AddHours(2)
            };

            ViewBag.AllSupportedLanguages = LanguageManager.GetAllLanguageNames();

            return(View("Edit", entity));
        }
Exemplo n.º 21
0
        /// <summary>
        /// 讨论版主题页面
        /// </summary>
        /// <param name="id">主题ID</param>
        /// <returns>操作后的结果</returns>
        public ActionResult Topic(Int32 id = -1)
        {
            ContestEntity    contest = ViewData["Contest"] as ContestEntity;
            ForumPostEntity  post    = ForumPostManager.GetForumPostByTopicID(id.ToString());
            ForumTopicEntity topic   = ForumTopicManager.GetForumTopic(post.TopicID);

            if (topic.Type != ForumTopicType.Contest || topic.RelativeID != contest.ContestID)
            {
                return(RedirectToErrorMessagePage("This contest does not have this topic!"));
            }

            List <ForumPostEntity> list = ForumPostManager.GetForumPostList(topic, false);

            return(View(new Tuple <ForumTopicEntity, List <ForumPostEntity> >(topic, list)));
        }
Exemplo n.º 22
0
 /// <summary>
 /// 从给定的比赛 ID 创建 ContestHandle 类的新实例。
 /// </summary>
 /// <param name="contestId">比赛 ID。</param>
 /// <returns>从给定的比赛 ID 创建的 ContestHandle 类对象。若数据库中不存在这样的比赛实体对象,返回 null。</returns>
 public ContestHandle QueryContestById(int contestId)
 {
     return(m_factory.WithContext(context =>
     {
         ContestEntity entity = context.QueryContestById(contestId);
         if (entity == null)
         {
             return null;
         }
         else
         {
             return ContestHandle.FromContestEntity(entity);
         }
     }));
 }
Exemplo n.º 23
0
        /// <summary>
        /// 创建一个新的比赛并返回相应的比赛句柄。
        /// </summary>
        /// <returns></returns>
        public ContestHandle CreateContest()
        {
            // 创建新的比赛实体对象。
            return(m_factory.WithContext(context =>
            {
                ContestEntity entity = new ContestEntity();
                entity = context.AddContest(entity);

                // 为新创建的比赛分配配置文件。
                entity.ContestConfigurationFile = string.Concat(ContestDirectory, "\\", entity.Id);
                context.SaveChanges();

                return ContestHandle.FromContestEntity(entity);
            }));
        }
Exemplo n.º 24
0
        /// <summary>
        /// 删除给定比赛 ID 所对应的比赛。
        /// </summary>
        /// <param name="contestId">比赛 ID。</param>
        public void RemoveContest(int contestId)
        {
            m_factory.WithContext(context =>
            {
                ContestEntity entity = context.QueryContestById(contestId);
                if (entity != null)
                {
                    // 删除本地配置文件。
                    File.Delete(entity.ContestConfigurationFile);

                    // 从数据上下文中删除数据实体对象。
                    context.RemoveContest(entity);
                    context.SaveChanges();
                }
            });
        }
Exemplo n.º 25
0
        public ActionResult List(Int32 id = 1, Int32 pid = -1, String name = "", String lang = "", String type = "")
        {
            ContestEntity             contest = ViewData["Contest"] as ContestEntity;
            Dictionary <String, Byte> langs   = LanguageManager.GetSupportLanguages(contest.SupportLanguage);

            ViewBag.Languages = langs;

            PagedList <SolutionEntity> list = SolutionManager.GetSolutionList(id, contest.ContestID, pid, name, lang, type, null);

            ViewBag.ProblemID  = pid;
            ViewBag.UserName   = name;
            ViewBag.Language   = lang;
            ViewBag.SearchType = type;

            return(ViewWithPager(list, id));
        }
Exemplo n.º 26
0
        public ActionResult Add(FormCollection form)
        {
            ContestEntity entity = new ContestEntity()
            {
                Title             = form["title"],
                ContestType       = (ContestType)Byte.Parse(form["type"]),
                Description       = form["description"],
                StartTime         = DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["startdate"], form["starthour"], form["startminute"], form["startsecond"])),
                EndTime           = DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["enddate"], form["endhour"], form["endminute"], form["endsecond"])),
                RegisterStartTime = String.IsNullOrEmpty(form["regstartdate"]) ? new Nullable <DateTime>() : DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["regstartdate"], form["regstarthour"], form["regstartminute"], form["regstartsecond"])),
                RegisterEndTime   = String.IsNullOrEmpty(form["regenddate"]) ? new Nullable <DateTime>() : DateTime.Parse(String.Format("{0} {1}:{2}:{3}", form["regenddate"], form["regendhour"], form["regendminute"], form["regendsecond"])),
                SupportLanguage   = form["supportlangs"]
            };

            return(ResultToMessagePage(ContestManager.AdminInsertContest, entity, "Your have added contest successfully!"));
        }
Exemplo n.º 27
0
        public ActionResult New(FormCollection form)
        {
            ContestEntity    contest = ViewData["Contest"] as ContestEntity;
            ForumTopicEntity topic   = new ForumTopicEntity()
            {
                Title = form["title"],
            };

            String userip = this.GetCurrentUserIP();

            if (!ForumTopicManager.InsertForumTopic(topic, contest.ContestID.ToString(), String.Empty, form["content"], userip))
            {
                return(RedirectToErrorMessagePage("Failed to post your topic!"));
            }

            return(RedirectToAction("List", "Forum", new { area = "Contest", cid = contest.ContestID }));
        }
Exemplo n.º 28
0
        /// <summary>
        /// 获取竞赛排行Excel文件
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="userrealnames">用户姓名对照表</param>
        /// <returns>竞赛排行</returns>
        public static IMethodResult AdminGetExportRanklist(Int32 cid, String userrealnames)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            ContestEntity contest = ContestManager.GetContest(cid);
            Dictionary <String, String>   userdict    = null;
            Dictionary <String, RankItem> rank        = SolutionRepository.Instance.GetContestRanklist(contest.ContestID, contest.StartTime);
            List <ContestProblemEntity>   problemlist = ContestProblemManager.GetContestProblemList(contest.ContestID);
            List <RankItem> list = new List <RankItem>();

            foreach (RankItem userRank in rank.Values)
            {
                list.Add(userRank);
            }

            list.Sort();

            if (!String.IsNullOrEmpty(userrealnames))
            {
                userdict = new Dictionary <String, String>();
                String[] nametable = userrealnames.Lines();

                for (Int32 i = 0; i < nametable.Length; i++)
                {
                    if (String.IsNullOrEmpty(nametable[i]))
                    {
                        continue;
                    }

                    String[] namepair = nametable[i].Replace('\t', ' ').Split(' ');

                    if (namepair.Length == 2 && !String.IsNullOrEmpty(namepair[0]) && !String.IsNullOrEmpty(namepair[1]))
                    {
                        userdict.Add(namepair[0], namepair[1]);
                    }
                }
            }

            Byte[] data = ContestResultExport.ExportResultToExcel(contest, problemlist, list, userdict);

            return(MethodResult.SuccessAndLog <Byte[]>(data, "Admin export contest result, id = {0}", cid.ToString()));
        }
Exemplo n.º 29
0
        /// <summary>
        /// 从给定的题目句柄创建 ContestDataProvider 类的新实例。
        /// </summary>
        /// <param name="handle">比赛句柄。</param>
        /// <param name="isReadonly">一个值,该值指示当前对象是否为只读对象。</param>
        /// <returns>从给定的题目句柄创建的 ContestDataProvider 对象。</returns>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ContestNotFoundException"/>
        public static ContestDataProvider Create(ContestHandle handle, bool isReadonly)
        {
            if (handle == null)
            {
                throw new ArgumentNullException(nameof(handle));
            }

            ContestDataContext context = new ContestDataContextFactory().CreateContext();
            ContestEntity      entity  = context.QueryContestById(handle.ContestId);

            if (entity == null)
            {
                context.Dispose();
                throw new ContestNotFoundException(handle);
            }

            return(new ContestDataProvider(context, entity, isReadonly));
        }
Exemplo n.º 30
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            ContestEntity contest       = filterContext.ActionParameters["Contest"] as ContestEntity;
            Boolean       hasPermission = AdminManager.HasPermission(PermissionType.ContestManage);

            if (contest.EndTime < DateTime.Now)
            {
                throw new NoPermissionException("This contest has ended!");
            }

            if (!hasPermission && contest.ContestType == ContestType.RegisterPublic)
            {
                if (!ContestUserManager.ContestContainsUser(contest.ContestID, UserManager.CurrentUserName))
                {
                    throw new NoPermissionException("You have no privilege to submit in this contest!");
                }
            }
        }