当前位置: 首页>>代码示例>>C#>>正文


C# Reader.Find方法代码示例

本文整理汇总了C#中Reader.Find方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.Find方法的具体用法?C# Reader.Find怎么用?C# Reader.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Reader的用法示例。


在下文中一共展示了Reader.Find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestParallelFor

        public void TestParallelFor(FileAccessMode mode)
        {
            var count = 0;
            var ipsAndResults = new Dictionary<IPAddress, string>();
            var rand = new Random();
            using (var reader = new Reader(Path.Combine("..", "..", "TestData", "GeoLite2-City.mmdb"), mode))
            {
                while (count < 10000)
                {
                    var ip = new IPAddress(rand.Next(int.MaxValue));
                    var resp = reader.Find(ip);
                    if (resp != null && !ipsAndResults.ContainsKey(ip))
                    {
                        ipsAndResults.Add(ip, resp.ToString());
                        count++;
                    }
                }

                var ips = ipsAndResults.Keys.ToArray();
                Parallel.For(0, ips.Length, i =>
                {
                    var ipAddress = ips[i];
                    var result = reader.Find(ipAddress);
                    var resultString = result.ToString();
                    var expectedString = ipsAndResults[ipAddress];
                    if (resultString != expectedString)
                        throw new Exception($"Non-matching result. Expected {expectedString}, found {resultString}");
                });
            }
        }
开发者ID:RalphSim,项目名称:MaxMind-DB-Reader-dotnet,代码行数:30,代码来源:ThreadingTest.cs

示例2: TestParallelFor

        public void TestParallelFor(FileAccessMode mode)
        {
            var count = 0;
            var ipsAndResults = new Dictionary<IPAddress, string>();
            var rand = new Random();
            using (var reader = new Reader(Path.Combine("..", "..", "TestData", "GeoLite2-City.mmdb"), mode))
            {
                while (count < 10000)
                {
                    var ip = new IPAddress(rand.Next(int.MaxValue));
                    var resp = reader.Find(ip);
                    if (resp != null)
                    {
                        ipsAndResults.Add(ip, resp.ToString());
                        count++;
                    }
                }

                var ips = ipsAndResults.Keys.ToArray();
                var start = DateTime.Now;
                Parallel.For(0, ips.Length, i =>
                {
                    var ipAddress = ips[i];
                    var result = reader.Find(ipAddress);
                    var resultString = result.ToString();
                    var expectedString = ipsAndResults[ipAddress];
                    if (resultString != expectedString)
                        throw new Exception(string.Format("Non-matching result. Expected {0}, found {1}", expectedString, resultString));
                });
                var stop = DateTime.Now;
                Console.WriteLine("Requests per second: " + count / (stop - start).TotalSeconds);
            }
        }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:33,代码来源:ThreadingTest.cs

示例3: NoIPV4SearchTree

 public void NoIPV4SearchTree()
 {
     using (var reader = new Reader(Path.Combine(TestDataRoot, "MaxMind-DB-no-ipv4-search-tree.mmdb")))
     {
         Assert.That(reader.Find("1.1.1.1").ToObject<string>(), Is.EqualTo("::0/64"));
         Assert.That(reader.Find("192.1.1.1").ToObject<string>(), Is.EqualTo("::0/64"));
     }
 }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:8,代码来源:ReaderTest.cs

示例4: TestBrokenSearchTreePointer

 public void TestBrokenSearchTreePointer()
 {
     using (var reader = new Reader(Path.Combine(TestDataRoot, "MaxMind-DB-test-broken-pointers-24.mmdb")))
     {
         reader.Find("1.1.1.32");
     }
 }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:7,代码来源:ReaderTest.cs

示例5: TestBrokenDatabase

 public void TestBrokenDatabase()
 {
     using (var reader = new Reader(Path.Combine(TestDataRoot, "GeoIP2-City-Test-Broken-Double-Format.mmdb")))
     {
         reader.Find("2001:220::");
     }
 }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:7,代码来源:ReaderTest.cs

示例6: TestManyOpens

 public void TestManyOpens(FileAccessMode mode)
 {
     Parallel.For(0, 1000, i =>
     {
         using (var reader = new Reader(Path.Combine("..", "..", "TestData", "GeoLite2-City.mmdb"), mode))
         {
             reader.Find("1.1.1.1");
         }
     });
 }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:10,代码来源:ThreadingTest.cs

示例7: Main

        static void Main(string[] args)
        {
            using (var reader = new Reader("GeoLite2-City.mmdb", FileAccessMode.MemoryMapped))
            {
                var count = 100000;
                var rand = new Random();
                var start = DateTime.Now;
                for (int i = 0; i < count; i++)
                {
                    var ip = new IPAddress(rand.Next(int.MaxValue));
                    if (i % 50000 == 0)
                        Console.WriteLine(i + " " + ip);

                    var resp = reader.Find(ip);
                }

                var stop = DateTime.Now;
                Console.WriteLine("Requests per second: " + count / (stop - start).TotalSeconds);
            }
        }
