Пример #1
0
        public void Setup()
        {
            Config = new QQWryOptions()
            {
                DbPath = Test.MapRootPath("qqwry.dat")
            };
            QQWryIpSearchMode2 = new QQWryIpSearchMode2(Config);
            QQWryIpSearch      = new QQWryIpSearch(Config);

            //预热
            QQWryIpSearchMode2.GetIpLocation(GetRandomIp(QQWryIpSearchMode2));
            QQWryIpSearch.GetIpLocation(GetRandomIp(QQWryIpSearchMode2));

            Java2QQWry = new Java2QQWry(Config.DbPath);
            Java2QQWry.SearchIPLocation(GetRandomIp(QQWryIpSearchMode2));

            //加载数据
            data = new string[Range];
            for (int i = 0; i < data.Length; i++)
            {
                data[i] = GetRandomIp(QQWryIpSearchMode2);
            }
        }
Пример #2
0
        private static void Main(string[] args)
        {
            Console.WriteLine("QQWry Sample!");

            var config = new QQWryOptions()
            {
                DbPath = Test.MapRootPath("qqwry.dat")
            };

            #region QQWry
            Console.WriteLine("");
            Console.WriteLine("QQWry");

            var ipSearch      = new QQWryIpSearch(config);
            var ipSearchMode2 = new QQWryIpSearchMode2(config);

            var copyWrite = ipSearch.GetCopyWrite();
            var date      = copyWrite.Text.Replace("纯真IP地址数据库 ", string.Empty);
            var getNewDb  = ipSearch.Version.IndexOf(date) == -1;

            ipSearch.Init(getNewDb);
            ipSearchMode2.Init(getNewDb);

            for (var i = 0; i < 100; i++)
            {
                var ipLocation = ipSearchMode2.GetIpLocation(Test.GetRandomIp(ipSearchMode2));
                Write(ipLocation);
            }
            Console.WriteLine("记录总数" + ipSearchMode2.IpCount);
            Console.WriteLine("版本" + ipSearchMode2.Version);

            #endregion

            #region QQWry.DependencyInjection
            Console.WriteLine("");
            Console.WriteLine("QQWry.DependencyInjection");
            var service = new ServiceCollection();

            service.AddQQWry(config);

            var serviceProvider = service.BuildServiceProvider();

            using (var scope = serviceProvider.CreateScope())
            {
                var ipSearchInterface = scope.ServiceProvider.GetRequiredService <IIpSearch>();
                for (var i = 0; i < 100; i++)
                {
                    var ipLocation = ipSearch.GetIpLocation(Test.GetRandomIp(ipSearch));
                    Write(ipLocation);
                }
                Console.WriteLine("记录总数" + ipSearchInterface.IpCount);
                Console.WriteLine("版本" + ipSearchInterface.Version);
            }


            #endregion

            #region java to QQWry
            Console.WriteLine("");
            Console.WriteLine("java to QQWry");
            var javaQQWry = new Java2QQWry(config.DbPath);
            for (var i = 0; i < 100; i++)
            {
                var ip         = Test.GetRandomIp(ipSearch);
                var ipLocation = javaQQWry.SearchIPLocation(ip);
                Write(ip, ipLocation);
            }

            #endregion

            var summary = BenchmarkRunner.Run <Test>();

            Console.ReadKey();
        }
Пример #3
0
 public string[] QQWryIpSearchMode2Execute()
 {
     return(data.Select(x => QQWryIpSearchMode2.GetIpLocation(x).Country).ToArray());
 }