Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (ExerciseInitialCode != null ? ExerciseInitialCode.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ExpectedOutput != null ? ExpectedOutput.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (HintsMd != null ? HintsMd.GetHashCode() : 0);
         return(hashCode);
     }
 }
Ejemplo n.º 3
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = ExerciseInitialCode?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (ExpectedOutput?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (HintsMd?.GetHashCode() ?? 0);
         return(hashCode);
     }
 }
Ejemplo n.º 4
0
        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);
        }