コード例 #1
0
        /// <summary>
        /// 获取题目统计信息
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <returns>题目统计信息实体</returns>
        public static ProblemStatistic GetProblemStatistic(Int32 cid, Int32 pid)
        {
            //此处不能验证cid,因为普通Problem的Statistic也经由此方法

            if (pid < ConfigurationManager.ProblemSetStartID)
            {
                throw new InvalidRequstException(RequestType.Problem);
            }

            //验证pid有效性
            if (cid < 0)//非竞赛题目
            {
                ProblemEntity entity = ProblemManager.GetProblem(pid);
                pid = entity.ProblemID;
            }
            else//竞赛题目
            {
                ProblemEntity entity = ContestProblemManager.GetProblem(cid, pid);
                //竞赛题目传入的pid是ContestProblemID
            }

            ProblemStatistic statistic = SolutionCache.GetProblemStatisticCache(cid, pid);

            if (statistic == null)
            {
                statistic = SolutionRepository.Instance.GetProblemStatistic(cid, pid);//一定有返回值
            }

            return(statistic);
        }
コード例 #2
0
        /// <summary>
        /// 增加一条提交
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <param name="userip">用户IP</param>
        /// <returns>是否成功增加</returns>
        public static Boolean InsertSolution(SolutionEntity entity, String userip)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(entity.SourceCode) || entity.SourceCode.Length < SolutionRepository.SOURCECODE_MINLEN)
            {
                throw new InvalidInputException("Code is too short!");
            }

            if (entity.SourceCode.Length > SolutionRepository.SOURCECODE_MAXLEN)
            {
                throw new InvalidInputException("Code is too long!");
            }

            if (LanguageType.IsNull(entity.LanguageType))
            {
                throw new InvalidInputException("Language Type is INVALID!");
            }

            if (!UserSubmitStatus.CheckLastSubmitSolutionTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit code more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            ProblemEntity problem = ProblemManager.InternalGetProblemModel(entity.ProblemID);

            if (problem == null)//判断题目是否存在
            {
                throw new NullResponseException(RequestType.Problem);
            }

            if (entity.ContestID <= 0 && problem.IsHide && !AdminManager.HasPermission(PermissionType.ProblemManage))//非竞赛下判断是否有权访问题目
            {
                throw new NoPermissionException("You have no privilege to submit the problem!");
            }

            entity.UserName   = UserManager.CurrentUserName;
            entity.SubmitTime = DateTime.Now;
            entity.SubmitIP   = userip;

            Boolean success = SolutionRepository.Instance.InsertEntity(entity) > 0;

            if (success)
            {
                ProblemCache.UpdateProblemCacheSubmitCount(entity.ProblemID, -1);//更新缓存
                SolutionCache.RemoveProblemIDListCache(entity.UserName, true);
            }

            return(success);
        }
コード例 #3
0
ファイル: ProblemManager.cs プロジェクト: sanshengshi/sdnuoj
        /// <summary>
        /// 获取题目列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <returns>题目列表</returns>
        public static PagedList <ProblemEntity> AdminGetProblemList(Int32 pageIndex)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ProblemManager.AdminCountProblems();

            return(ProblemRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount)
                   .ToPagedList(pageSize, recordCount));
        }
コード例 #4
0
ファイル: ProblemManager.cs プロジェクト: sanshengshi/sdnuoj
        /// <summary>
        /// 根据题目搜索结果获取题目列表
        /// </summary>
        /// <param name="type">搜索类别</param>
        /// <param name="content">搜索内容</param>
        /// <returns>题目列表</returns>
        public static List <ProblemEntity> GetProblemBySearch(String type, String content)
        {
            List <ProblemEntity> list = null;

            if (String.Equals(type, "category", StringComparison.OrdinalIgnoreCase))
            {
                Int32 typeID = -1;

                if (!Int32.TryParse(content, out typeID) || typeID <= 0)
                {
                    throw new InvalidRequstException(RequestType.ProblemCategory);
                }

                list = ProblemManager.GetProblemListByType(typeID);
            }
            else if (String.Equals(type, "pid", StringComparison.OrdinalIgnoreCase))
            {
                content = content.SearchOptimized();

                if (!RegexVerify.IsNumericIDs(content))
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                list = ProblemManager.GetProblemListByID(content);
            }
            else if (String.Equals(type, "title", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrEmpty(content) || !SQLValidator.IsNonNullANDSafe(content))
                {
                    throw new InvalidInputException("Problem Title is INVALID!");
                }

                list = ProblemManager.GetProblemListByTitle(content);
            }
            else if (String.Equals(type, "source", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrEmpty(content) || !SQLValidator.IsNonNullANDSafe(content))
                {
                    throw new InvalidInputException("Problem Source is INVALID!");
                }

                list = ProblemManager.GetProblemListBySource(content);
            }

            list = GetUserCanViewProblemList(list);

            return(list);
        }
