public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { if (!Language.HasValue) { Language = LanguageHelpers.GuessByExtension(new FileInfo(UserCodeFilePath)); } UnitDirectory = context.UnitDirectory; CourseDirectory = context.CourseDirectory; ExpectedOutput = ExpectedOutput ?? ""; SolutionRegionContent = new Lazy <string>(() => GetRegionContent(UserCodeFile)); InitialRegionContent = new Lazy <string>(() => GetRegionContent(InitialUserCodeFile)); ExerciseInitialCode = NoStudentZip ? GetNoStudentZipInitialCode() : ExerciseInitialCode ?? "// Вставьте сюда финальное содержимое файла " + UserCodeFilePath; CheckForPlagiarism = false; yield return(this); var correctSolution = GetCorrectSolution(); if (correctSolution != null) { yield return(new MarkdownBlock("### Решение") { Hide = true }); yield return(new CodeBlock(GetCorrectSolution(), Language) { Hide = true }); } }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { yield return(new ImageGalleryBlock(context.UnitDirectory.GetFilenames(Directory)) { Hide = Hide }); }
private static SlideBlock[] DeserializeBlocks(string blocksXml) { var buildUpContext = new SlideBuildingContext("Test", new Unit(null, new DirectoryInfo(".")), CourseSettings.DefaultSettings, null); var blocks = DeserializeLesson(blocksXml).Blocks; return(blocks.SelectMany(b => b.BuildUp(buildUpContext, ImmutableHashSet <string> .Empty)).ToArray()); }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { yield return(new MarkdownBlock(context.UnitDirectory.GetContent(File)) { Hide = Hide }); }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { if (!Language.HasValue) { Language = LanguageHelpers.GuessByExtension(new FileInfo(UserCodeFilePath)); } Slide = context.Slide; CourseId = context.CourseId; UnitDirectory = context.UnitDirectory; CourseDirectory = context.CourseDirectory; ExpectedOutput = ExpectedOutput ?? ""; SolutionRegionContent = new Lazy <string>(() => GetRegionContent(CorrectSolutionFile)); InitialRegionContent = new Lazy <string>(() => GetRegionContent(InitialUserCodeFile)); var commentSymbols = Language.GetAttribute <CommentSymbolsAttribute>()?.CommentSymbols ?? "//"; ExerciseInitialCode = NoStudentZip ? GetNoStudentZipInitialCode() : ExerciseInitialCode ?? $"{commentSymbols} Вставьте сюда финальное содержимое файла {UserCodeFilePath}"; yield return(this); var correctSolution = GetCorrectSolution(); if (correctSolution != null) { yield return(new MarkdownBlock("### Решение") { Hide = true }); yield return(new CodeBlock(correctSolution, Language) { Hide = true }); } }
public override void Validate(SlideBuildingContext slideBuildingContext) { if (HideQuizButton && !(slideBuildingContext.Slide is QuizSlide)) { throw new CourseLoadingException("У блока <spoiler> указан атрибут hideQuizButton=\"true\", хотя слайд не является тестом. Этот атрибут можно использовать только внутри <slide.quiz>"); } }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { if (!Language.HasValue) { Language = context.CourseSettings.DefaultLanguage; } Slide = context.Slide; CourseId = context.CourseId; ExerciseInitialCode = ExerciseInitialCode ?? "// Вставьте сюда финальное содержимое файла " + UserCodeFilePath; ExpectedOutput = ExpectedOutput ?? ""; Validator.ValidatorName = string.Join(" ", Language.GetName(), Validator.ValidatorName ?? ""); SlideFolderPath = context.UnitDirectory; ReplaceStartupObjectForNUnitExercises(); yield return(this); if (CorrectSolutionFile.Exists) { yield return(new MarkdownBlock("### Решение") { Hide = true }); yield return(new CodeBlock(CorrectSolutionFile.ContentAsUtf8(), Language) { Hide = true }); } }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { CodeFile = CodeFile ?? context.Slide.DefaultIncludeCodeFile ?? context.Unit.Settings?.DefaultIncludeCodeFile; if (CodeFile == null) { throw new CourseLoadingException($"У блока <exercise.file> не указан атрибут file."); } if (ExerciseInitialCode == null) { throw new CourseLoadingException($"У блока <exercise.file> не указан код, который надо показывать пользователю перед началом работы. Укажите его в тэге <initialCode>"); } if (!Language.HasValue) { Language = LanguageHelpers.GuessByExtension(new FileInfo(CodeFile)); } RemovedLabels = RemovedLabels ?? new Label[0]; if (PreludeFile == null) { PreludeFile = context.CourseSettings.GetPrelude(Language); if (PreludeFile != null) { PreludeFile = Path.Combine("..", PreludeFile); } } var code = context.UnitDirectory.GetContent(CodeFile); var regionRemover = new RegionRemover(Language); var extractor = context.GetExtractor(CodeFile, Language, code); var prelude = ""; if (PreludeFile != null) { prelude = context.UnitDirectory.GetContent(PreludeFile); } var exerciseCode = regionRemover.Prepare(code); exerciseCode = regionRemover.Remove(exerciseCode, RemovedLabels, out var _); exerciseCode = regionRemover.RemoveSolution(exerciseCode, SolutionLabel, out var index); if (index < 0) { index = 0; } index += prelude.Length; ExerciseInitialCode = ExerciseInitialCode.RemoveCommonNesting(); ExerciseCode = prelude + exerciseCode; IndexToInsertSolution = index; EthalonSolution = extractor.GetRegion(SolutionLabel); Validator.ValidatorName = string.Join(" ", Language.GetName(), Validator.ValidatorName ?? ""); yield return(this); }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { if (Blocks == null) { Blocks = new SlideBlock[0]; } Blocks = Blocks.SelectMany(b => b.BuildUp(context, filesInProgress)).ToArray(); DefineBlockTypes(); return(base.BuildUp(context, filesInProgress)); }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { if (filesInProgress.Contains(File)) { throw new Exception("Cyclic dependency"); } var xmlStream = new StringReader(context.UnitDirectory.GetContent(File)); var serializer = new XmlSerializer(typeof(SlideBlock[])); var slideBlocks = (SlideBlock[])serializer.Deserialize(xmlStream); var newInProgress = filesInProgress.Add(File); return(slideBlocks.SelectMany(b => b.BuildUp(context, newInProgress))); }
public void Validate(SlideLoadingContext context, Slide flashcardSlide) { var slideBuildingContext = new SlideBuildingContext(context, flashcardSlide); foreach (var block in Question.Blocks) { block.Validate(slideBuildingContext); } foreach (var block in Answer.Blocks) { block.Validate(slideBuildingContext); } }
public override void Validate(SlideBuildingContext slideBuildingContext) { if (Items.DistinctBy(i => i.Id).Count() != Items.Length) { throw new FormatException("Duplicate choice id in quizBlock " + Id); } if (!Multiple && Items.Count(i => i.IsCorrect == ChoiceItemCorrectness.True) != 1) { throw new FormatException("Should be exaclty one correct item for non-multiple choice. BlockId=" + Id); } if (!Multiple && Items.Count(i => i.IsCorrect == ChoiceItemCorrectness.Maybe) != 0) { throw new FormatException("'Maybe' items are not allowed for for non-multiple choice. BlockId=" + Id); } }
public override void Validate(SlideBuildingContext slideBuildingContext) { if (string.IsNullOrEmpty(Sample)) { return; } if (Regexes == null) { return; } if (!Regexes.Any(re => re.Regex.IsMatch(Sample))) { throw new FormatException("Sample should match at least one regex. BlockId=" + Id); } }
public void OneTimeSetUp() { TestsHelper.RecreateDirectory(tempSlideFolderPath); FileSystem.CopyDirectory(TestsHelper.ProjSlideFolderPath, tempSlideFolderPath); string studentZipFilepath = Path.Combine(tempSlideFolderPath, "ProjDir.exercise.zip"); if (File.Exists(studentZipFilepath)) { File.Delete(studentZipFilepath); } var ctx = new SlideBuildingContext("Test", new Unit(null, exerciseBlock.SlideFolderPath), CourseSettings.DefaultSettings, exerciseBlock.SlideFolderPath, null); // ReSharper disable once ReturnValueOfPureMethodIsNotUsed exerciseBlock.BuildUp(ctx, ImmutableHashSet <string> .Empty).ToList(); }
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 void BuildUp(SlideLoadingContext context, Slide flashcardSlide) { if (Answer is null) { Answer = new FlashcardContent(); } if (Question is null) { Question = new FlashcardContent(); } if (Answer.Blocks is null) { Answer.Blocks = new SlideBlock[0]; } if (Question.Blocks is null) { Question.Blocks = new SlideBlock[0]; } if (TheorySlidesIds is null) { TheorySlidesIds = new Guid[0]; } var slideLoadingContext = new SlideBuildingContext(context, flashcardSlide); Answer.Blocks = Answer.Blocks .SelectMany(x => x.BuildUp(slideLoadingContext, ImmutableHashSet <string> .Empty)) .ToArray(); Question.Blocks = Question.Blocks .SelectMany(x => x.BuildUp(slideLoadingContext, ImmutableHashSet <string> .Empty)) .ToArray(); }
public override void Validate(SlideBuildingContext slideBuildingContext) { }
public override IEnumerable <SlideBlock> BuildUp(SlideBuildingContext context, IImmutableSet <string> filesInProgress) { BaseUrl ??= context.Slide.Info.DirectoryRelativePath; yield return(this); }