예제 #1
0
        public void ReadCsvData_GeoLiteCityBlockIsCorrectLoad()
        {
            var geoLiteBlock = CsvDatabaseHelper.GetAllGeoLiteCityBlock();
            var fileCount    = File.ReadLines(AppDomain.CurrentDomain.BaseDirectory + "\\GeoDatabases\\CsvDatabase\\GeoLiteCity-Blocks.csv").Count() - 2;

            Assert.AreEqual(fileCount, geoLiteBlock.Count);
        }
예제 #2
0
        public static void InitDatabase()
        {
            if (!ConfigHelper.UseMaxMindDb())
            {
                Task.Run(() =>
                {
                    CsvDatabaseHelper.GetAllGeoLiteCityBlock();
                });

                Task.Run(() =>
                {
                    CsvDatabaseHelper.GetAllGeoLiteCityLocation();
                });
            }
        }
예제 #3
0
        public IHttpActionResult Get(string ip = "")
        {
            if (string.IsNullOrEmpty(ip))
            {
                ip = GetIpAddress();
            }

            ip = RemovePort(ip);

            IPAddress ipAddress;

            if (string.IsNullOrEmpty(ip) || !IPAddress.TryParse(ip, out ipAddress))
            {
                return(BadRequest("Invalid ip address"));
            }

            GeoLiteCityLocationViewModel geoLiteCityLocation = null;

            if (ConfigHelper.UseMaxMindDb())
            {
                geoLiteCityLocation = MaxMindDatabaseHelper.GetGeoLiteCityLocation(ipAddress);
            }
            else
            {
                geoLiteCityLocation = CsvDatabaseHelper.GetGeoLiteCityLocation(ip);
            }

            if (geoLiteCityLocation == null)
            {
                return(BadRequest("Invalid ip address"));
            }

            geoLiteCityLocation.Ip = ip;

            return(Ok(geoLiteCityLocation));
        }