public void MissingDistance(int countryId) { //var googleCounter = dALSchedulers.Scheduler_GetGoogleMapsMethodCount("directions"); //if (googleCounter == null || googleCounter.Counter < // Convert.ToInt32(ConfigurationManager.AppSettings["recordCount"])) { var pendingRecords = dALSchedulers.Scheduler_GetMissingDistance(countryId); var travelMode = dALSchedulers.Scheduler_GetTravelMode(); AttractionTravelTimeDistanceDTO attractionTravelTimeDistanceDTO = new AttractionTravelTimeDistanceDTO(); foreach (AttractionsDTO attractionsDTO in pendingRecords) { var attractionInformation = dALSchedulers.Scheduler_GetDestinationMissingDistance(countryId, attractionsDTO.AttractionsId); foreach (MissingDataAttractionDTO _attractionsDTO in attractionInformation) { foreach (MasterTravelModeDTO masterTravelModeDTO in _attractionsDTO.MasterTravelModeID > 0 ? travelMode.Where(x => x.TravelModeId == _attractionsDTO.MasterTravelModeID) : travelMode) { DistanceGetting(masterTravelModeDTO.TravelType, _attractionsDTO.SourceText, _attractionsDTO.DestinationText, attractionsDTO.AttractionsId, _attractionsDTO.AttractionsId, masterTravelModeDTO.TravelModeId, countryId); } dALSchedulers.Scheduler_DeleteMissingDistanceDestination(countryId, _attractionsDTO .MissingDistanceAttractionsRecordsXAttractionsID); } dALSchedulers.Scheduler_DeleteMissingDistance(countryId, attractionsDTO.AttractionsId); } } }
public void DistanceGetting(string travelType, string origin, string destination, int sourceAttractionId, int destinationAttractionId, int travelTypeId, int countryId) { string url = string.Empty; try { AttractionTravelTimeDistanceDTO attractionTravelTimeDistanceDTO = new AttractionTravelTimeDistanceDTO(); string radiusData = string.Empty; origin = origin.Replace('#', ' '); destination = destination.Replace('#', ' '); url = "https://maps.googleapis.com/maps/api/directions/json?&mode=" + travelType.ToLower() + "&origin=" + origin + "&destination=" + destination + "&key=" + ConfigurationManager.AppSettings["apiKey"]; radiusData = webRequest.WebServiceInformation(url); var returnsInformation = Newtonsoft.Json.JsonConvert.DeserializeObject <NearBySearchEntity>(radiusData); if (returnsInformation.results != null && returnsInformation.results.Count > 0) { //dALSchedulers.Scheduler_GoogleLogging("directions", "CalculateDistance", "", // string.Empty, string.Empty, // false); } else { //dALSchedulers.Scheduler_GoogleLogging("directions", "CalculateDistance", "", // string.Empty, string.Empty, // true); } attractionTravelTimeDistanceDTO = new AttractionTravelTimeDistanceDTO(); attractionTravelTimeDistanceDTO.SourceAttractionId = sourceAttractionId; attractionTravelTimeDistanceDTO.DestinationAttractionId = destinationAttractionId; attractionTravelTimeDistanceDTO.TravelModeId = travelTypeId; attractionTravelTimeDistanceDTO.Distance = Convert.ToInt32( returnsInformation.routes.FirstOrDefault().legs.FirstOrDefault().distance.value); attractionTravelTimeDistanceDTO.TravelTime = Convert.ToInt32( returnsInformation.routes.FirstOrDefault().legs.FirstOrDefault().duration.value); List <StepsConsolidated> stepsConsolidated = new List <StepsConsolidated>(); StepsConsolidated _stepsConsolidated = new StepsConsolidated(); int OrderId = 1; foreach (Steps _steps in returnsInformation.routes.FirstOrDefault().legs.FirstOrDefault().steps .ToList()) { _stepsConsolidated = new StepsConsolidated() { distance_Value = Convert.ToInt32(_steps.distance.value), duration_Value = Convert.ToInt32(_steps.duration.value), end_location_lat = _steps.end_location.lat, end_location_lng = _steps.end_location.lng, start_location_lat = _steps.start_location.lat, start_location_lng = _steps.start_location.lng, travel_mode = _steps.travel_mode, OrderId = OrderId++ }; stepsConsolidated.Add(_stepsConsolidated); } dALSchedulers.Scheduler_InsertAttractionTravelTimeDistance( attractionTravelTimeDistanceDTO, countryId, stepsConsolidated); } catch (Exception ex) { exceptionLogging.InsertExceptionInformation(new LoggingEntity { CreatedBy = "scheduler", ExceptionMessage = ex.Message, ExceptionStackTrace = ex.StackTrace, MethodName = "CalculateDistance", Parameters = "SourceAttractionId = " + sourceAttractionId + " DestinationAttractionId = " + destinationAttractionId + " TravelModeId = " + travelTypeId + "url= " + url, CountryId = countryId }); } }