Exemplo n.º 1
0
        protected override void Add(string fileName)
        {
            string contents = File.ReadAllText(fileName);
            int    position = 0;

            while ((position = contents.IndexOf("\"x\"", position) + 3) != 2)
            {
                int id      = contents.IndexOf("\"id\"", position) + 4;
                int text    = contents.IndexOf("\"text\"", position) + 6;
                int choices = contents.IndexOf("\"choices\"", position) + 9;
                if (id == 3 || text == 5 || choices == 8)
                {
                    continue;
                }
                id = contents.IndexOf(':', id) + 1;
                FinalRounder imported = new FinalRounder(int.Parse(contents.Substring(id, contents.IndexOf(',', id) - id).Trim()),
                                                         Parsing.GetTextEntry(ref contents, contents.IndexOf(':', text) + 1));
                choices  = contents.IndexOf('[', choices);
                position = Parsing.FindArrayEnd(ref contents, choices);
                string choiceCut = contents.Substring(choices + 1, position - choices - 2);
                choices = 0;
                while (true)
                {
                    int correct = choiceCut.IndexOf("\"correct\"", choices) + 9;
                    text = choiceCut.IndexOf("\"text\"", choices) + 6;
                    if (correct == 8 || text == 5)
                    {
                        break;
                    }
                    string correctResult = choiceCut.Substring(correct, text - correct - 6);
                    imported.Items.Add(new FinalRounderChoice(correctResult.Contains("true"),
                                                              Parsing.GetTextEntry(ref choiceCut, choices = choiceCut.IndexOf(':', text) + 1)));
                }
                Add(imported);
            }
        }