Exemplo n.º 1
0
        public void BtreeSearchTestForChinese()
        {
            const int    cityId = 2163;
            const string region = "中国|0|广东省|深圳市|鹏博士";

            var result = _dbSearcher.BtreeSearch("101.105.35.57");

            Assert.AreEqual(result.CityID, cityId);
            Assert.AreEqual(result.Region, region);
        }
Exemplo n.º 2
0
        public void Search_Test()
        {
            string memResult              = _search.MemorySearch("223.104.246.20").Region;
            string binarySearchResult     = _search.BinarySearch("223.104.246.20").Region;
            string binaryTreeSearchResult = _search.BtreeSearch("223.104.246.20").Region;

            Assert.NotNull(memResult);
            Assert.NotNull(binarySearchResult);
            Assert.NotNull(binaryTreeSearchResult);

            Assert.Equal(memResult, binarySearchResult);
            Assert.Equal(binaryTreeSearchResult, memResult);
        }
Exemplo n.º 3
0
        public Object GetInfo()
        {
            var ico = new IcoCore(dc).GetIcoStat();

            DbSearcher dbSearcher = new DbSearcher(new DbConfig
            {
            }, $"{Database.ContentRootPath}{Path.DirectorySeparatorChar}App_Data{Path.DirectorySeparatorChar}ip2region.db");
            var ipRegion = dbSearcher.BtreeSearch(Request.Host.Host);

            return(new
            {
                Sold = (ico.TotalSupply - ico.AvailableSupply).ToString("N0"),
                Available = ico.AvailableSupply.ToString("N0"),
                Total = ico.TotalSupply.ToString("N0"),
                Percent = (ico.TotalSupply - ico.AvailableSupply) / ico.TotalSupply * 100 + "%",
                StartDate = ico.StartDate,
                IpRegion = ipRegion.GetRegion()
            });
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            DbSearcher dbSearcher = new DbSearcher(new DbConfig
            {
            }, AppContext.BaseDirectory + @"/DBFile/ip2region.db");
            string    ipAddress = "";
            DataBlock result = null, result2 = null, result3 = null;

            Console.WriteLine("请输入IP地址:");
            ipAddress = Console.ReadLine();
            Stopwatch sw = new Stopwatch();

            do
            {
                sw.Start();
                try
                {
                    result = dbSearcher.BtreeSearch(ipAddress);
                    sw.Stop();
                    Console.WriteLine("[btree]你的IP所属区域为:" + result.GetRegion() + ";耗时:" + sw.Elapsed.TotalMilliseconds + "ms");
                    sw.Start();
                    result2 = dbSearcher.BinarySearch(ipAddress);
                    sw.Stop();
                    Console.WriteLine("[binarySearch]你的IP所属区域为:" + result2.GetRegion() + ";耗时:" + sw.Elapsed.TotalMilliseconds + "ms");
                    sw.Start();
                    result3 = dbSearcher.MemorySearch(ipAddress);
                    sw.Stop();
                    Console.WriteLine("[MemorySearch]你的IP所属区域为:" + result3.GetRegion() + ";耗时:" + sw.Elapsed.TotalMilliseconds + "ms");
                    Console.WriteLine("请输入IP地址:");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    sw.Stop();
                }

                //Console.WriteLine("结束请输入bye");
            } while ((ipAddress = Console.ReadLine()) != "bye");
        }