コード例 #5
0
ファイル: ProblemManager.cs プロジェクト: sanshengshi/sdnuoj
        /// <summary>
        /// 获取题目列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="pageSize">页面大小</param>
        /// <returns>题目列表</returns>
        public static PagedList <ProblemEntity> GetProblemSet(Int32 pageIndex)
        {
            Int32 pageSize    = ProblemManager.PROBLEM_SET_PAGE_SIZE;
            Int32 recordCount = ProblemManager.CountProblemsByMaxID();

            List <ProblemEntity> list = ProblemCache.GetProblemSetCache(pageIndex);//获取缓存

            if (list == null)
            {
                list = ProblemRepository.Instance.GetEntitiesForProblemSet(pageIndex, pageSize);
                ProblemCache.SetProblemSetCache(pageIndex, list);//设置缓存
            }

            list = ProblemManager.GetUserCanViewProblemList(list);

            return(list.ToPagedList(pageSize, recordCount));
        }
コード例 #6
0
ファイル: ProblemManager.cs プロジェクト: sanshengshi/sdnuoj
        /// <summary>
        /// 根据ID得到一个题目实体
        /// </summary>
        /// <param name="id">题目ID</param>
        /// <returns>题目实体</returns>
        public static ProblemEntity GetProblem(Int32 id)
        {
            if (id < ConfigurationManager.ProblemSetStartID)
            {
                throw new InvalidRequstException(RequestType.Problem);
            }

            ProblemEntity problem = ProblemManager.InternalGetProblemModel(id);

            if (problem == null)
            {
                throw new NullResponseException(RequestType.Problem);
            }

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

            return(problem);
        }
コード例 #7
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> GetForumTopicList(Int32 pageIndex, String cid, String pid)
        {
            ForumTopicType type       = ForumTopicManager.GetForumTopicType(cid, pid);
            Int32          relativeID = ForumTopicManager.GetRelativeID(cid, pid);

            if (type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(relativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(relativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            Int32 pageSize    = ForumTopicManager.FORUM_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.CountForumTopics(cid, pid);

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, type, relativeID, false)
                   .ToPagedList(pageSize, recordCount));
        }
コード例 #8
0
        /// <summary>
        /// 发布新主题
        /// </summary>
        /// <param name="topic">主题实体</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="content">主题帖内容</param>
        /// <param name="postip">发布者IP</param>
        /// <returns>是否成功发布</returns>
        public static Boolean InsertForumTopic(ForumTopicEntity topic, String cid, String pid, String content, String postip)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(topic.Title))
            {
                throw new InvalidInputException("Topic title can not be NULL!");
            }

            if (topic.Title.Length > ForumPostRepository.TITLE_MAXLEN)
            {
                throw new InvalidInputException("Topic title is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(topic.Title))
            {
                throw new InvalidInputException("Topic title can not contain illegal keywords!");
            }

            if (String.IsNullOrEmpty(content) || content.Length < ForumPostRepository.POST_MINLEN)
            {
                throw new InvalidInputException("Topic content is too short!");
            }

            if (content.Length > ForumPostRepository.POST_MAXLEN)
            {
                throw new InvalidInputException("Topic content is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(content))
            {
                throw new InvalidInputException("Topic content can not contain illegal keywords!");
            }

            if (!UserSubmitStatus.CheckLastSubmitForumPostTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit post more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            topic.Type       = ForumTopicManager.GetForumTopicType(cid, pid);
            topic.RelativeID = (topic.Type == ForumTopicType.Default ? 0 : ForumTopicManager.GetRelativeID(cid, pid));

            if (topic.Type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (topic.Type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            topic.UserName = UserManager.CurrentUserName;
            topic.LastDate = DateTime.Now;
            topic.Title    = HtmlEncoder.HtmlEncode(topic.Title);
            content        = HtmlEncoder.HtmlEncode(content);

            Boolean success = ForumTopicRepository.Instance.InsertEntity(topic, content, postip) > 0;

            if (success)
            {
                ForumTopicCache.IncreaseForumTopicCountCache(topic.Type, topic.RelativeID);//更新缓存

                if (topic.Type == ForumTopicType.Problem)
                {
                    ForumTopicCache.IncreaseForumTopicCountCache(ForumTopicType.Default, 0);//更新缓存
                }
            }

            return(success);
        }