private CcData CreateItemTemplate(string courseName, string courseYear, string problemId, string langId, IList <SimpleFileDto> files) { var id = ObjectId.GenerateNewId(); var problem = Problem(courseName, courseYear, problemId); var language = _languageService[langId]; var solutions = new List <CcDataSolution>(); if (problem.Type == ProblemType.Unittest) { var unittestSpec = problem.Unittest.SingleOrDefault(i => i.Lang == langId) ?? throw new NotSupportedException($"Language {langId} has no tests defined, contact your teacher"); var entryPointSrc = problem.ProblemDir().RootFile(unittestSpec.Entrypoint).ReadAllText(); solutions.Add(CcDataSolution.Single(entryPointSrc, unittestSpec.Entrypoint, 2, false, unittestSpec.Hidden)); solutions.AddRange(files.Select(i => CcDataSolution.Single(i.Content, i.Path))); } else { // add all files solutions.AddRange(files.Select(i => CcDataSolution.Single(i.Content, i.Path))); } // add other required files solutions.AddRange(language.Files.Select(i => CcDataSolution.Single(i.Values.First(), i.Keys.First(), 9, false, true))); var ccData = new CcData { Id = id, CourseName = courseName, CourseYear = courseYear, Action = "solve", Docker = true, Problem = problemId, Language = langId, Solutions = solutions, Result = new CcDataResult { Status = ProcessStatus.InQueue.Value, Duration = 0, Message = null, Score = 0, Scores = new[] { 0, 0, 0 }, }, SubmissionStatus = DateTime.Now <= problem.Avail ? SubmissionStatus.Intime : DateTime.Now <= problem.Deadline ? SubmissionStatus.Late : SubmissionStatus.None, }; return(ccData); }
public CcData CreateItemGenerateInputOutput(string userId, string courseName, string courseYear, string problemId, string action) { if (User.Role != AppUserRoles.Root) { throw new PermissionDeniedException(); } var id = ObjectId.GenerateNewId(); var problem = Problem(courseName, courseYear, problemId); var language = _languageService[problem.Reference.Lang]; var courseDir = _courseService[courseName].CourseDir; var problemDir = Path.Combine(courseDir, courseYear, "problems", problemId); var solutions = new List <CcDataSolution> { CcDataSolution.Single( Path.Combine(problemDir, problem.Reference.Name).ReadAllText(), problem.Reference.Name ), CcDataSolution.Single(string.Empty, ".debug", int.MaxValue, false) }; // add other required files solutions.AddRange(language.Files.Select(i => CcDataSolution.Single(i.Values.First(), i.Keys.First(), 9, false, true))); var ccData = new CcData { Id = id, User = userId, CourseName = courseName, CourseYear = courseYear, Problem = problemId, Action = action, Language = language.Id, Solutions = solutions, Result = new CcDataResult { Status = ProcessStatus.InQueue.Value, Duration = 0, Message = null, Score = 0, Scores = new[] { 0, 0, 0 }, }, SubmissionStatus = DateTime.Now <= problem.Avail ? SubmissionStatus.Intime : DateTime.Now <= problem.Deadline ? SubmissionStatus.Late : SubmissionStatus.None, }; return(ccData); }
public CcData ConvertToExtended(CcData item) { var course = _courseService[item.CourseName]; var courseYearConfig = course[item.CourseYear]; var problem = courseYearConfig[item.Problem]; item.IsActive = problem.IsActive; item.Solutions = item.Solutions .Where(i => !i.Hidden || _userService.CurrentUser?.Role == "root") .OrderBy(i => i.IsMain ? 0 : int.MaxValue) .ThenBy(i => i.Index) .ToList(); item.Solutions.Insert(0, CcDataSolution.Seperator("Solution Files")); if (problem.Export.Any()) { var context = new CourseContext(_courseService, _languageService, item); item.Solutions.Add(CcDataSolution.Seperator("Result files")); foreach (var f in problem.Export) { var filepath = context.StudentDir.RootFile(f); if (System.IO.File.Exists(filepath)) { item.Solutions.Add(new CcDataSolution { Filename = f, Content = Convert.ToBase64String(System.IO.File.ReadAllBytes(filepath)) }); } } } item.Solutions.Add(CcDataSolution.Seperator("Browser Directories")); item.Solutions.AddRange( new[] { problem.Type == ProblemType.Unittest ? null : CcDataSolution.Dynamic("Input", item.ObjectId), CcDataSolution.Dynamic("Output", item.ObjectId), CcDataSolution.Dynamic("Error", item.ObjectId), problem.Type == ProblemType.Unittest ? null : CcDataSolution.Dynamic("Reference", item.ObjectId) } ); item.Solutions = item.Solutions .Where(i => i != null) .ToList(); return(item); }