/// <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))); } }
/// <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); } } }
/// <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); }
/// <summary> /// 根据用户名和提交结果获取通过提交列表 /// </summary> /// <param name="userName">用户名</param> /// <param name="contestID">竞赛ID</param> /// <returns>题目ID列表</returns> public static List <Int32> GetSolvedProblemIDListByUser(String userName, Int32 contestID) { if (String.IsNullOrEmpty(userName)) { return(new List <Int32>()); } if (!RegexVerify.IsUserName(userName)) { throw new InvalidRequstException(RequestType.User); } List <Int32> lstSolved = (contestID == -1 ? SolutionCache.GetProblemIDListCache(userName, false) : null);//获取缓存 if (lstSolved == null) { lstSolved = SolutionRepository.Instance.GetEntityIDsByUserAndResultType(userName, contestID, ResultType.Accepted); if (contestID == -1) { SolutionCache.SetProblemIDListCache(userName, false, lstSolved); //获取缓存 } } return(lstSolved != null ? lstSolved : new List <Int32>()); }
/// <summary> /// 根据用户名获取未通过提交列表 /// </summary> /// <param name="userName">用户名</param> /// <param name="solvedList">该用户AC题目ID的列表</param> /// <param name="contestID">竞赛ID</param> /// <returns>题目ID列表</returns> public static List <Int32> GetUnSolvedProblemIDListByUser(String userName, List <Int32> lstSolved, Int32 contestID) { if (String.IsNullOrEmpty(userName)) { return(new List <Int32>()); } if (!RegexVerify.IsUserName(userName)) { throw new InvalidRequstException(RequestType.User); } List <Int32> lstUnsolved = (contestID == -1 ? SolutionCache.GetProblemIDListCache(userName, true) : null);//获取缓存 if (lstUnsolved == null) { lstUnsolved = SolutionRepository.Instance.GetEntityIDsByUserAndLessResultType(userName, contestID, ResultType.Accepted); if (lstUnsolved != null && lstUnsolved.Count > 0 && lstSolved != null && lstSolved.Count > 0) { foreach (Int32 pid in lstSolved) { lstUnsolved.Remove(pid); } } if (contestID == -1) { SolutionCache.SetProblemIDListCache(userName, true, lstUnsolved);//设置缓存 } } return(lstUnsolved != null ? lstUnsolved : new List <Int32>()); }
/// <summary> /// 获取指定用户名的所有AC代码打包文件 /// </summary> /// <returns>所有AC代码打包文件</returns> public static Byte[] GetAcceptedSourceCodeList() { if (!UserManager.IsUserLogined) { throw new UserUnLoginException(); } if (!ConfigurationManager.AllowDownloadSource) { throw new FunctionDisabledException("Source code download is DISABLED!"); } String userName = UserManager.CurrentUserName; Byte[] file = SolutionCache.GetAcceptedCodesCache(userName); if (file == null) { List <SolutionEntity> solutions = SolutionRepository.Instance.GetEntitiesForAcceptedSourceCode(userName); file = SolutionCodeExport.ExportSolutionAcceptedCodeToZip(userName, ConfigurationManager.OnlineJudgeName, solutions); SolutionCache.SetAcceptedCodesCache(userName, file); } return(file); }
/// <summary> /// Generates solution files for specified solution. /// </summary> /// <param name="solution">Parsed solution object.</param> /// <returns>Path to main solution file.</returns> public virtual string GenerateSolutionFiles(SolutionCache solution) { var solutionDirectoryPath = Path.Combine(solution.CachedLocation, "Build"); Directory.CreateDirectory(solutionDirectoryPath); return solutionDirectoryPath; }
public async Task <SolutionServiceResult> FinalizeSolutionSet(string id, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id)); } cancellationToken.ThrowIfCancellationRequested(); if (await SolutionCache.FetchSizeAsync(cancellationToken) > Configuration.MaxCache) { return(SolutionServiceResult.Full); } var solution = await SolutionSet.FetchSolutionMetdataAsync(id, cancellationToken); var result = SolutionValidator.Validate(solution, cancellationToken); if (result == ValidationResult.Incomplete) { return(SolutionServiceResult.Incomplete); } if (result == ValidationResult.Invalid) { await SolutionSet.RemoveSolutionMetadataAsync(id, cancellationToken); return(SolutionServiceResult.StartOver); } await SolutionCache.PutAsync(solution, cancellationToken); await SolutionSet.RemoveSolutionMetadataAsync(id, cancellationToken); return(SolutionServiceResult.Success); }
public async void Start() { while (Program.IsRunning) { var solution = await SolutionCache.Fetch(); Compilers[solution.SolutionType].Compile(solution, Directory); } }
/// <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); }
/// <summary> /// 获取竞赛题目统计信息 /// </summary> /// <param name="cid">竞赛ID</param> /// <returns>竞赛题目统计信息实体列表</returns> public static IDictionary <Int32, ContestProblemStatistic> GetContestStatistic(Int32 cid) { if (cid <= 0) { throw new InvalidRequstException(RequestType.Contest); } IDictionary <Int32, ContestProblemStatistic> statistics = SolutionCache.GetContestStatisticCache(cid); if (statistics == null) { statistics = SolutionRepository.Instance.GetContestStatistic(cid); SolutionCache.SetContestStatisticCache(cid, statistics); } return(statistics); }