예제 #1
0
        /// <summary>
        /// 获取评测列表的Json信息
        /// </summary>
        /// <param name="lanaugeSupport">评测机支持语言</param>
        /// <param name="count">评测机请求个数</param>
        /// <returns>评测列表Json信息</returns>
        public static Boolean TryGetPendingListJson(String lanaugeSupport, String count, out String result, out String error)
        {
            result = String.Empty;

            try
            {
                error = JudgeStatusManager.GetJudgeServerLoginStatus();

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

                StringBuilder         ret          = new StringBuilder();
                Int32                 requestCount = Math.Max(1, count.ToInt32(1));
                List <SolutionEntity> pendingList  = SolutionManager.JudgeGetPendingSolution(requestCount, GetJudgeSupportLanguages(lanaugeSupport));

                Dictionary <Int32, ProblemEntity> problemCache        = new Dictionary <Int32, ProblemEntity>();
                Dictionary <Int32, String>        problemVersionCache = new Dictionary <Int32, String>();

                ProblemEntity  problem            = null;
                String         problemDataVersion = String.Empty;
                SolutionEntity solution           = null;
                Int32          listCount          = (pendingList == null ? 0 : pendingList.Count);

                ret.Append("[");

                for (Int32 i = 0; i < listCount; i++)
                {
                    if (i > 0)
                    {
                        ret.Append(",");
                    }

                    solution = pendingList[i];

                    if (!problemCache.TryGetValue(solution.ProblemID, out problem))
                    {
                        problem = ProblemManager.GetJudgeProblem(solution.ProblemID);
                        problemCache[solution.ProblemID] = problem;
                    }

                    if (!problemVersionCache.TryGetValue(solution.ProblemID, out problemDataVersion))
                    {
                        problemDataVersion = ProblemDataManager.GetProblemDataVersion(solution.ProblemID);
                        problemVersionCache[solution.ProblemID] = problemDataVersion;
                    }

                    if (problem != null)
                    {
                        Double scale       = solution.LanguageType.Scale;
                        Int32  timeLimit   = (Int32)(problem.TimeLimit * scale);
                        Int32  memoryLimit = (Int32)(problem.MemoryLimit * scale);

                        ret.Append("{");
                        ret.Append("\"sid\":\"").Append(solution.SolutionID.ToString()).Append("\",");
                        ret.Append("\"pid\":\"").Append(solution.ProblemID.ToString()).Append("\",");
                        ret.Append("\"username\":\"").Append(solution.UserName).Append("\",");
                        ret.Append("\"dataversion\":\"").Append(problemDataVersion).Append("\",");
                        ret.Append("\"timelimit\":\"").Append(timeLimit.ToString()).Append("\",");
                        ret.Append("\"memorylimit\":\"").Append(memoryLimit.ToString()).Append("\",");
                        ret.Append("\"language\":\"").Append(solution.LanguageType.Type).Append("[]\",");
                        ret.Append("\"sourcecode\":\"").Append(JsonEncoder.JsonEncode(solution.SourceCode)).Append("\"");
                        ret.Append("}");
                    }
                }

                ret.Append("]");

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