public void Init(int countryId) { var pendingRecords = dALSchedulers.Scheduler_GetNoLatitudeAndLogitute(countryId); var masterCityList = dALSchedulers.Scheduler_GetCityOnCountryId(countryId); string googleSearchText = string.Empty; string radiusData = string.Empty; string attractionaddress = string.Empty; string url = String.Empty; foreach (GoogleSearchTextDTO restlt in pendingRecords) { var mapsXapixFeature = dALSchedulers.Scheduler_CheckWithAccountNeedToUse("LatAndLong", countryId); if (string.IsNullOrEmpty(mapsXapixFeature?.API)) { break; } try { attractionaddress = restlt.AttractionName.Trim() + "," + restlt.GoogleSearchText.Trim(); radiusData = string.Empty; switch (mapsXapixFeature.MapsId) { case 2: { url = mapsXapixFeature.API + "key=" + mapsXapixFeature.apiKeyOrapiId + "&format=json" + "&q=" + attractionaddress; radiusData = webRequest.WebServiceInformation(url); var returnsInformation = JsonConvert .DeserializeObject <List <BusinessEntites.Scheduler.locationiq.LatAndLong> >(radiusData); if (returnsInformation != null && returnsInformation.Any()) { dALSchedulers.Scheduler_UpdateLatAndLong(restlt.AttractionsId, countryId, returnsInformation.Select(x => x.lat).FirstOrDefault(), returnsInformation.Select(x => x.lon).FirstOrDefault()); dALSchedulers.Scheduler_MapsLogging("LatAndLong_Init", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, string.Empty, string.Empty, string.Empty, countryId, restlt.AttractionsId, url, false, 0); } else { dALSchedulers.Scheduler_MapsLogging("LatAndLong_Init", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, string.Empty, string.Empty, countryId, restlt.AttractionsId, url, true, 0); } //Every request after taking a break of one second Thread.Sleep(1000); break; } } } catch (Exception ex) { dALSchedulers.Scheduler_MapsLogging("LatAndLong_Init", mapsXapixFeature.MapsId, mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData, ex.Message, ex.StackTrace, countryId, restlt.AttractionsId, url, true, 0); if (ex.Message == "The remote server returned an error: (429) Too Many Requests.") { Thread.Sleep(1000 * 60); } } } }
public void Init(int countryId) { try { var masterCityList = dALSchedulers.Scheduler_GetCityOnCountryId(countryId); string latitude = string.Empty; string longitude = string.Empty; var pendingAttractions = dALSchedulers.Scheduler_AttractionGetOnCityId(countryId); foreach (MasterCityDTO _masterCityDTO in masterCityList) { latitude = string.Empty; longitude = string.Empty; if (!_masterCityDTO.IsGettingNearLocationDone) { latitude = _masterCityDTO.Latitude; longitude = _masterCityDTO.Longitude; } if (string.IsNullOrEmpty(latitude) && string.IsNullOrEmpty(longitude)) { foreach (RadiusInfo attractionInfo in pendingAttractions) { var mapsXapixFeature = dALSchedulers.Scheduler_CheckWithAccountNeedToUse("Near By", countryId); if (string.IsNullOrEmpty(mapsXapixFeature?.API)) { break; } latitude = attractionInfo.Latitude; longitude = attractionInfo.Longitude; var googleType = dALSchedulers.Scheduler_GetTypes(mapsXapixFeature.MapsId); if (googleType.Any()) { NearestLocationApiCall(latitude, longitude, false, _masterCityDTO, googleType, countryId, attractionInfo.AttractionsId, mapsXapixFeature, attractionInfo.AttractionName); } } } else { var mapsXapixFeature = dALSchedulers.Scheduler_CheckWithAccountNeedToUse("Near By", countryId); if (!string.IsNullOrEmpty(mapsXapixFeature?.API)) { var googleType = dALSchedulers.Scheduler_GetTypes(mapsXapixFeature.MapsId); NearestLocationApiCall(latitude, longitude, true, _masterCityDTO, googleType, countryId, 0, mapsXapixFeature, string.Empty); } } } } catch (Exception ex) { exceptionLogging.InsertExceptionInformation(new LoggingEntity { CreatedBy = "scheduler", ExceptionMessage = ex.Message, ExceptionStackTrace = ex.StackTrace, MethodName = "GetRadiusInformation", Parameters = "countryId = " + countryId.ToString(), CountryId = countryId }); } }