public static void BuildUp(Quiz quiz, DirectoryInfo slideDir, CourseSettings settings) { var context = new BuildUpContext(slideDir, settings, null, quiz.Title); var blocks = quiz.Blocks.SelectMany(b => b.BuildUp(context, ImmutableHashSet <string> .Empty)); quiz.Blocks = blocks.ToArray(); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { yield return(new ImageGaleryBlock(context.Dir.GetFilenames(Directory)) { Hide = Hide }); }
public override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { FillProperties(context); RemovedLabels = RemovedLabels ?? new Label[0]; if (PreludeFile == null) { PreludeFile = context.CourseSettings.GetPrelude(LangId); if (PreludeFile != null) PreludeFile = Path.Combine("..", PreludeFile); } var code = context.FileSystem.GetContent(File); var regionRemover = new RegionRemover(LangId); var extractor = context.GetExtractor(File, LangId, code); var prelude = ""; if (PreludeFile != null) prelude = context.FileSystem.GetContent(PreludeFile); var exerciseCode = regionRemover.Prepare(code); IEnumerable<Label> notRemoved; exerciseCode = regionRemover.Remove(exerciseCode, RemovedLabels, out notRemoved); int index; exerciseCode = regionRemover.RemoveSolution(exerciseCode, SolutionLabel, out index); index += prelude.Length; ExerciseInitialCode = ExerciseInitialCode.RemoveCommonNesting(); ExerciseCode = prelude + exerciseCode; IndexToInsertSolution = index; EthalonSolution = extractor.GetRegion(SolutionLabel); ValidatorName = string.Join(" ", LangId, ValidatorName); yield return this; }
private static SlideBlock[] DeserializeBlocks(string blocksXml) { var buildUpContext = new BuildUpContext(new Unit(null, new DirectoryInfo(".")), CourseSettings.DefaultSettings, null, "Test", "Заголовок слайда"); var blocks = DeserializeLesson(blocksXml).Blocks; return(blocks.SelectMany(b => b.BuildUp(buildUpContext, ImmutableHashSet <string> .Empty)).ToArray()); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { yield return(new MdBlock(context.Dir.GetContent(File)) { Hide = Hide }); }
public static void BuildUp(Quiz quiz, Unit unit, string courseId, CourseSettings settings) { var context = new BuildUpContext(unit, settings, null, courseId, quiz.Title); var blocks = quiz.Blocks.SelectMany(b => b.BuildUp(context, ImmutableHashSet <string> .Empty)); quiz.Blocks = blocks.ToArray(); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { if (LangVer == null) { LangVer = context.CourseSettings.GetLanguageVersion(LangId); } yield return(this); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { string FormatFragment(VideoAnnotationFragment f) => $"* {f.StartTimeAsString} — {f.Text}"; var fragmentsList = string.Join("\n", Fragments.Select(FormatFragment)); yield return(new MdBlock($"## Содержание видео\n\n{Text}\n\n{fragmentsList}")); }
public override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { if (filesInProgress.Contains(File)) throw new Exception("Cyclic dependency"); var xmlStream = new StringReader(context.FileSystem.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 override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { FillProperties(context); ExerciseInitialCode = ExerciseInitialCode ?? "// Вставьте сюда финальное содержимое файла " + UserCodeFileName; ExpectedOutput = ExpectedOutput ?? ""; ValidatorName = string.Join(" ", LangId, ValidatorName); SlideFolderPath = context.Dir; var exercisePath = context.Dir.GetSubdir(ExerciseDir).FullName; if (context.ZippedProjectExercises.Add(exercisePath)) CreateZipForStudent(); yield return this; }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { if (filesInProgress.Contains(File)) { throw new Exception("Cyclic dependency"); } var xmlStream = new StringReader(context.Dir.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))); }
private static SlideBlock[] DeserializeBlocks(string blocksXml) { var input = $@" <Lesson xmlns='https://ulearn.azurewebsites.net/lesson'> {blocksXml} </Lesson>"; File.WriteAllText("temp.xml", input); var fileInfo = new FileInfo("temp.xml"); var buildUpContext = new BuildUpContext(new DirectoryInfo("."), CourseSettings.DefaultSettings, null, "Заголовок слайда"); return(fileInfo.DeserializeXml <Lesson>().Blocks .SelectMany(b => b.BuildUp(buildUpContext, ImmutableHashSet <string> .Empty)) .ToArray()); }
public override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { FillProperties(context); DisplayLabels = DisplayLabels ?? new Label[0]; if (DisplayLabels.Length == 0) { var content = context.Dir.GetContent(File); yield return new CodeBlock(content, LangId, LangVer); yield break; } var extractor = context.GetExtractor(File, LangId); yield return new CodeBlock(string.Join("\r\n\r\n", extractor.GetRegions(DisplayLabels)), LangId, LangVer) { Hide = Hide }; }
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 BuildUpContext(new Unit(null, exBlock.SlideFolderPath), CourseSettings.DefaultSettings, null, "Test", string.Empty); exBlock.BuildUp(ctx, ImmutableHashSet <string> .Empty).ToList(); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { FillProperties(context); DisplayLabels = DisplayLabels ?? new Label[0]; if (DisplayLabels.Length == 0) { var content = context.FileSystem.GetContent(File); yield return(new CodeBlock(content, LangId, LangVer)); yield break; } var extractor = context.GetExtractor(File, LangId); yield return(new CodeBlock(String.Join("\r\n\r\n", extractor.GetRegions(DisplayLabels)), LangId, LangVer)); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { FillProperties(context); ExerciseInitialCode = ExerciseInitialCode ?? "// Вставьте сюда финальное содержимое файла " + UserCodeFileName; ExpectedOutput = ExpectedOutput ?? ""; ValidatorName = string.Join(" ", LangId, ValidatorName); SlideFolderPath = context.Dir; var exercisePath = context.Dir.GetSubdir(ExerciseDir).FullName; if (context.ZippedProjectExercises.Add(exercisePath)) { CreateZipForStudent(); } CheckScoringGroup(context.SlideTitle, context.CourseSettings.Scoring); yield return(this); }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { FillProperties(context); RemovedLabels = RemovedLabels ?? new Label[0]; if (PreludeFile == null) { PreludeFile = context.CourseSettings.GetPrelude(LangId); if (PreludeFile != null) { PreludeFile = Path.Combine("..", PreludeFile); } } var code = context.Dir.GetContent(CodeFile); var regionRemover = new RegionRemover(LangId); var extractor = context.GetExtractor(CodeFile, LangId, code); var prelude = ""; if (PreludeFile != null) { prelude = context.Dir.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(" ", LangId, Validator.ValidatorName ?? ""); CheckScoringGroup(context.SlideTitle, context.CourseSettings.Scoring); yield return(this); }
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 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 override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { yield return new ImageGaleryBlock(context.FileSystem.GetFilenames(Directory)); }
protected void FillProperties(BuildUpContext context) { File = File ?? context.Lesson?.DefaultIncludeCodeFile; LangId = LangId ?? Path.GetExtension(File)?.Trim('.') ?? context.CourseSettings.DefaultLanguage; LangVer = LangVer ?? context.CourseSettings.GetLanguageVersion(LangId); }
public override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { return InnerBlocks?.SelectMany(b => b.BuildUp(context, filesInProgress)) ?? new[] { this }; }
public override IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { return(InnerBlocks?.SelectMany(b => b.BuildUp(context, filesInProgress)) ?? new[] { this }); }
protected void FillProperties(BuildUpContext context) { File = File ?? context.Lesson?.DefaultIncludeCodeFile; LangId = LangId ?? Path.GetExtension(File)?.Trim('.') ?? context.CourseSettings.DefaultLanguage; LangVer = LangVer ?? context.CourseSettings.GetLanguageVersion(LangId); }
public override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { yield return new MdBlock(context.FileSystem.GetContent(File)); }
public virtual IEnumerable <SlideBlock> BuildUp(BuildUpContext context, IImmutableSet <string> filesInProgress) { yield return(this); }
public virtual IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { yield return this; }
public override IEnumerable<SlideBlock> BuildUp(BuildUpContext context, IImmutableSet<string> filesInProgress) { if (LangVer == null) LangVer = context.CourseSettings.GetLanguageVersion(LangId); yield return this; }