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

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddWay(null));
            Assert.Throws <Exception>(() => cache.AddWay(new Way()));
            Assert.IsNull(cache.GetWay(way.Id.Value));

            cache.AddWay(way);

            Assert.IsTrue(cache.ContainsWay(way.Id.Value));
            Way readWay = cache.GetWay(way.Id.Value);

            Assert.IsNotNull(readWay);
            Assert.AreEqual(1, readWay.Id.Value);
            Assert.IsNotNull(way.Tags);
            Assert.AreEqual(1, way.Tags.Count);
            Assert.AreEqual("yes", way.Tags["way"]);

            Assert.IsTrue(cache.TryGetWay(way.Id.Value, out readWay));
            Assert.IsNotNull(readWay);
            Assert.AreEqual(1, readWay.Id.Value);
            Assert.IsNotNull(way.Tags);
            Assert.AreEqual(1, way.Tags.Count);
            Assert.AreEqual("yes", way.Tags["way"]);

            Assert.IsTrue(cache.RemoveWay(way.Id.Value));
            Assert.IsFalse(cache.ContainsWay(way.Id.Value));
            Assert.IsFalse(cache.RemoveWay(way.Id.Value));
        }
示例#2
0
        /// <summary>
        /// Tests the clear functionality on the datacache.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestClear(OsmDataCache cache)
        {
            Node node = Node.Create(1, new TagsCollection(
                                        Tag.Create("node", "yes")), 1, 2);
            Way way = Way.Create(1, new TagsCollection(
                                     Tag.Create("way", "yes")), 1, 2);
            Relation relation = Relation.Create(1, new TagsCollection(
                                                    Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node));

            cache.AddNode(node);
            cache.AddWay(way);
            cache.AddRelation(relation);

            Assert.IsTrue(cache.ContainsNode(node.Id.Value));
            Assert.IsTrue(cache.ContainsWay(way.Id.Value));
            Assert.IsTrue(cache.ContainsRelation(relation.Id.Value));

            cache.Clear();

            Assert.IsFalse(cache.ContainsNode(node.Id.Value));
            Assert.IsFalse(cache.ContainsWay(way.Id.Value));
            Assert.IsFalse(cache.ContainsRelation(relation.Id.Value));
        }
示例#3
0
        private bool IsChild(OsmGeo currentSimple)
        {
            switch (currentSimple.Type)
            {
            case OsmGeoType.Node:
                HashSet <long> nodesToInclude = this._nodesToInclude;
                long?          id1            = currentSimple.Id;
                long           num1           = id1.Value;
                if (nodesToInclude.Contains(num1))
                {
                    return(true);
                }
                OsmDataCache dataCache1 = this._dataCache;
                id1 = currentSimple.Id;
                long id2 = id1.Value;
                return(dataCache1.ContainsNode(id2));

            case OsmGeoType.Way:
                HashSet <long> waysToInclude = this._waysToInclude;
                long?          id3           = currentSimple.Id;
                long           num2          = id3.Value;
                if (waysToInclude.Contains(num2))
                {
                    return(true);
                }
                OsmDataCache dataCache2 = this._dataCache;
                id3 = currentSimple.Id;
                long id4 = id3.Value;
                return(dataCache2.ContainsWay(id4));

            case OsmGeoType.Relation:
                HashSet <long> relationsToInclude = this._relationsToInclude;
                long?          id5  = currentSimple.Id;
                long           num3 = id5.Value;
                if (relationsToInclude.Contains(num3))
                {
                    return(true);
                }
                OsmDataCache dataCache3 = this._dataCache;
                id5 = currentSimple.Id;
                long id6 = id5.Value;
                return(dataCache3.ContainsRelation(id6));

            default:
                return(false);
            }
        }
        /// <summary>
        /// Returns true if the given object is an object that needs to be included.
        /// </summary>
        /// <param name="currentSimple"></param>
        /// <returns></returns>
        private bool IsChild(OsmGeo currentSimple)
        {
            switch (currentSimple.Type)
            {
            case OsmGeoType.Node:
                return(_nodesToInclude.Contains(currentSimple.Id.Value) ||
                       _dataCache.ContainsNode(currentSimple.Id.Value));

            case OsmGeoType.Way:
                return(_waysToInclude.Contains(currentSimple.Id.Value) ||
                       _dataCache.ContainsWay(currentSimple.Id.Value));

            case OsmGeoType.Relation:
                return(_relationsToInclude.Contains(currentSimple.Id.Value) ||
                       _dataCache.ContainsRelation(currentSimple.Id.Value));
            }
            return(false);
        }