public ProjectExerciseValidator(BaseValidator baseValidator, SandboxRunnerSettings settings, ExerciseSlide slide, ProjectExerciseBlock exercise) : base(baseValidator) { this.settings = settings; this.slide = slide; ex = exercise; }
private static byte[] GetFileContentInStudentZip(ProjectExerciseBlock block, FileInfo file) { if (!file.Name.Equals(block.CsprojFileName, StringComparison.InvariantCultureIgnoreCase)) { return(null); } return(ProjModifier.ModifyCsproj(file, proj => ProjModifier.PrepareForStudentZip(proj, block))); }
public static string ValidateBlock(ProjectExerciseBlock exBlock) { var valOut = new StringBuilder(); var val = BuildProjectExerciseValidator(exBlock, valOut); val.ValidateExercises(); return(valOut.ToString()); }
public static void PrepareForCheckingUserCode(Project proj, ProjectExerciseBlock ex, List <string> excludedPaths) { var solutionRelativePath = ex.ExerciseFolder.GetRelativePathsOfFiles() .SingleOrDefault(n => n.Equals(ex.CorrectSolutionPath, StringComparison.InvariantCultureIgnoreCase)); if (solutionRelativePath != null) { excludedPaths.Add(solutionRelativePath); } SetFilepathItemTypeToCompile(proj, ex.UserCodeFilePath); PrepareForChecking(proj, ex.StartupObject, excludedPaths); }
private void StudentsZipIsBuildingOk(Slide slide, ProjectExerciseBlock ex) { var tempDir = new DirectoryInfo("./temp"); try { Utils.UnpackZip(ex.StudentsZip.Content(), "./temp"); var res = MsBuildRunner.BuildProject(settings.MsBuildSettings, tempDir.GetFile(ex.CsprojFileName).FullName, tempDir); if (!res.Success) { ReportSlideError(slide, ex.CsprojFileName + " not building! " + res); } } finally { tempDir.Delete(true); } }
public void SetUp() { exBlock = new ProjectExerciseBlock { StartupObject = "test.Program", UserCodeFilePath = TestsHelper.UserCodeFileName, SlideFolderPath = tempSlideFolder, CsProjFilePath = TestsHelper.CsProjFilePath, }; FileSystem.CopyDirectory(TestsHelper.ProjSlideFolderPath, tempSlideFolderPath, true); string studentZipFilepath = Path.Combine(tempSlideFolderPath, "ProjDir.exercise.zip"); if (File.Exists(studentZipFilepath)) { File.Delete(studentZipFilepath); } var ctx = new BuildUpContext(new Unit(null, exBlock.SlideFolderPath), CourseSettings.DefaultSettings, null, "Test", string.Empty); exBlock.BuildUp(ctx, ImmutableHashSet <string> .Empty).ToList(); }
public static void PrepareForStudentZip(Project proj, ProjectExerciseBlock ex) { var toExclude = FindItemNames(proj, file => ExerciseStudentZipBuilder.NeedExcludeFromStudentZip(ex, file)).ToList(); var solutionsOfOtherTasks = toExclude.Where(n => ExerciseStudentZipBuilder.IsAnySolution(n) && ex.CorrectSolutionPath != n).ToList(); /* Remove StartupObject from csproj: it's not needed in student zip */ var startupObject = proj.GetProperty("StartupObject"); if (startupObject != null) { proj.RemoveProperty(startupObject); } RemoveCheckingFromCsproj(proj); var userCodeFilepathsOfOtherTasks = solutionsOfOtherTasks.Select(ProjectExerciseBlock.SolutionFilepathToUserCodeFilepath); SetFilepathItemTypeToCompile(proj, userCodeFilepathsOfOtherTasks.Concat(new[] { ex.UserCodeFilePath })); ReplaceLinksWithItems(proj); ExcludePaths(proj, toExclude); }
public void OneTimeSetUp() { TestsHelper.RecreateDirectory(tempSlideFolderPath); FileSystem.CopyDirectory(TestsHelper.ProjSlideFolderPath, tempSlideFolderPath); TestsHelper.RecreateDirectory(checkerExerciseFolderPath); TestsHelper.RecreateDirectory(studentExerciseFolderPath); Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); ex = new ProjectExerciseBlock { StartupObject = "test.Program", UserCodeFilePath = TestsHelper.UserCodeFileName, SlideFolderPath = tempSlideFolder, CsProjFilePath = TestsHelper.CsProjFilePath, PathsToExcludeForStudent = new[] { "inner-dir-1\\inner-dir-2\\ExcludeMeForStudent.cs" } }; var unit = new Unit(null, ex.SlideFolderPath); var ctx = new BuildUpContext(unit, CourseSettings.DefaultSettings, null, "Test", string.Empty); exBlocks = ex.BuildUp(ctx, ImmutableHashSet <string> .Empty).ToList(); var builder = new ExerciseStudentZipBuilder(); builder.BuildStudentZip(new ExerciseSlide(exBlocks, new SlideInfo(unit, null, 1), "", Guid.NewGuid(), meta: null), studentExerciseZipFilePath); Utils.UnpackZip(studentExerciseZipFilePath.Content(), studentExerciseFolderPath); var zipBytes = ex.GetZipBytesForChecker("i_am_user_code"); Utils.UnpackZip(zipBytes, checkerExerciseFolderPath); studentZipCsproj = new Project(studentCsProjFilePath, null, null, new ProjectCollection()); checkerZipCsproj = new Project(checkerCsprojFilePath, null, null, new ProjectCollection()); }
public static void PrepareForChecking(Project proj, ProjectExerciseBlock exerciseBlock, IReadOnlyList <string> excludedPaths) { PrepareForChecking(proj, exerciseBlock.StartupObject, excludedPaths); }
public static IEnumerable <FileContent> ResolveCsprojLinks(ProjectExerciseBlock block) { return(ResolveCsprojLinks(block.CsprojFile, block.BuildEnvironmentOptions.ToolsVersion)); }
public static bool NeedExcludeFromStudentZip(ProjectExerciseBlock block, string filepath) { return(IsAnyWrongAnswerOrAnySolution(filepath) || block.PathsToExcludeForStudent != null && block.PathsToExcludeForStudent.Any(p => p == filepath)); }
private static bool NeedExcludeFromStudentZip(ProjectExerciseBlock block, FileInfo file) { var relativeFilePath = file.GetRelativePath(block.ExerciseFolder.FullName); return(NeedExcludeFromStudentZip(block, relativeFilePath)); }
public static ProjectExerciseValidator BuildProjectExerciseValidator(ProjectExerciseBlock exBlock, StringBuilder valOut) { var slide = BuildSlide(exBlock); return(new ProjectExerciseValidator(BuildValidator(slide, valOut), new SandboxRunnerSettings(), slide, exBlock)); }