Example #1
0
        public Question Convert(QuestionResource questionResource)
        {
            var existingQuestion = CreatedQuestions.Where(obj => obj.Id == questionResource.Id).FirstOrDefault();

            if (existingQuestion != null)
            {
                if (existingQuestion is ChoiceQuestion)
                {
                    Assign(existingQuestion as ChoiceQuestion, questionResource);
                }
                else if (existingQuestion is TextQuestion)
                {
                    Assign(existingQuestion as TextQuestion, questionResource);
                }
                return(existingQuestion);
            }
            else
            {
                if (questionResource.DefaultChoice == null)
                {
                    var newChoiceQuestion = new ChoiceQuestion();
                    CreatedQuestions.Add(newChoiceQuestion);
                    Assign(newChoiceQuestion, questionResource);
                    return(newChoiceQuestion);
                }
                else
                {
                    var newTextQuestion = new TextQuestion();
                    CreatedQuestions.Add(newTextQuestion);
                    Assign(newTextQuestion, questionResource);
                    return(newTextQuestion);
                }
            }
        }
Example #2
0
        void Assign(TextQuestion textQuestion, QuestionResource questionResource)
        {
            textQuestion.Id = questionResource.Id;

            if (questionResource.QuestionText != null)
            {
                textQuestion.QuestionText = questionResource.QuestionText;
            }

            if ((questionResource.ChoicesThatOpensThis != null) && textQuestion.ChoicesThatOpensThis == null)
            {
                textQuestion.ChoicesThatOpensThis = new List <Choice>();

                foreach (ChoiceResource choiceResource in questionResource.ChoicesThatOpensThis)
                {
                    Choice newChoice = Convert(choiceResource);
                    textQuestion.ChoicesThatOpensThis.Add(newChoice);
                    if (newChoice.OpensQuestions == null)
                    {
                        newChoice.OpensQuestions = new List <Question>();
                    }
                    newChoice.OpensQuestions.Add(textQuestion);
                }
            }

            if ((questionResource.Choices != null) && textQuestion.Choices == null)
            {
                textQuestion.Choices = new List <ChoiceForTextQuestion>();

                foreach (ChoiceResource choiceResource in questionResource.Choices)
                {
                    ChoiceForTextQuestion newChoice = Convert(choiceResource) as ChoiceForTextQuestion;
                    textQuestion.Choices.Add(newChoice);
                    newChoice.Question = textQuestion;
                }
            }

            if ((questionResource.DefaultChoice != null) && textQuestion.DefaultChoice == null)
            {
                DefaultChoice newChoice = Convert(questionResource.DefaultChoice) as DefaultChoice;
                textQuestion.DefaultChoice = newChoice;
                newChoice.Question         = textQuestion;
            }
        }
Example #3
0
        private IEnumerable <QuestionResource> GetQuestionsFromResponseContent(string content)
        {
            string divBegin       = @"<div class='random_question'>";
            string divEnd         = @"</div>";
            string requiredPhrase = "Вопрос";

            var strings   = content.Split(divBegin);
            var questions = new List <QuestionResource>();

            foreach (var item in strings)
            {
                QuestionResource question = ConvertStringToQuestion(item.Contains(requiredPhrase) ? divBegin + item + divEnd : item, divBegin, divEnd);
                if (question.answer.Length > 0 && question.question.Length > 0)
                {
                    questions.Add(question);
                }
            }
            return(questions);
        }
Example #4
0
        public static IQuestion Create(QuestionResourcePath resourcePath)
        {
            QuestionResource resource = new QuestionResource(resourcePath);

            IQuestion returnObject = null;

            switch (resource.Answer.Value)
            {
            case "hai":
                returnObject = new Hai(resource);
                break;

            case "bai":
                returnObject = new Bai(resource);
                break;

            case "pai":
                returnObject = new Pai(resource);
                break;
            }
            return(returnObject);
        }
Example #5
0
        void Assign(ChoiceQuestion choiceQuestion, QuestionResource questionResource)
        {
            choiceQuestion.Id = questionResource.Id;

            if (questionResource.QuestionText != null)
            {
                choiceQuestion.QuestionText = questionResource.QuestionText;
            }

            if ((questionResource.ChoicesThatOpensThis != null) && choiceQuestion.ChoicesThatOpensThis == null)
            {
                choiceQuestion.ChoicesThatOpensThis = new List <Choice>();

                foreach (ChoiceResource choiceResource in questionResource.ChoicesThatOpensThis)
                {
                    Choice newChoice = Convert(choiceResource);
                    choiceQuestion.ChoicesThatOpensThis.Add(newChoice);
                    if (newChoice.OpensQuestions == null)
                    {
                        newChoice.OpensQuestions = new List <Question>();
                    }
                    newChoice.OpensQuestions.Add(choiceQuestion);
                }
            }

            if ((questionResource.Choices != null) && choiceQuestion.Choices == null)
            {
                choiceQuestion.Choices = new List <ChoiceForChoiceQuestion>();

                foreach (ChoiceResource choiceResource in questionResource.Choices)
                {
                    ChoiceForChoiceQuestion newChoice = Convert(choiceResource) as ChoiceForChoiceQuestion;
                    choiceQuestion.Choices.Add(newChoice);
                    newChoice.Question = choiceQuestion;
                }
            }
        }
Example #6
0
        private QuestionResource ConvertStringToQuestion(string html, string divBegin, string divEnd)
        {
            var index1 = html.IndexOf(divBegin);
            //console.log(index1)
            //console.log(html.indexOf('random_question'))


            var question = getTextBetweenTags(html, divBegin, divEnd);
            var title    = replaceEncodedSymbols(getTextBetweenTags(getTextBetweenTags(question, "<p>", "</p>"), ">", "<"));
            var text     = replaceEncodedSymbols(getTextBetweenTags(question, "</strong>", "<p>"));

            var img = getTextBetweenTags(question, "<img", ">");

            var answer  = getTextBetweenTags(question, "<strong>Ответ:</strong>", "</p>");
            var answer2 = getTextBetweenTags(question, "<strong>Зачёт:</strong>", "</p>");
            var _author = getTextBetweenTags(question, "<strong>Автор:</strong>", "</p>");
            var source  = replaceEncodedSymbols(getTextBetweenTags(question, "<strong>Источник(и):</strong>", "</p>"));
            var comment = replaceEncodedSymbols(getTextBetweenTags(question, "<strong>Комментарий:</strong>", "</p>"));

            var tmp    = getTextBetweenTags(_author, ">", "<");
            var author = tmp.Length == 0 ? _author : tmp;

            var result = new QuestionResource()
            {
                answer    = answer,
                title     = title,
                answer2   = answer2,
                author    = author,
                comment   = comment,
                imageLink = img.Length == 0 ? "" : "<img " + img + ">",
                question  = text,
                source    = source
            };

            return(result);
        }
Example #7
0
 public Bai(QuestionResource resource) : base(resource)
 {
 }
Example #8
0
 public GeneralQuestionBase(QuestionResource resource)
 {
     _resource = resource;
 }