Exemple #1
0
    public void ReadBook(Progress progress)
    {
        string xmlpath = BookDirectory() + m_bookName + ".xml";

        XmlDocument doc = new XmlDocument();

        doc.Load(xmlpath);
        XmlNodeList headerList = doc.DocumentElement.GetElementsByTagName(m_headerTag);
        IEnumerator headerEnum = headerList.GetEnumerator();

        if (headerEnum.MoveNext())
        {
            XmlNode headerNode = (XmlNode)headerEnum.Current;
            var     typeAttr   = headerNode.Attributes[m_typeTag];
            if (typeAttr != null)
            {
                m_type = typeAttr.Value;
            }
            m_answerType = AnswerType.Default;
            var answerAttr = headerNode.Attributes[m_answerTag];
            if (answerAttr != null)
            {
                m_answerType = (AnswerType)Enum.Parse(typeof(AnswerType), answerAttr.Value);
            }

            var timeAttr = headerNode.Attributes[m_timeTag];
            if (timeAttr != null)
            {
                m_timer = Convert.ToInt32(timeAttr.Value);
            }
        }

        XmlNodeList contentList = doc.DocumentElement.GetElementsByTagName(m_contentTag);
        IEnumerator contentEnum = contentList.GetEnumerator();

        while (contentEnum.MoveNext())
        {
            XmlNode     contentNode = (XmlNode)contentEnum.Current;
            XmlNodeList itemList    = contentNode.SelectNodes(m_itemTag);
            IEnumerator itemEnum    = itemList.GetEnumerator();
            while (itemEnum.MoveNext())
            {
                XmlNode itemNode = (XmlNode)itemEnum.Current;
                string  word     = itemNode.Attributes[m_idTag].Value;
                if (!m_wordSet.Contains(word))
                {
                    m_wordSet.Add(word);
                    m_bookWords.Add(word);
                    BookItem item = new BookItem(word, this);
                    item.ReadItem(itemNode);
                    progress.AddWord(item);
                    m_bookItems.Add(item);
                }
            }
        }
        ItemComparer comparer = new ItemComparer();

        m_bookItems.Sort(comparer);
    }