Beispiel #1
0
        public static XmlChaserNode ReadXml(XmlReader reader)
        {
            while (!reader.IsStartElement("Node") && reader.Read())
            {
                ;
            }

            var caption           = reader.GetAttribute(nameof(Caption));
            var probabilityString = reader.GetAttribute(nameof(Probability));
            var probability       = double.Parse(probabilityString);

            var root = new XmlChaserNode {
                Caption = caption, Probability = probability
            };

            if (reader.IsEmptyElement)
            {
                reader.Read();
            }
            else
            {
                while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                {
                    if (reader.IsStartElement("Node"))
                    {
                        var child = ReadXml(reader);
                        root.Add(child);
                    }
                }
                reader.Read();
            }

            return(root);
        }
Beispiel #2
0
        static async Task ReadXmlChildrenAsync(XmlReader reader, XmlChaserNode parent, XmlChaserNode root)
        {
            var isLeaf = true;

            if (reader.IsEmptyElement)
            {
                await reader.ReadAsync();
            }
            else
            {
                while (await reader.ReadAsync() && reader.NodeType != XmlNodeType.EndElement)
                {
                    if (reader.IsStartElement("Node"))
                    {
                        var child = await ReadXmlNodeAsync(reader);
                        await ReadXmlChildrenAsync(reader, child, root);

                        parent.Add(child);

                        isLeaf = false;
                    }
                }
                await reader.ReadAsync();
            }

            if (isLeaf)
            {
                parent._children = root._children;
            }
        }
Beispiel #3
0
        public void Add(XmlChaserNode node)
        {
            if (_children == null)
            {
                _children = new List <XmlChaserNode>();
            }

            var limit = _children.Count;

            while (0 < limit && _children[limit - 1].Probability < node.Probability)
            {
                limit--;
            }
            _children.Insert(limit, node);

            node.Parent = this;
        }
Beispiel #4
0
        static async Task <XmlChaserNode> ReadXmlNodeAsync(XmlReader reader)
        {
            while (!reader.IsStartElement("Node") && await reader.ReadAsync())
            {
                ;
            }

            var caption           = reader.GetAttribute(nameof(Caption));
            var probabilityString = reader.GetAttribute(nameof(Probability));
            var probability       = double.Parse(probabilityString);

            var node = new XmlChaserNode {
                Caption = caption, Probability = probability
            };

            return(node);
        }