Exemplo n.º 1
0
        public static Quiz LoadQuiz(string name)
        {
            CardList list = new CardList();
            Quiz     quiz = new Quiz(list);

            quiz.Title = name;

            loadMetaData(quiz);
            loadCards(quiz, list);
            return(quiz);
        }
Exemplo n.º 2
0
        public static Quiz LoadQuiz(string pathname)
        {
            CardList     list = new CardList();
            Quiz         quiz = new Quiz(list);
            StreamReader file = new StreamReader(pathname);

            // First check the header
            checkHeader(file);
            loadMetaData(file, quiz);
            loadCards(file, list);
            file.Close();
            return(quiz);
        }
Exemplo n.º 3
0
        public static Quiz LoadQuiz(Quiz quiz)
        {
            if (quiz.Title == "")
            {
                return(quiz);
            }

            CardList list = new CardList();

            quiz.Cards = list;
            loadMetaData(quiz);
            loadCards(quiz, list);
            return(quiz);
        }
Exemplo n.º 4
0
        static void loadCards(Quiz quiz, CardList list)
        {
            string        sql     = "SELECT * FROM \"question\" WHERE \"quiz\" = @quiz";
            SQLiteCommand command = new SQLiteCommand(sql, dbConn);

            command.Parameters.Add("@quiz", DbType.Int32);
            command.Parameters["@quiz"].Value = quiz.ID;

            SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Card card = new Card(reader["question"].ToString(), reader["answer"].ToString());
                card.Type = reader["type"].ToString();
                // Fallback to flashcard type in case something went wrong
                if (card.Type == "")
                {
                    card.Type = "flashcard";
                }
                card.ID = int.Parse(reader["id"].ToString());

                if (card.Type == "multiplechoice")
                {
                    string   options     = reader["options"].ToString();
                    string[] optionArray = options.Split(new string[] { ";;" }, StringSplitOptions.None);
                    if (optionArray.Length != 4)
                    {
                        continue;
                    }

                    card.AddOption(0, optionArray[0]);
                    card.AddOption(1, optionArray[1]);
                    card.AddOption(2, optionArray[2]);
                    card.AddOption(3, optionArray[3]);
                }

                list.Add(card);
            }
        }
Exemplo n.º 5
0
 public Quiz(CardList list)
 {
     ID           = 0;
     LastModified = DateTime.Now;
     Cards        = list;
 }
Exemplo n.º 6
0
 public Quiz()
 {
     ID           = 0;
     LastModified = DateTime.Now;
     Cards        = new CardList();
 }
Exemplo n.º 7
0
        static void loadCards(StreamReader file, CardList list)
        {
            string line;
            Card   card = new Card();

            while ((line = file.ReadLine()) != null)
            {
                // Comments begin with #
                if (line[0] == '#')
                {
                    continue;
                }

                // === signifies the end of each question
                if (line == "===")
                {
                    list.Add(card);
                    card = new Card();
                    continue;
                }

                string property = "";
                string value    = "";
                int    position = line.IndexOf(':');
                if (position > 0)
                {
                    property = line.Substring(0, position);
                    value    = line.Substring(position + 1).Trim();
                }

                switch (property)
                {
                case "question":
                    card.Question = value;
                    break;

                case "type":
                    // Fallback to flashcard if type is blank
                    if (value == "")
                    {
                        value = "flashcard";
                    }
                    card.Type = value;
                    break;

                case "answer":
                    card.Answer = value;
                    break;

                case "a":
                    card.AddOption(0, value);
                    break;

                case "b":
                    card.AddOption(1, value);
                    break;

                case "c":
                    card.AddOption(2, value);
                    break;

                case "d":
                    card.AddOption(3, value);
                    break;
                }
            }
            // Add last card to deck
            list.Add(card);
        }