public string GetComplexDescription(CourseProblem problem, string courseDir, string course, string year) { var candidates = new List <String> { Path.Combine( new DirectoryInfo(courseDir).Name, year, "problems", problem.Id, "build", "index.html" ), Path.Combine( new DirectoryInfo(courseDir).Name, year, "problems", problem.Id, "index.html" ), }; return(candidates.FirstOrDefault(i => { var fullPath = Path.Combine(_appOptions.CourseDir, i); var exists = File.Exists(fullPath); _logger.LogDebug($"desc: {fullPath}: {exists}"); return exists; } )); }
public string GetProblemReadMe(CourseProblem problem, string courseDir, string course, string year) { var readmePath = Path.Combine( _appOptions.CourseDir, courseDir, year, "problems", problem.Id, "README.md" ); if (!File.Exists(readmePath)) { _logger.LogWarning("Could not find README.md {path}", readmePath); return(null); } var pipeline = new MarkdownPipelineBuilder() // .UseAdvancedExtensions() // .UseMathematics() .Build(); var writer = new StringWriter(); var renderer = new HtmlRenderer(writer) { LinkRewriter = arg => { if (arg.StartsWith("http")) { return(arg); } return($"/static-files/serve/{course}/{year}/{problem.Id}/{arg}"); } }; var content = File.Exists(readmePath) ? File.ReadAllText(readmePath) : "*no description provided*"; content = FixMathEQ(content); var document = MarkdownParser.Parse(content, pipeline); renderer.Render(document); writer.Flush(); return(writer.ToString()); }
private IEnumerable <SimpleFile> BrowseFiles(CcData item, CourseProblem problem) { var context = new CourseContext(_courseService, _languageService, item); var referenceRootDir = new DirectoryInfo(context.ProblemDir.Root); var referenceOutputDir = new DirectoryInfo(context.ProblemDir.OutputDir); var allowedDirs = new List <string> { "output", "input", "error", ".verification" }; var resultDir = item.ResultDir(problem.CourseYearConfig.Course.CourseDir); var studentDir = new DirectoryInfo(context.StudentDir.Root); var files = new List <SimpleFile>(); if (item.Action == "solve") { files.AddRange(problem.Export.Select(i => ToSimpleFile(new FileInfo($"{resultDir}/{i}")))); files.Add(new SimpleFile { RawPath = studentDir.FullName, Filename = "generated", IsDir = true, Files = studentDir.Exists ? studentDir.GetDirectories() .Where(i => allowedDirs.Contains(i.Name)) .Select(i => ToSimpleFile(i)).ToList() : new List <SimpleFile>() }); files.Add(ToSimpleFile(referenceOutputDir, "reference")); files.ForEach(i => PopulateRelPath(i)); return(FilterEmptyFiles(files)); } else { files.Add(ToSimpleFile(referenceRootDir, "reference")); files.ForEach(i => PopulateRelPath(i)); return(FilterEmptyFiles(files)); } }
public static CcData EmptyResult(Course course, CourseYearConfig courseYear, CourseProblem problem, User user) { return(new CcData { Id = ObjectId.GenerateNewId(), User = user.id, Problem = problem.Id, CourseName = course.Name, CourseYear = courseYear.Year, Action = "solve", Attempt = 0, Points = 0, GradeComment = "No solution recieved", Result = new CcDataResult { Score = 0, Scores = new int[] { 0, 0, 0 }, Status = (int)ProcessStatusCodes.NoSolution, Duration = 0.0, Message = "No result", }, SubmissionStatus = SubmissionStatus.None, }); }
private async Task <PrepareItemResult> TerminatePreparation(Exception e, IClientProxy channel, CourseProblem problem, CourseYearConfig course) { Item.Results.ForEach(i => i.Status = ProcessStatus.Skipped.Value); Item.Result.Status = ProcessStatus.Skipped.Value; Item.Result.Message = e.Message; await channel.ItemChanged(Item); return(new PrepareItemResult { Channel = channel, Problem = problem, Course = course, Error = $"Failed to prepare environment, contact teacher: ${e.Message}", }); }