Beispiel #1
0
        /// <summary>
        /// 更新一条提交(更新所有评测信息)
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <param name="error">编译错误信息</param>
        /// <returns>是否成功更新</returns>
        public static Boolean JudgeUpdateSolutionAllResult(SolutionEntity entity, String error)
        {
            if (entity == null)
            {
                return(false);
            }

            lock (_updateLock)
            {
                entity.JudgeTime = DateTime.Now;

                if (SolutionRepository.Instance.UpdateEntity(entity, error) > 0)
                {
                    if (entity.Result == ResultType.Accepted)
                    {
                        UserCache.RemoveUserTop10Cache();
                    }

                    SolutionCache.RemoveAcceptedCodesCache(entity.UserName);
                    SolutionCache.RemoveProblemIDListCache(entity.UserName, false);
                    SolutionCache.RemoveProblemIDListCache(entity.UserName, true);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Beispiel #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);
        }