开发者ID:horatiu80,项目名称:MaxMind-DB-Reader-dotnet,代码行数:20,代码来源:Program.cs

示例8: CanDeserializeFromDatabaseJToken

        public void CanDeserializeFromDatabaseJToken()
        {
            var reader =
                new Reader(Path.Combine("..", "..", "TestData", "MaxMind-DB", "test-data", "GeoIP2-City-Test.mmdb"));

            var obj = reader.Find("216.160.83.56");
            var response = obj.ToObject<InsightsResponse>();
            response.SetLocales(new List<string> { "en" });

            Assert.That(response.City.GeoNameId, Is.EqualTo(5803556));
            Assert.That(response.City.Name, Is.EqualTo("Milton"));

            Assert.That(response.Continent.Code, Is.EqualTo("NA"));
            Assert.That(response.Continent.GeoNameId, Is.EqualTo(6255149));
            Assert.That(response.Continent.Name, Is.EqualTo("North America"));

            Assert.That(response.Country.GeoNameId, Is.EqualTo(6252001));
            Assert.That(response.Country.IsoCode, Is.EqualTo("US"));
            Assert.That(response.Country.Name, Is.EqualTo("United States"));

            Assert.That(response.Location.Latitude, Is.EqualTo(47.2513));
            Assert.That(response.Location.Longitude, Is.EqualTo(-122.3149));
            Assert.That(response.Location.MetroCode, Is.EqualTo(819));
            Assert.That(response.Location.TimeZone, Is.EqualTo("America/Los_Angeles"));

            Assert.That(response.Postal.Code, Is.EqualTo("98354"));

            Assert.That(response.RegisteredCountry.GeoNameId, Is.EqualTo(2635167));
            Assert.That(response.RegisteredCountry.IsoCode, Is.EqualTo("GB"));
            Assert.That(response.RegisteredCountry.Name, Is.EqualTo("United Kingdom"));

            Assert.That(response.Subdivisions[0].GeoNameId, Is.EqualTo(5815135));
            Assert.That(response.Subdivisions[0].IsoCode, Is.EqualTo("WA"));
            Assert.That(response.Subdivisions[0].Name, Is.EqualTo("Washington"));
        }
开发者ID:choban49,项目名称:GeoIP2-dotnet,代码行数:35,代码来源:DeserializationTests.cs

示例9: TestDecodingTypes

        public void TestDecodingTypes()
        {
            using (var reader = new Reader(Path.Combine(TestDataRoot, "MaxMind-DB-test-decoder.mmdb")))
            {

                var record = reader.Find("::1.1.1.0");

                Assert.That(record.Value<bool>("boolean"), Is.True);

                Assert.That(record.Value<byte[]>("bytes"), Is.EquivalentTo(new byte[] { 0, 0, 0, 42 }));

                Assert.That(record.Value<string>("utf8_string"), Is.EqualTo("unicode! ☯ - ♫"));

                var array = record["array"];
                Assert.That(array, Is.InstanceOf<JArray>());
                Assert.That(array.Count(), Is.EqualTo(3));
                Assert.That(array[0].Value<int>(), Is.EqualTo(1));
                Assert.That(array[1].Value<int>(), Is.EqualTo(2));
                Assert.That(array[2].Value<int>(), Is.EqualTo(3));

                var map = record["map"];
                Assert.That(map, Is.InstanceOf<JObject>());
                Assert.That(map.Count(), Is.EqualTo(1));

                var mapX = map["mapX"];
                Assert.That(mapX.Count(), Is.EqualTo(2));

                var arrayX = mapX["arrayX"];
                Assert.That(arrayX.Count(), Is.EqualTo(3));
                Assert.That(arrayX[0].Value<int>(), Is.EqualTo(7));
                Assert.That(arrayX[1].Value<int>(), Is.EqualTo(8));
                Assert.That(arrayX[2].Value<int>(), Is.EqualTo(9));

                Assert.That(mapX.Value<string>("utf8_stringX"), Is.EqualTo("hello"));

                Assert.AreEqual(42.123456, record.Value<double>("double"), 0.000000001);
                Assert.AreEqual(1.1, record.Value<float>("float"), 0.000001);
                Assert.That(record.Value<int>("int32"), Is.EqualTo(-268435456));
                Assert.That(record.Value<int>("uint16"), Is.EqualTo(100));
                Assert.That(record.Value<int>("uint32"), Is.EqualTo(268435456));
                Assert.That(record.Value<UInt64>("uint64"), Is.EqualTo(1152921504606846976));
                Assert.That(record["uint128"].ToObject<BigInteger>(),
                    Is.EqualTo(BigInteger.Parse("1329227995784915872903807060280344576")));
            }
        }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:45,代码来源:ReaderTest.cs

