Beispiel #1
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// <created>UPh,28.08.2015</created>
        /// <changed>UPh,28.08.2015</changed>
        // ********************************************************************************
        private void Load()
        {
            ClearData();
            if (!File.Exists(SettingsFile))
                return;

            using (XmlReader reader = XmlReader.Create(SettingsFile))
            {
                CXmlNode elRoot = new CXmlNode();
                if (!reader.ReadRootElement(ref elRoot))
                    return;

                CXmlNode elChild = new CXmlNode();
                while (elRoot.ReadChildNode(ref elChild))
                {
                    if (elChild.IsElement("termbases"))
                    {
                        CXmlNode elTermBase = new CXmlNode();
                        while (elChild.ReadChildNode(ref elTermBase, "file"))
                        {
                            string path;
                            bool active;
                            if (elTermBase.GetAttribute("path", out path) &&
                                elTermBase.GetBoolAttribute("active", out active))
                            {
                                TermBaseFile file = new TermBaseFile(path);
                                file.Active = active;
                                Files.Add(file);

                                Color displayColor;
                                if (elTermBase.GetColorAttribute("display_color", out displayColor))
                                    file.DisplayColor = displayColor;

                            }

                        }
                    }
                }
            }
        }
Beispiel #2
0
        public static bool ReadRootElement(this XmlReader reader, ref CXmlNode el)
        {
            XmlNodeType nodeType = XmlNodeType.None;
            while(reader.Read())
            {
                nodeType = reader.NodeType;
                if (nodeType != XmlNodeType.Element)
                    continue;

                int depth = reader.Depth;

                el.InitValues(XmlNodeType.Element, depth, reader);

                bool hr = reader.MoveToFirstAttribute();
                while (hr)
                {
                    string attName = reader.LocalName;
                    string attValue = reader.Value;

                    el.AddAttribute(attName, attValue);

                    hr = reader.MoveToNextAttribute();
                }

                return true;
            }

            return false;
        }
Beispiel #3
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="elementname"></param>
        /// <returns></returns>
        /// <created>UPh,10.02.2015</created>
        /// <changed>UPh,10.02.2015</changed>
        // ********************************************************************************
        public CXmlNode(CXmlNode nodeParent, string elementname)
        {
            m_nDepth = 0;
            m_nNodeType = XmlNodeType.EndElement;
            m_bEmptyElement = false;
            m_pReader = null;

            m_pWriter = nodeParent.m_pWriter;
            m_strName = elementname;

            m_pWriter.WriteStartElement(elementname);
        }
Beispiel #4
0
        //********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        /// <created>UPh,20.03.2013</created>
        /// <changed>UPh,20.03.2013</changed>
        //********************************************************************************
        public bool ReadChildNode(ref CXmlNode node, string elementname = null)
        {
            if (!IsReading)
                return false;

            node.m_nNodeType = XmlNodeType.None;
            node.m_strName = "";
            node.m_AttributeNames.Clear();
            node.m_AttributeValues.Clear();

            if (IsElement() && m_bEmptyElement)
                return false;

            // Read until we get the matching element end
            XmlReader reader = m_pReader;

            XmlNodeType nodeType = XmlNodeType.None;
            while(reader.Read())
            {
                nodeType = reader.NodeType;

                int depth = reader.Depth;

                if (elementname != null && nodeType != XmlNodeType.Element && nodeType != XmlNodeType.EndElement)
                    continue;

                if (nodeType == XmlNodeType.Element)
                {
                    if (depth > m_nDepth + 1)
                        continue; // Skip all sub elements in this loop

                    string name = reader.LocalName;
                    m_strName = name;

                    if (elementname != null && elementname != name)
                        continue;

                    node.m_strName = name;
                    node.m_nDepth = depth;
                    node.m_bEmptyElement = reader.IsEmptyElement;
                    node.m_nNodeType = nodeType;
                    node.m_pReader = m_pReader;

                    bool hr = reader.MoveToFirstAttribute();
                    while (hr)
                    {
                        string attName = reader.LocalName;
                        string attValue = reader.Value;

                        node.m_AttributeNames.Add(attName);
                        node.m_AttributeValues.Add(attValue);

                        hr = reader.MoveToNextAttribute();
                    }

                    return true;
                }
                else if (nodeType == XmlNodeType.Text)
                {
                    if (depth > m_nDepth + 1)
                        continue; // Skip all sub elements in this loop

                    string value = reader.Value;
                    node.m_strName = value;

                    node.m_nDepth = depth;
                    node.m_bEmptyElement = true;
                    node.m_nNodeType = nodeType;
                    node.m_pReader = m_pReader;
                    return true;
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (depth <= m_nDepth + 1)
                    {
                        m_bEmptyElement = true; // prevents returning wrong nodes, if ReadChildNode is called again
                        return false;
                    }
                }
            }

            return false;
        }
