示例#1
0
        /// <summary>
        /// Tests a simple node read/write operation.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestNode(OsmDataCache cache)
        {
            Node node = Node.Create(1, new TagsCollection(
                                        Tag.Create("node", "yes")), 1, 2);

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddNode(null));
            Assert.Throws <Exception>(() => cache.AddNode(new Node()));
            Assert.IsNull(cache.GetNode(node.Id.Value));

            cache.AddNode(node);

            Assert.IsTrue(cache.ContainsNode(node.Id.Value));
            Node readNode = cache.GetNode(node.Id.Value);

            Assert.IsNotNull(readNode);
            Assert.AreEqual(1, readNode.Id.Value);
            Assert.AreEqual(1, readNode.Latitude.Value);
            Assert.AreEqual(2, readNode.Longitude.Value);
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(1, node.Tags.Count);
            Assert.AreEqual("yes", node.Tags["node"]);

            Assert.IsTrue(cache.TryGetNode(node.Id.Value, out readNode));
            Assert.IsNotNull(readNode);
            Assert.AreEqual(1, readNode.Id.Value);
            Assert.AreEqual(1, readNode.Latitude.Value);
            Assert.AreEqual(2, readNode.Longitude.Value);
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(1, node.Tags.Count);
            Assert.AreEqual("yes", node.Tags["node"]);

            Assert.IsTrue(cache.RemoveNode(node.Id.Value));
            Assert.IsFalse(cache.ContainsNode(node.Id.Value));
            Assert.IsFalse(cache.RemoveNode(node.Id.Value));
        }
        /// <summary>
        /// Reports that the node with the given id was used.
        /// </summary>
        /// <param name="nodeId"></param>
        private void ReportNodeUsage(long nodeId)
        {
            int nodeCount;

            if (_nodesUsedTwiceOrMore.TryGetValue(nodeId, out nodeCount))
            { // node is used twice or more.
                nodeCount--;
                if (nodeCount > 0)
                { // update count.
                    _nodesUsedTwiceOrMore[nodeId] = nodeCount;
                }
                else
                { // remove twice or more.
                    _nodesUsedTwiceOrMore.Remove(nodeId);
                }
            }
            else
            { // the node was used for the last time.
                _dataCache.RemoveNode(nodeId);
            }
        }