示例10: TestAddresses

        private void TestAddresses(Reader reader, string file, IEnumerable<string> singleAddresses, Dictionary<string, string> pairs, IEnumerable<string> nullAddresses)
        {
            foreach (var address in singleAddresses)
            {
                Assert.That(reader.Find(address).Value<string>("ip"), Is.EqualTo(address), string.Format("Did not find expected data record for {0} in {1}", address, file));
            }

            foreach (var address in pairs.Keys)
            {
                Assert.That(reader.Find(address).Value<string>("ip"), Is.EqualTo(pairs[address]), string.Format("Did not find expected data record for {0} in {1}", address, file));
            }

            foreach (var address in nullAddresses)
            {
                Assert.That(reader.Find(address), Is.Null, string.Format("Did not find expected data record for {0} in {1}", address, file));
            }
        }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:17,代码来源:ReaderTest.cs

示例11: TestZeros

        public void TestZeros()
        {
            using (var reader = new Reader(Path.Combine(TestDataRoot, "MaxMind-DB-test-decoder.mmdb")))
            {
                var record = reader.Find("::");

                Assert.That(record.Value<bool>("boolean"), Is.False);

                Assert.That(record.Value<byte[]>("bytes"), Is.EquivalentTo(new byte[0]));

                Assert.That(record.Value<string>("utf8_string"), Is.EqualTo(""));

                Assert.That(record["array"], Is.InstanceOf<JArray>());
                Assert.That(record["array"].Count(), Is.EqualTo(0));

                Assert.That(record["map"], Is.InstanceOf<JObject>());
                Assert.That(record["map"].Count(), Is.EqualTo(0));

                Assert.AreEqual(0, record.Value<double>("double"), 0.000000001);
                Assert.AreEqual(0, record.Value<float>("float"), 0.000001);
                Assert.That(record.Value<int>("int32"), Is.EqualTo(0));
                Assert.That(record.Value<UInt16>("uint16"), Is.EqualTo(0));
                Assert.That(record.Value<UInt32>("uint32"), Is.EqualTo(0));
                Assert.That(record.Value<UInt64>("uint64"), Is.EqualTo(0));
                Assert.That(record["uint128"].ToObject<BigInteger>(), Is.EqualTo(new BigInteger(0)));
            }
        }
开发者ID:Wolfium,项目名称:MaxMind-DB-Reader-dotnet,代码行数:27,代码来源:ReaderTest.cs

示例12: CanDeserializeFromDatabaseJToken

        public void CanDeserializeFromDatabaseJToken()
        {
            var reader = new Reader(Path.Combine("..", "..", "TestData", "GeoLite2-City.mmdb"));

            var obj = reader.Find("74.125.227.161");
            var response = obj.ToObject<OmniResponse>();
            response.SetLocales(new List<string> { "en" });

            Assert.That(response.City.GeoNameId, Is.EqualTo(5375480));
            Assert.That(response.City.Name, Is.EqualTo("Mountain View"));

            Assert.That(response.Continent.Code, Is.EqualTo("NA"));
            Assert.That(response.Continent.GeoNameId, Is.EqualTo(6255149));
            Assert.That(response.Continent.Name, Is.EqualTo("North America"));

            Assert.That(response.Country.GeoNameId, Is.EqualTo(6252001));
            Assert.That(response.Country.IsoCode, Is.EqualTo("US"));
            Assert.That(response.Country.Name, Is.EqualTo("United States"));

            Assert.That(response.Location.Latitude, Is.EqualTo(37.419200000000004));
            Assert.That(response.Location.Longitude, Is.EqualTo(-122.0574));
            Assert.That(response.Location.MetroCode, Is.EqualTo(807));
            Assert.That(response.Location.TimeZone, Is.EqualTo("America/Los_Angeles"));

            Assert.That(response.Postal.Code, Is.EqualTo("94043"));

            Assert.That(response.RegisteredCountry.GeoNameId, Is.EqualTo(6252001));
            Assert.That(response.RegisteredCountry.IsoCode, Is.EqualTo("US"));
            Assert.That(response.RegisteredCountry.Name, Is.EqualTo("United States"));

            Assert.That(response.Subdivisions[0].GeoNameId, Is.EqualTo(5332921));
            Assert.That(response.Subdivisions[0].IsoCode, Is.EqualTo("CA"));
            Assert.That(response.Subdivisions[0].Name, Is.EqualTo("California"));
        }
开发者ID:Wolfium,项目名称:GeoIP2-dotnet,代码行数:34,代码来源:DeserializationTests.cs


注:本文中的Reader.Find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。