Ejemplo n.º 1
0
    void Convert(TextAsset csv, string targetFile, string section)
    {
        QuestionData qData = new QuestionData();

        if (System.IO.File.Exists(XmlManager.XmlPath + targetFile))
        {
            qData = QuestionData.LoadAsInstance(XmlManager.XmlPath + targetFile);
            if (qData == null)
            {
                Debug.Log(string.Format("Target File {0} is exist, but it's content is null", targetFile));
                qData = new QuestionData();
            }
        }

        StringReader reader = new StringReader(csv.text);

        using (CsvReader csvReader = new CsvReader(reader, false))
        {
            int fieldCount = csvReader.FieldCount;
            Debug.Log(fieldCount);
            while (csvReader.ReadNextRecord())
            {
                string colorCode = csvReader[0];

                // Color Code pass check
                if ((colorCode != "B" && colorCode != "G" && colorCode != "R" &&
                     colorCode != "Y" && colorCode != "P" && colorCode != "O") ||
                    string.IsNullOrEmpty(colorCode))
                {
                    continue;
                }

                // Get the question content
                var qcontent = csvReader[2];

                QuestionData.question question = new QuestionData.question();
                question.content = qcontent.Trim();
                question.section = section;
                question.type    = GetColorNameFromCode(colorCode);


                qData.questions.Add(question);
            }
        }

        QuestionData.Save(targetFile, qData);

        //Debug.Log("Converted " + count);
    }
Ejemplo n.º 2
0
    private void EndElement(ref QuestionData qData, XmlReader xml)
    {
        switch (xml.Name)
        {
        case "question":
            qData.questions.Add(this.q);
            break;

        case "type":
            this.q.type = xmlValue;
            break;

        case "section":
            this.q.section = xmlValue;
            FixTypeBasedOnSection(ref this.q);
            break;

        case "content":
            this.q.content = xmlValue;
            break;

        case "info":
            this.q.info = xmlValue;
            break;

        case "answer":
            answer.text = xmlValue;
            this.q.answers.Add(answer);
            break;

        case "correct":
            foreach (var ans in this.q.answers)
            {
                if (ans.option == xmlValue)
                {
                    ans.correct = true;
                }
            }
            break;

        case "questions":
            Debug.Log("end questions");
            QuestionData.Save(targetFileName, qData);
            break;
        }

        xmlValue = "";
    }