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 });
        }
        public ActionResult Submit(Int32 id, FormCollection form)
        {
            SolutionEntity entity = new SolutionEntity()
            {
                ProblemID = id,
                SourceCode = form["code"],
                LanguageType = LanguageType.FromLanguageID(form["lang"])
            };

            Dictionary<String, Byte> supportLanguages = LanguageManager.MainSubmitSupportLanguages;

            if (!supportLanguages.ContainsValue(entity.LanguageType.ID))
            {
                return RedirectToErrorMessagePage("This problem 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");
        }
Beispiel #3
0
        /// <summary>
        /// 更新一条提交(更新所有评测信息)
        /// </summary>
        /// <param name="model">对象实体</param>
        /// <param name="error">编译错误信息</param>
        /// <returns>是否成功更新</returns>
        public static Boolean JudgeUpdateSolutionAllResult(SolutionEntity model, String error)
        {
            if (model == null) return false;

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

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

                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
Beispiel #4
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);//更新缓存
            }

            return success;
        }
        /// <summary>
        /// 更新评测状态
        /// </summary>
        /// <param name="sid">提交ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="username">用户名</param>
        /// <param name="result">评测结果</param>
        /// <param name="detail">出错信息</param>
        /// <param name="tcost">花费时间</param>
        /// <param name="mcost">花费内存</param>
        /// <param name="error">错误信息</param>
        /// <returns>是否更新成功</returns>
        public static Boolean TryUpdateSolutionStatus(String sid, String pid, String username, String result, String detail, String tcost, String mcost, out String error)
        {
            try
            {
                error = JudgeStatusManager.GetJudgeServerLoginStatus();

                if (!String.IsNullOrEmpty(error))
                {
                    return false;
                }

                SolutionEntity entity = new SolutionEntity()
                {
                    SolutionID = Int32.Parse(sid),
                    ProblemID = pid.ToInt32(0),
                    UserName = username,
                    Result = (ResultType)result.ToByte(0),
                    TimeCost = tcost.ToInt32(0),
                    MemoryCost = mcost.ToInt32(0)
                };

                if (entity.Result > ResultType.Accepted)//没有题目数据则评测失败 否则重新评测
                {
                    entity.Result = String.IsNullOrEmpty(ProblemDataManager.GetProblemDataRealPath(entity.ProblemID)) ? ResultType.JudgeFailed : ResultType.RejudgePending;
                }

                SolutionManager.JudgeUpdateSolutionAllResult(entity, detail);

                return true;
            }
            catch (System.Exception ex)
            {
                error = ex.Message;
                return false;
            }
        }