Ejemplo n.º 1
0
        internal static List <Groupe> importQuestions(string sourcepath, int verbose)
        {
            XmlDocument document = new XmlDocument();

            document.Load(sourcepath);
            List <Groupe> res = new List <Groupe>();
            Groupe        g   = new Groupe();

            foreach (XmlNode question in document.DocumentElement)
            {
                Question q = null;
                if (question.Name.Equals("question"))
                {
                    switch (question.Attributes[0].InnerText)
                    {
                    case "multichoice":
                        q = makeMultiChoiceQuestion(question);
                        break;

                    case "description":
                        q = makecDescription(question);
                        break;

                    case "essay":
                        q = makeEssayQuestion(question);
                        break;

                    case "matching":
                        q = makeMatchingQuestion(question);
                        break;

                    case "truefalse":
                        q = makeTrueFalseQuestion(question);
                        break;

                    case "numerical":
                        q = makeNumericalQuestion(question);
                        break;

                    case "shortanswer":
                        q = makeShortAnswerQuestion(question);
                        break;
                    }
                    if (q != null)
                    {
                        g.addQuestion(q);
                        logImport(q);
                    }
                }
            }
            res.Add(g);
            return(res);
        }
Ejemplo n.º 2
0
        private static Object makeQuestion(Groupe gp, Boolean open, string ligne)
        {
            String   type = ligne.Substring(0, 2);
            Question q    = null;
            Groupe   g    = null;

            switch (type)
            {
            case "*<":
                q = new QuestionOuverteAMC();
                int nblignes = 1;
                int debutl   = ligne.IndexOf("<");
                int finl     = ligne.IndexOf(">");
                if ((debutl != -1) && (finl != -1))
                {
                    String   options = ligne.Substring(debutl + 1, finl - 2);
                    String[] spl     = options.Split("=");
                    if (spl[0].ToLower().Equals("lines"))
                    {
                        nblignes = int.Parse(spl[1]);
                    }
                    q.addTitre(ligne.Substring(finl + 1));
                }
                ((QuestionOuverte)q).setLignes(nblignes);
                break;

            case "**":
                q = new QuestionMultiple();
                break;

            case "*(":
                g = new Groupe();
                g.addTexte1(ligne.Substring(3));
                break;

            case "*)":
                if (open)
                {
                    open = false;
                    if (ligne.Length > 2)
                    {
                        gp.addTexte2(ligne.Substring(2));
                    }
                }
                break;

            default:
                q = new QuestionSimple();
                break;
            }
            int debutopt = ligne.IndexOf("{");
            int finopt   = ligne.IndexOf("}");

            if ((debutopt != -1) && (finopt != -1))
            {
                ligne = ligne.Substring(finopt + 2);
            }
            else
            {
                ligne = ligne.Substring(2);
            }
            if (q != null)
            {
                if (q.titre.Count == 0)
                {
                    q.addTitre(ligne);
                }
                return(q);
            }
            return(g);
        }
Ejemplo n.º 3
0
        internal static List <Groupe> importQuestions(string sourcepath, int verbose)
        {
            List <Groupe> res = new List <Groupe>();
            Groupe        g   = new Groupe();

            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(sourcepath);
                String allFile;
                int    nbligne = 0;
                allFile = file.ReadToEnd();
                String titreq = "";
                // ligne pour gerer le code FEFF en UTF-8 BOM qui peut apparaitre si le fichier
                // txt est edité avec windows notepad
                // ce caractere apparait uniquement en debut de fichier
                if (allFile.Substring(0, 1).Equals("\uFEFF"))
                {
                    allFile = allFile.Substring(1);
                }
                string[] lines = allFile.Split('\r');
                int      i     = 0;
                while (i < lines.Length)
                {
                    if (lines[i].Length == 1)
                    {
                        //Console.WriteLine(lines[i]);
                    }
                    else
                    {
                        if (!(lines[i].Substring(0, 2).Equals("//")) && !(lines[i].Substring(0, 3).Equals("\n//"))) // si ligne commence par un # c'est un commentaire, donc on l'ignore
                        {
                            for (int j = 0; j < lines[i].Length; j++)
                            {
                                if (lines[i][j].Equals('\\'))
                                {
                                    j++;
                                }
                                else if (lines[i][j] == '{')
                                {
                                    StringBuilder sb = new StringBuilder();
                                    j++;
                                    if (j == lines[i].Length)
                                    {
                                        j = 0;
                                        i++;
                                        nbligne++;
                                    }
                                    while (lines[i][j] != '}' && i < lines.Length)
                                    {
                                        if (j == lines[i].Length)
                                        {
                                            j = 0;
                                            i++;
                                            nbligne++;
                                        }
                                        else
                                        {
                                            sb.Append(lines[i][j]);
                                            j++;
                                            if (j == lines[i].Length)
                                            {
                                                j = 0;
                                                i++;
                                                nbligne++;
                                            }
                                        }
                                    }
                                    Question q = makeQuestion(sb.ToString(), titreq);
                                    g.addQuestion(q);
                                    logImport(q);
                                    titreq = "";
                                }
                                else
                                {
                                    titreq += lines[i][j];
                                }
                            }
                        }
                    }
                    nbligne++;
                    i++;
                }

                file.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            res.Add(g);
            return(res);
        }