Beispiel #5
0
        //********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <created>UPh,20.03.2013</created>
        /// <changed>UPh,20.03.2013</changed>
        //********************************************************************************
        public string GetInnerText()
        {
            CXmlNode child = new CXmlNode();

            string text = "";

            while (ReadChildNode(ref child))
            {
                if (child.IsText())
                {
                    if (!string.IsNullOrEmpty(text))
                        text += " ";
                    text += child.GetText();
                }
            }

            return text;
        }
Beispiel #6
0
        //********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        /// <created>UPh,20.03.2013</created>
        /// <changed>UPh,20.03.2013</changed>
        //********************************************************************************
        public bool ReadChildNode(ref CXmlNode node, string elementname = null)
        {
            if (!IsReading)
            {
                return(false);
            }

            node.m_nNodeType = XmlNodeType.None;
            node.m_strName   = "";
            node.m_AttributeNames.Clear();
            node.m_AttributeValues.Clear();

            if (IsElement() && m_bEmptyElement)
            {
                return(false);
            }

            // Read until we get the matching element end
            XmlReader reader = m_pReader;

            XmlNodeType nodeType = XmlNodeType.None;

            while (reader.Read())
            {
                nodeType = reader.NodeType;

                int depth = reader.Depth;

                if (elementname != null && nodeType != XmlNodeType.Element && nodeType != XmlNodeType.EndElement)
                {
                    continue;
                }

                if (nodeType == XmlNodeType.Element)
                {
                    if (depth > m_nDepth + 1)
                    {
                        continue; // Skip all sub elements in this loop
                    }
                    string name = reader.LocalName;
                    m_strName = name;

                    if (elementname != null && elementname != name)
                    {
                        continue;
                    }

                    node.m_strName       = name;
                    node.m_nDepth        = depth;
                    node.m_bEmptyElement = reader.IsEmptyElement;
                    node.m_nNodeType     = nodeType;
                    node.m_pReader       = m_pReader;

                    bool hr = reader.MoveToFirstAttribute();
                    while (hr)
                    {
                        string attName  = reader.LocalName;
                        string attValue = reader.Value;

                        node.m_AttributeNames.Add(attName);
                        node.m_AttributeValues.Add(attValue);

                        hr = reader.MoveToNextAttribute();
                    }

                    return(true);
                }
                else if (nodeType == XmlNodeType.Text)
                {
                    if (depth > m_nDepth + 1)
                    {
                        continue; // Skip all sub elements in this loop
                    }
                    string value = reader.Value;
                    node.m_strName = value;

                    node.m_nDepth        = depth;
                    node.m_bEmptyElement = true;
                    node.m_nNodeType     = nodeType;
                    node.m_pReader       = m_pReader;
                    return(true);
                }
                else if (nodeType == XmlNodeType.EndElement)
                {
                    if (depth <= m_nDepth + 1)
                    {
                        m_bEmptyElement = true; // prevents returning wrong nodes, if ReadChildNode is called again
                        return(false);
                    }
                }
            }

            return(false);
        }