Пример #1
0
		public override void Validate(SlideLoadingContext context)
		{
			var scoringGroupsIds = context.CourseSettings.Scoring.Groups.Keys;
			var scoringGroup = Scoring.ScoringGroup;
			if (!string.IsNullOrEmpty(scoringGroup) && !scoringGroupsIds.Contains(scoringGroup))
				throw new CourseLoadingException(
					$"Неизвестная группа оценки у задания «{Title}»: {Scoring.ScoringGroup}\n" +
					"Возможные значения: " + string.Join(", ", scoringGroupsIds));

			var exerciseBlocksCount = Blocks.Count(b => b is AbstractExerciseBlock);
			if (exerciseBlocksCount == 0)
			{
				throw new CourseLoadingException(
					$"Не найдено блоков с упражнениями (<exercise.file>, <exercise.csproj> или <exercise.universal>) в слайде «{Title}», " +
					"для которого использован внешний тег <slide.exercise>. Если вы хотите создать обычный слайд без упражнения, используйте тег <slide>");
			}

			if (exerciseBlocksCount > 1)
			{
				throw new CourseLoadingException(
					"Блок с упражнением (<exercise.file>, <exercise.csproj> или <exercise.universal>) может быть только один на слайде. " +
					$"Но на слайде «{Title}» найдено {exerciseBlocksCount} таких блока.");
			}

			base.Validate(context);
		}
Пример #2
0
        public override void Validate(SlideLoadingContext context)
        {
            var scoringGroupsIds = context.CourseSettings.Scoring.Groups.Keys;

            if (!string.IsNullOrEmpty(ScoringGroup) && !scoringGroupsIds.Contains(ScoringGroup))
            {
                throw new CourseLoadingException(
                          $"Неизвестная группа оценки у теста «{Title}»: {ScoringGroup}\n" +
                          "Возможные значения: " + string.Join(", ", scoringGroupsIds));
            }

            var questionBlocks   = Blocks.OfType <AbstractQuestionBlock>().ToList();
            var questionIds      = questionBlocks.Select(b => b.Id).ToImmutableHashSet();
            var questionIdsCount = questionIds.ToDictionary(id => id, id => questionBlocks.Count(b => b.Id == id));

            if (questionIdsCount.Values.Any(count => count > 1))
            {
                var repeatedQuestionId = questionIdsCount.First(kvp => kvp.Value > 1).Key;
                throw new CourseLoadingException(
                          $"Идентификатор «{repeatedQuestionId}» в тесте «{Title}» принадлежит как минимум двум различным вопросам. " +
                          "Идентификаторы вопросов (параметры id) должны быть уникальны.");
            }

            if (!questionIds.All(id => questionIdRegex.IsMatch(id)))
            {
                var badQuestionId = questionIds.First(id => !questionIdRegex.IsMatch(id));
                throw new CourseLoadingException(
                          $"Идентификатор «{badQuestionId}» в тесте «{Title}» не удовлетворяет формату. " +
                          "Идентификаторы вопросов (параметры id) должны состоять из латинских букв, цифр и символа подчёркивания. Идентификатор не может быть пустым.");
            }

            base.Validate(context);
        }
Пример #3
0
		public override void BuildUp(SlideLoadingContext context)
		{
			if (string.IsNullOrEmpty(ScoringGroup))
				Scoring.ScoringGroup = context.CourseSettings.Scoring.DefaultScoringGroupForExercise;

			base.BuildUp(context);
		}
Пример #4
0
        private Slide LoadSlideFromXmlFile(string filename)
        {
            var slideFile           = new DirectoryInfo(testDataDirectory).GetFile(filename);
            var slideLoadingContext = new SlideLoadingContext("CourseId", unit, courseSettings, slideFile.Directory, slideFile, 1);

            return(loader.Load(slideLoadingContext));
        }
Пример #5
0
        public override void Validate(SlideLoadingContext context)
        {
            if (Hide)
            {
                throw new CourseLoadingException(
                          "Слайд с флэшкартами не может быть скрытым\n" +
                          $"{Title}");
            }

            foreach (var flashcard in FlashcardsList)
            {
                flashcard.Validate(context, this);
            }

            var emptyIdFlashcards = FlashcardsList.Where(x => string.IsNullOrEmpty(x.Id)).ToList();

            if (emptyIdFlashcards.Any())
            {
                throw new CourseLoadingException(
                          "Идентификаторы флеш-карт должны быть заполненными.\n" +
                          "Модуль с флешкартами с пустыми идентификаторами:\n" +
                          $"{Title}");
            }

            base.Validate(context);
        }
Пример #6
0
 public override void Validate(SlideLoadingContext context)
 {
     if (string.IsNullOrEmpty(PolygonPath))
     {
         throw new CourseLoadingException("В slide.polygon должен находиться атрибут polygonPath");
     }
     base.Validate(context);
 }
