コード例 #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);
        }
コード例 #2
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);
        }