Пример #1
0
 public ProjectExerciseValidator(BaseValidator baseValidator, CsSandboxRunnerSettings settings, ExerciseSlide slide, CsProjectExerciseBlock exercise)
     : base(baseValidator)
 {
     this.settings = settings;
     this.slide    = slide;
     ex            = exercise;
 }
Пример #2
0
 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)));
 }
Пример #3
0
        public static string ValidateBlock(CsProjectExerciseBlock exBlock)
        {
            var valOut = new StringBuilder();
            var val    = BuildProjectExerciseValidator(exBlock, valOut);

            val.ValidateExercises();
            return(valOut.ToString());
        }
Пример #4
0
        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);
        }
Пример #5
0
        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());
        }
Пример #8
0
 public static IEnumerable <FileContent> ResolveCsprojLinks(CsProjectExerciseBlock block)
 {
     return(ResolveCsprojLinks(block.CsprojFile, block.BuildEnvironmentOptions.ToolsVersion));
 }
Пример #9
0
 public static bool NeedExcludeFromStudentZip(CsProjectExerciseBlock block, string filepath)
 {
     return(IsAnyWrongAnswerOrAnySolution(filepath) ||
            block.PathsToExcludeForStudent != null && block.PathsToExcludeForStudent.Any(p => p == filepath));
 }
Пример #10
0
        private static bool NeedExcludeFromStudentZip(CsProjectExerciseBlock block, FileInfo file)
        {
            var relativeFilePath = file.GetRelativePath(block.ExerciseFolder.FullName);

            return(NeedExcludeFromStudentZip(block, relativeFilePath));
        }
Пример #11
0
        public static ProjectExerciseValidator BuildProjectExerciseValidator(CsProjectExerciseBlock exBlock, StringBuilder valOut)
        {
            var slide = BuildSlide(exBlock);

            return(new ProjectExerciseValidator(BuildValidator(slide, valOut), new CsSandboxRunnerSettings(), slide, exBlock));
        }