示例#1
0
        public void Test1()
        {
            var map = new CefStringMap();

            map.Append("Key 1", "String 1");
            map.Append("Key 2", "String 2");
            map.Append("Key 3", "String 3");

            Assert.That(map.Count, Is.EqualTo(3));

            // TODO:

            /*
             * Assert.That(map.GetKey(0), Is.EqualTo("Key 1"));
             * Assert.That(map.GetValue(0), Is.EqualTo("String 1"));
             *
             * Assert.That(map.GetKey(1), Is.EqualTo("Key 2"));
             * Assert.That(map.GetValue(1), Is.EqualTo("String 2"));
             *
             * Assert.That(map.GetKey(2), Is.EqualTo("Key 3"));
             * Assert.That(map.GetValue(2), Is.EqualTo("String 3"));
             */

            Assert.That(map.GetValue("Key 2"), Is.EqualTo("String 2"));

            map.Clear();
            Assert.That(map.Count, Is.EqualTo(0));

            // TODO: map.Dispose();
        }
示例#2
0
        public override bool Read()
        {
            // First call to Read
            if (ReadState == System.Xml.ReadState.Initial)
            {
                var rootNode = this.document.GetDocument();
                this.nodeStack.Push(rootNode);
                currentNode = rootNode.GetFirstChild();
                return(CheckReadStateAndReturn());
            }

            if (xmlReader != null)
            {
                var result = xmlReader.Read();
                if (result && xmlReader.Depth > 0)
                {
                    return(result);
                }
                else
                {
                    xmlReader.Close();
                    textReader.Dispose();
                    xmlReader  = null;
                    textReader = null;
                }
            }

            switch (traverseDirection)
            {
            case TraverseDirection.Down:
                // As long as there're children go down (depth first)
                if (currentNode.HasChildren)
                {
                    nodeStack.Push(currentNode);
                    currentNode = currentNode.GetFirstChild();
                }
                else
                {
                    var parent = nodeStack.Peek();
                    using (var lastChild = parent.GetLastChild())
                    {
                        if (currentNode.IsSame(lastChild))
                        {
                            // Time to move back up
                            nodeStack.Pop();
                            traverseDirection = TraverseDirection.Up;
                            currentNode.Dispose();
                            currentNode = parent;
                        }
                        else
                        {
                            // There're still siblings left to visit
                            var nextSibling = currentNode.GetNextSibling();
                            currentNode.Dispose();
                            currentNode = nextSibling;
                        }
                    }
                }
                break;

            case TraverseDirection.Up:
                // See if we can find siblings (need to have a parent)
                if (nodeStack.Count > 1)
                {
                    var parent = nodeStack.Peek();
                    using (var lastChild = parent.GetLastChild())
                    {
                        if (currentNode.IsSame(lastChild))
                        {
                            // No sibling left, go further up
                            nodeStack.Pop();
                            currentNode.Dispose();
                            currentNode = parent;
                        }
                        else
                        {
                            // There's a sibling, try to traverse down again (depth first)
                            traverseDirection = TraverseDirection.Down;
                            var nextSibling = currentNode.GetNextSibling();
                            currentNode.Dispose();
                            currentNode = nextSibling;
                        }
                    }
                }
                else
                {
                    // No parent left, we have to be the root -> EOF
                    currentNode.Dispose();
                    currentNode = null;
                    readState   = System.Xml.ReadState.EndOfFile;
                    return(false);
                }
                break;
            }

            if (currentNode != null)
            {
                // See if this node defines a new namespace
                if (currentNode.IsElement && currentNode.HasElementAttributes())
                {
                    attributeMap = currentNode.GetElementAttributes();
                    switch (traverseDirection)
                    {
                    case TraverseDirection.Down:
                        for (int i = 0; i < attributeMap.Count; i++)
                        {
                            string key, value;
                            if (attributeMap.TryGetKey(i, out key) && attributeMap.TryGetValue(i, out value))
                            {
                                if (key.StartsWith("xmlns"))
                                {
                                    var prefix = GetNamespacePrefix(key);
                                    namespaceManager.AddNamespace(prefix, value);
                                }
                            }
                        }
                        namespaceManager.PushScope();
                        break;

                    case TraverseDirection.Up:
                        namespaceManager.PopScope();
                        break;
                    }
                }
                else
                {
                    attributeMap = null;
                }
            }

            return(CheckReadStateAndReturn());
        }