示例#1
0
 public Question()
 {
     Titre      = "";
     Lignes     = new List <string>();
     Reponses   = new List <Reponse>();
     Correction = new Correction("");
 }
示例#2
0
        public void Load(TextReader textStream)
        {
            State currentState = State.None;
            //
            Theme      currentTheme      = new Theme("aucun");
            Question   currentQuestion   = null;
            Reponse    currentReponse    = null;
            Correction currentCorrection = null;

            //
            while (textStream.Peek() > 0)
            {
                string ligne   = textStream.ReadLine();
                string toCheck = ligne.Trim();
                //
                switch (currentState)
                {
                case State.None:
                    if (toCheck.StartsWith(E3CTest.StartTheme))
                    {
                        currentTheme = new Theme(ligne);
                        currentState = State.Theme;
                    }
                    break;

                case State.Theme:
                    if (toCheck.StartsWith(E3CTest.StartTheme))
                    {
                        currentTheme = new Theme(ligne);
                    }
                    else if (toCheck.StartsWith(E3CTest.StartQuestion))
                    {
                        //
                        currentQuestion = new Question(ligne);
                        currentTheme.Questions.Add(currentQuestion);
                        this.AddTheme(currentTheme);
                        currentState = State.Question;
                    }
                    break;

                case State.Question:
                    if (toCheck.StartsWith(E3CTest.StartReponses))
                    {
                        // ligne est ignorée
                        currentState = State.Reponse;
                    }
                    else
                    {
                        currentQuestion.Lignes.Add(ligne);
                    }
                    break;

                case State.Reponse:
                    if (toCheck.StartsWith(E3CTest.StartTheme))
                    {
                        currentTheme = new Theme(ligne);
                        currentState = State.Theme;
                        break;
                    }
                    else if (toCheck.StartsWith(E3CTest.StartQuestion))
                    {
                        currentQuestion = new Question(ligne);
                        currentTheme.Questions.Add(currentQuestion);
                        this.AddTheme(currentTheme);
                        currentState = State.Question;
                        break;
                    }
                    else if (toCheck.StartsWith(E3CTest.StartCorrection))
                    {
                        currentCorrection          = new Correction(ligne);
                        currentQuestion.Correction = currentCorrection;
                        currentState = State.Theme;
                        break;
                    }
                    // Il y a quelquechose ?
                    if (ligne.Length > 0)
                    {
                        // Rien dans le premier caractère ?
                        if (String.IsNullOrWhiteSpace(ligne.Substring(0, 1)))
                        {
                            // Soit elle est vide, soit c'est la suite de la réponse
                            if (!String.IsNullOrWhiteSpace(ligne))
                            {
                                currentReponse.Lignes.Add(ligne);
                            }
                            //
                        }
                        else
                        {
                            // Début d'une réponse
                            currentReponse = new Reponse(ligne);
                            currentQuestion.Reponses.Add(currentReponse);
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }