public ImportManager(string tempFolderPath) { GeonamesAPIUserName = "******"; TempFolder = tempFolderPath; geolocationCacheManager = new GeolocationCacheManager(TempFolder); geolocationCacheManager.GeonamesAPIUserName = GeonamesAPIUserName; geolocationCacheManager.LoadCache(); }
/// <summary> /// For a list of ChargePoint objects, attempt to populate the AddressInfo (at least country) based on lat/lon if not already populated /// </summary> /// <param name="itemList"></param> /// <param name="coreRefData"></param> public void PopulateLocationFromGeolocationCache(List <ChargePoint> itemList, CoreReferenceData coreRefData) { GeolocationCacheManager geolocationCacheManager = new GeolocationCacheManager(TempFolder); geolocationCacheManager.GeonamesAPIUserName = GeonamesAPIUserName; geolocationCacheManager.LoadCache(); //process list of locations, populating country refreshing cache where required foreach (var item in itemList) { if (item.AddressInfo.Country == null) { var geoLookup = geolocationCacheManager.PerformLocationLookup((double)item.AddressInfo.Latitude, (double)item.AddressInfo.Longitude, coreRefData.Countries); if (geoLookup != null) { var country = coreRefData.Countries.FirstOrDefault(c => c.ID == geoLookup.CountryID || c.ISOCode == geoLookup.CountryCode || c.Title == geoLookup.CountryName); if (country != null) { item.AddressInfo.Country = country; //remove country name from address line 1 if present if (item.AddressInfo.AddressLine1.ToLower().Contains(country.Title.ToLower())) { item.AddressInfo.AddressLine1 = item.AddressInfo.AddressLine1.Replace(country.Title, "").Trim(); } } } } if (item.AddressInfo.Country == null) { LogHelper.Log("Failed to resolve country for item:" + item.AddressInfo.Title); } } //cache may have updates, save for next time geolocationCacheManager.SaveCache(); }