Пример #1
0
        private static Question LoadQuestion(string questionDirectoryPath)
        {
            var question = new Question();
            foreach (var answerFilePath in Directory.GetFiles(questionDirectoryPath, "Answer*.cs"))
            {
                var answerLines = File.ReadLines(answerFilePath).ToList();
                var answer = new Answer();

                var correctAnswerLine = answerLines.FirstOrDefault(x => x.Contains("[CorrectAnswer"));
                if (correctAnswerLine != null)
                {
                    answer.IsCorrect = true;
                    question.Difficulty = ParseDifficulty(correctAnswerLine);
                }

                TrimToClass(answerLines);
                LoadHighlightedSectionIndexes(answerLines, answer);

                answer.Text = string.Join(Environment.NewLine, answerLines);

                question.Answers.Add(answer);
            }
            question.ShuffleAnswers();

            question.MarkdownHelpContent = LoadHelpContent(questionDirectoryPath);
            return question;
        }
        private void SelectAnswer(Answer answer)
        {
            _selectedAnswer = answer;
            Quiz.CurrentQuestion.SelectedAnswer = answer;

            var canContinue = Quiz.MoveToNextQuestion();
       
            if (!canContinue)
            {
                GoToNext();
                return;
            }

            OnPropertyChanged();
        }
 private static int[] GetHighlightedLines(Answer answer)
 {
     var lineCount = answer.HighlightedSectionEndIndex - answer.HighlightedSectionBeginIndex + 1;
     return Enumerable.Range(answer.HighlightedSectionBeginIndex + 1, lineCount).ToArray();
 }
Пример #4
0
        private static void LoadHighlightedSectionIndexes(List<string> answerLines, Answer answer)
        {
            answer.HighlightedSectionBeginIndex = answerLines.FindIndex(x => x.Contains("// begin"));
            answerLines.RemoveAt(answer.HighlightedSectionBeginIndex);

            answer.HighlightedSectionEndIndex = answerLines.FindIndex(x => x.Contains("// end")) - 1;
            answerLines.RemoveAt(answer.HighlightedSectionEndIndex + 1);
        }