Пример #1
0
        public void SetUp(ViewInterface view, FileModelInterface fileModel)
        {
            this.view      = view;
            this.fileModel = fileModel;
            this.quiz      = this.GetEmptyQuiz();

            this.LoadQuiz(quiz);
        }
Пример #2
0
        public void LoadQuiz(Quiz.Quiz quiz)
        {
            this.viewMap.ResetBoxes();
            this.viewMap.titleBox.Text = quiz.GetName();

            List <Quiz.Question> questions = quiz.GetQuestions();

            if (questions.Count() > 0)
            {
                this.loadQuestion(questions[0]);
            }
        }
Пример #3
0
        private Quiz.Quiz ParseXmlToObject(XmlDocument xmlDocument)
        {
            try
            {
                List <Quiz.Question> questions = new List <Quiz.Question>();
                foreach (XmlElement question in xmlDocument["quiz"]["questions"].ChildNodes)
                {
                    if (question["answers"].ChildNodes.Count >= 2)
                    {
                        List <Quiz.Answer> answers = new List <Quiz.Answer>();
                        foreach (XmlElement answer in question["answers"])
                        {
                            answers.Add(
                                new Quiz.Answer(
                                    answer["content"]["pl"].HasChildNodes ? answer["content"]["pl"].FirstChild.Value : "",
                                    Boolean.Parse(answer["is_correct"].FirstChild.Value)
                                    )
                                );
                        }

                        Quiz.Question fileQuestion = new Quiz.Question(
                            question["content"]["pl"].HasChildNodes ? question["content"]["pl"].FirstChild.Value : "",
                            answers[0],
                            answers[1],
                            answers.Skip(2).ToList()
                            );

                        questions.Add(fileQuestion);
                    }
                    else
                    {
                        // not enough answers
                        throw new Exception("File is invalid");
                    }
                }

                Quiz.Quiz parsedQuiz = new Quiz.Quiz(
                    xmlDocument["quiz"]["name"]["pl"].HasChildNodes ? xmlDocument["quiz"]["name"]["pl"].FirstChild.Value : "",
                    questions
                    );

                return(parsedQuiz);
            }
            catch (NullReferenceException exception)
            {
                //File has no appropriate fields
                throw new Exception("File is invalid");
            }
        }
Пример #4
0
        public void ImprtFromFile(string filePath)
        {
            try
            {
                XmlDocument xml = this.fileModel.GetXmlDocument(filePath);
                this.quiz = this.ParseXmlToObject(xml);

                this.LoadQuiz(this.quiz);
            }
            catch (Exception exception)
            {
                // xml is not valid or doesnt ex
                this.view.ShowModal(exception.Message);
            }
        }
Пример #5
0
 public void NewQuiz()
 {
     this.quiz = new Quiz.Quiz(NEW_QUIZ_NAME);
     this.LoadQuiz(quiz);
 }
Пример #6
0
 private void LoadQuiz(Quiz.Quiz quiz)
 {
     this.questionIndex = 0;
     this.view.LoadQuiz(quiz);
 }
Пример #7
0
        public Quiz.Quiz GetEmptyQuiz()
        {
            Quiz.Quiz quiz = new Quiz.Quiz(NEW_QUIZ_NAME);

            return(quiz);
        }