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); }
public static void InitDatabase() { if (!ConfigHelper.UseMaxMindDb()) { Task.Run(() => { CsvDatabaseHelper.GetAllGeoLiteCityBlock(); }); Task.Run(() => { CsvDatabaseHelper.GetAllGeoLiteCityLocation(); }); } }
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)); }