Example #1
0
        /// <summary>
        /// 获取提交总数
        /// </summary>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="languageType">提交语言</param>
        /// <param name="resultType">提交结果</param>
        /// <returns>提交总数</returns>
        private static Int32 CountSolutions(Int32 cid, Int32 pid, String userName, String languageType, String resultType)
        {
            if (pid <= 0 && String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(languageType) && String.IsNullOrEmpty(resultType))
            {
                Int32 recordCount = SolutionCache.GetSolutionCountCache(cid);//获取缓存

                if (recordCount < 0)
                {
                    recordCount = SolutionRepository.Instance.CountEntities(cid, -1, null, LanguageType.Null, new Nullable <ResultType>());
                    SolutionCache.SetSolutionCountCache(cid, recordCount);//设置缓存
                }

                return(recordCount);
            }
            else
            {
                Byte langType, resType;
                Byte.TryParse(languageType, out langType);
                Byte.TryParse(resultType, out resType);

                return(SolutionRepository.Instance.CountEntities(
                           cid, pid, userName,
                           (String.IsNullOrEmpty(languageType) ? LanguageType.Null : LanguageType.FromLanguageID(langType)),
                           (String.IsNullOrEmpty(resultType) ? new Nullable <ResultType>() : (ResultType)resType)));
            }
        }
Example #2
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 }));
        }
Example #3
0
        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"));
        }
Example #4
0
        protected override SolutionEntity CreateEntity(Object sender, EntityCreatingArgs args)
        {
            SolutionEntity entity = new SolutionEntity();

            entity.SolutionID       = this.LoadInt32(args, SOLUTIONID);
            entity.ProblemID        = this.LoadInt32(args, PROBLEMID);
            entity.UserName         = this.LoadString(args, USERNAME);
            entity.SourceCode       = this.LoadString(args, SOURCECODE);
            entity.LanguageType     = LanguageType.FromLanguageID(this.LoadByte(args, LANGUAGE));
            entity.Result           = (ResultType)this.LoadByte(args, RESULT);
            entity.CodeLength       = this.LoadInt32(args, CODELENGTH);
            entity.ContestID        = this.LoadInt32(args, CONTESTID);
            entity.ContestProblemID = this.LoadInt32(args, CONTESTPROBLEMID);
            entity.TimeCost         = this.LoadInt32(args, TIMECOST);
            entity.MemoryCost       = this.LoadInt32(args, MEMORYCOST);
            entity.SubmitTime       = this.LoadDateTime(args, SUBMITTIME);
            entity.JudgeTime        = this.LoadDateTime(args, JUDGETIME);

            return(entity);
        }
Example #5
0
        /// <summary>
        /// 获取提交列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="languageType">提交语言</param>
        /// <param name="resultType">提交结果</param>
        /// <param name="order">排序顺序</param>
        /// <returns>提交列表</returns>
        public static PagedList <SolutionEntity> GetSolutionList(Int32 pageIndex, Int32 cid, Int32 pid, String userName, String languageType, String resultType, String order)
        {
            Int32 pageSize             = SolutionManager.STATUS_PAGE_SIZE;
            Int32 recordCount          = 0;
            List <SolutionEntity> list = null;

            if (pid <= 0 && String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(languageType) && String.IsNullOrEmpty(resultType))
            {
                recordCount = SolutionManager.CountSolutions(cid, -1, null, null, null);
                list        = SolutionRepository.Instance.GetEntities(cid, -1, null, LanguageType.Null, new Nullable <ResultType>(), -1,
                                                                      pageIndex, pageSize, recordCount);
            }
            else
            {
                if (!String.IsNullOrEmpty(userName) && (!RegexVerify.IsUserName(userName) || !SQLValidator.IsSafe(userName)))
                {
                    throw new InvalidInputException("Username is INVALID!");
                }
                if (!String.IsNullOrEmpty(languageType) && !RegexVerify.IsNumeric(languageType))
                {
                    throw new InvalidInputException("Language Type is INVALID!");
                }
                if (!String.IsNullOrEmpty(resultType) && !RegexVerify.IsNumeric(resultType))
                {
                    throw new InvalidInputException("Result Type is INVALID!");
                }

                recordCount = SolutionManager.CountSolutions(cid, pid, userName, languageType, resultType);
                list        = SolutionRepository.Instance.GetEntities(
                    cid, pid, userName,
                    (String.IsNullOrEmpty(languageType) ? LanguageType.Null : LanguageType.FromLanguageID(Convert.ToByte(languageType))),
                    (String.IsNullOrEmpty(resultType) ? new Nullable <ResultType>() : (ResultType)Convert.ToByte(resultType)),
                    (String.IsNullOrEmpty(order) ? -1 : Convert.ToInt32(order)),
                    pageIndex, pageSize, recordCount);
            }

            return(list.ToPagedList(pageSize, recordCount));
        }
Example #6
0
        private static Boolean AdminGetSolutionParams(String sids, String cid, String pid, String name, String lang, String type, String startDate, String endDate,
                                                      out String solutionIDs, out Int32 problemID, out Int32 contestID, out String userName, out LanguageType languageType, out ResultType?resultType, out DateTime?dtStart, out DateTime?dtEnd)
        {
            Boolean noCondition = true;
            String  dateFormat  = "yyyy-MM-dd HH:mm:ss";

            solutionIDs  = String.Empty;
            contestID    = -1;
            problemID    = -1;
            userName     = String.Empty;
            languageType = LanguageType.Null;
            resultType   = new Nullable <ResultType>();
            dtStart      = null;
            dtEnd        = null;

            if (!String.IsNullOrEmpty(sids))
            {
                solutionIDs = sids.SearchOptimized();

                if (!RegexVerify.IsNumericIDs(solutionIDs))
                {
                    throw new InvalidRequstException(RequestType.Solution);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(cid))
            {
                if (!Int32.TryParse(cid, out contestID))
                {
                    throw new InvalidRequstException(RequestType.Contest);
                }

                if (contestID < ContestRepository.NONECONTEST)
                {
                    throw new InvalidRequstException(RequestType.Contest);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(pid))
            {
                if (!Int32.TryParse(pid, out problemID))
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

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

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(name))
            {
                if (!RegexVerify.IsUserName(name))
                {
                    throw new InvalidRequstException(RequestType.User);
                }

                userName    = name;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(lang))
            {
                Byte langType = Byte.MaxValue;

                if (!Byte.TryParse(lang, out langType))
                {
                    throw new InvalidInputException("Language Type is INVALID!");
                }

                languageType = LanguageType.FromLanguageID(langType);
                noCondition  = false;
            }

            if (!String.IsNullOrEmpty(type))
            {
                Byte resType = Byte.MaxValue;

                if (!Byte.TryParse(type, out resType))
                {
                    throw new InvalidInputException("Result Type is INVALID!");
                }

                resultType  = (ResultType)resType;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(startDate))
            {
                DateTime temp;
                if (!DateTime.TryParseExact(startDate, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    throw new InvalidInputException("Datetime is INVALID!");
                }

                dtStart     = temp;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(endDate))
            {
                DateTime temp;
                if (!DateTime.TryParseExact(endDate, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    throw new InvalidInputException("Datetime is INVALID!");
                }

                dtEnd = temp;

                if (dtStart.HasValue && dtStart.Value >= dtEnd.Value)
                {
                    throw new InvalidInputException("Start date CANNOT be later than end date!");
                }

                noCondition = false;
            }

            return(noCondition);
        }