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);
    }