Пример #7
0
        public override void BuildUp(SlideLoadingContext context)
        {
            if (string.IsNullOrEmpty(ScoringGroup))
            {
                Scoring.ScoringGroup = context.CourseSettings.Scoring.DefaultScoringGroupForQuiz;
            }

            base.BuildUp(context);

            InitQuestionIndices();
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        public void Not_Report_Indentation_Warning_On_Ethalon_Solution_Of_SingleFileExercise()
        {
            var exerciseXmlFile = TestsHelper.ProjSlideFolder.GetFile("S055 - Упражнение на параметры по умолчанию.lesson.xml");

            var courseSettings = new CourseSettings(CourseSettings.DefaultSettings)
            {
                Preludes = new[] { new PreludeFile(Language.CSharp, TestsHelper.ProjSlideFolder.GetFile("Prelude.cs").FullName) }
            };

            var unit = new Unit(UnitSettings.CreateByTitle("Unit title", courseSettings), TestsHelper.ProjSlideFolder);
            var slideLoadingContext = new SlideLoadingContext("Test", unit, courseSettings, TestsHelper.ProjSlideFolder, exerciseXmlFile, 1);
            var exerciseSlide       = (ExerciseSlide) new XmlSlideLoader().Load(slideLoadingContext);

            var validatorOut = TestsHelper.ValidateExerciseSlide(exerciseSlide);

            validatorOut.Should().BeNullOrEmpty();
        }
Пример #10
0
        private Slide LoadSlide(FileInfo file, Unit unit, CourseLoadingContext context)
        {
            var slideLoadingContext = new SlideLoadingContext(context, unit, file);

            try
            {
                return(slideLoader.Load(slideLoadingContext));
            }
            catch (Exception e)
            {
                if (e.GetType().IsSubclassOf(typeof(CourseLoadingException)))
                {
                    throw;
                }
                throw new CourseLoadingException($"Не могу загрузить слайд из файла {file.GetRelativePath(context.CourseDirectory)}", e);
            }
        }
Пример #11
0
        public InstructorNote(string markdown, Unit unit, FileInfo file, CourseLoadingContext courseLoadingContext, int slideIndex)
        {
            Markdown = markdown;
            Unit     = unit;
            File     = file;
            Slide    = new Slide(new MarkdownBlock(Markdown)
            {
                Hide = true
            })
            {
                Id    = Unit.Id,
                Title = "Заметки преподавателю"
            };
            var slideLoadingContext = new SlideLoadingContext(courseLoadingContext, unit, file, slideIndex);

            Slide.BuildUp(slideLoadingContext);
            Slide.Validate(slideLoadingContext);
        }
Пример #12
0
        public override void BuildUp(SlideLoadingContext context)
        {
            if (FlashcardsList is null)
            {
                FlashcardsList = new Flashcard[0];
            }
            foreach (var flashcard in FlashcardsList)
            {
                flashcard.BuildUp(context, this);
            }

            if (Title is null)
            {
                Title = "Вопросы для самопроверки";
            }

            CheckBlockTypes();

            base.BuildUp(context);
        }
Пример #13
0
        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();
        }
Пример #14
0
        public override void BuildUp(SlideLoadingContext context)
        {
            var statementsPath = Path.Combine(context.Unit.Directory.FullName, PolygonPath, "statements");

            Blocks = GetBlocksProblem(statementsPath, context.CourseId, Id)
                     .Concat(Blocks.Where(block => !(block is MarkdownBlock)))
                     .ToArray();

            var polygonExercise = Blocks.Single(block => block is PolygonExerciseBlock) as PolygonExerciseBlock;

            polygonExercise !.ExerciseDirPath = Path.Combine(PolygonPath);
            var problem = GetProblem(Path.Combine(context.Unit.Directory.FullName, PolygonPath, "problem.xml"), context.CourseSettings.DefaultLanguage);

            polygonExercise.TimeLimitPerTest = problem.TimeLimit;
            polygonExercise.TimeLimit        = (int)Math.Ceiling(problem.TimeLimit * problem.TestCount);
            polygonExercise.UserCodeFilePath = problem.PathAuthorSolution;
            polygonExercise.Language         = LanguageHelpers.GuessByExtension(new FileInfo(polygonExercise.UserCodeFilePath));
            polygonExercise.DefaultLanguage  = context.CourseSettings.DefaultLanguage;
            polygonExercise.RunCommand       = $"python3.8 main.py {polygonExercise.Language} {polygonExercise.TimeLimitPerTest} {polygonExercise.UserCodeFilePath.Split('/', '\\')[1]}";
            Title = problem.Title;
            PrepareSolution(Path.Combine(context.Unit.Directory.FullName, PolygonPath, polygonExercise.UserCodeFilePath));

            base.BuildUp(context);
        }