public ProjectExerciseValidator(BaseValidator baseValidator, CsSandboxRunnerSettings settings, ExerciseSlide slide, CsProjectExerciseBlock exercise) : base(baseValidator) { this.settings = settings; this.slide = slide; ex = exercise; }
private static MemoryStream GetFileContentInStudentZip(CsProjectExerciseBlock 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(CsProjectExerciseBlock exBlock) { var valOut = new StringBuilder(); var val = BuildProjectExerciseValidator(exBlock, valOut); val.ValidateExercises(); return(valOut.ToString()); }
public static void PrepareForCheckingUserCode(Project proj, CsProjectExerciseBlock 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); }
public static void PrepareForStudentZip(Project proj, CsProjectExerciseBlock 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(CsProjectExerciseBlock.SolutionFilepathToUserCodeFilepath); SetFilepathItemTypeToCompile(proj, userCodeFilepathsOfOtherTasks.Concat(new[] { ex.UserCodeFilePath })); ReplaceLinksWithItems(proj); ExcludePaths(proj, toExclude); }
public void SetUp() { exerciseBlock = new CsProjectExerciseBlock { 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 context = new SlideBuildingContext("Test", new Unit(null, exerciseBlock.SlideFolderPath), CourseSettings.DefaultSettings, null); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed exerciseBlock.BuildUp(context, ImmutableHashSet <string> .Empty).ToList(); }
public void OneTimeSetUp() { TestsHelper.RecreateDirectory(tempSlideFolderPath); FileSystem.CopyDirectory(TestsHelper.ProjSlideFolderPath, tempSlideFolderPath); TestsHelper.RecreateDirectory(checkerExerciseFolderPath); TestsHelper.RecreateDirectory(studentExerciseFolderPath); Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); ex = new CsProjectExerciseBlock { 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 SlideBuildingContext("Test", unit, CourseSettings.DefaultSettings, unit.Directory, null); exBlocks = ex.BuildUp(ctx, ImmutableHashSet <string> .Empty).ToList(); var builder = new ExerciseStudentZipBuilder(); builder.BuildStudentZip(new ExerciseSlide(exBlocks.ToArray()), studentExerciseZipFilePath); Utils.UnpackZip(studentExerciseZipFilePath.ReadAllContent(), 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 IEnumerable <FileContent> ResolveCsprojLinks(CsProjectExerciseBlock block) { return(ResolveCsprojLinks(block.CsprojFile, block.BuildEnvironmentOptions.ToolsVersion)); }
public static bool NeedExcludeFromStudentZip(CsProjectExerciseBlock block, string filepath) { return(IsAnyWrongAnswerOrAnySolution(filepath) || block.PathsToExcludeForStudent != null && block.PathsToExcludeForStudent.Any(p => p == filepath)); }
private static bool NeedExcludeFromStudentZip(CsProjectExerciseBlock block, FileInfo file) { var relativeFilePath = file.GetRelativePath(block.ExerciseFolder.FullName); return(NeedExcludeFromStudentZip(block, relativeFilePath)); }
public static ProjectExerciseValidator BuildProjectExerciseValidator(CsProjectExerciseBlock exBlock, StringBuilder valOut) { var slide = BuildSlide(exBlock); return(new ProjectExerciseValidator(BuildValidator(slide, valOut), new CsSandboxRunnerSettings(), slide, exBlock)); }