Beispiel #1
0
        private async Task ApplyGeocodingAsync(JOBDC oldObject, JOBDC newObject, HttpRequestMessage request)
        {
            bool applyGeoCoding = false;

            if (oldObject == null)
            {
                applyGeoCoding = true;
                //new geo codding
            }
            if (oldObject != null && oldObject.CompleteAddress != newObject.CompleteAddress)
            {
                applyGeoCoding = true;
            }

            if (applyGeoCoding)
            {
                JOBBL            jobsBL          = new JOBBL();
                string           completeAddress = newObject.CompleteAddress;
                GeocoderLocation geoCode         = null;
                try
                {
                    geoCode = await GMGeocoder.GoeCodeAsync(completeAddress);
                }
                catch (Exception exp)
                {
                    int userID = Common.Utility.GetUserID(Request);
                    Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, userID);
                }

                if (geoCode != null)
                {
                    newObject.LAT  = geoCode.Latitude.ToString();
                    newObject.LONG = geoCode.Longitude.ToString();
                    if (newObject != null)
                    {
                        List <EXCEPTIONDC> lstException = new List <EXCEPTIONDC>();
                        try
                        {
                            List <JOBDC> jobListToBeUpdated = new List <JOBDC>();
                            jobListToBeUpdated.Add(newObject);
                            if (jobListToBeUpdated.Count > 0)
                            {
                                jobsBL.Update(jobListToBeUpdated, ref lstException, true);
                            }
                        }
                        catch (Exception exp)
                        {
                            new TextResult(lstException, request);
                        }
                    }
                }
            }

            //return "Finished";
        }
Beispiel #2
0
        public async Task ApplyGeocodingAsync()
        {
            JOBBL        jobsBL             = new JOBBL();
            List <JOBDC> jobListToBeUpdated = new List <JOBDC>();

            try
            {
                GeocoderLocation geoCode = null;
                int requestLimit         = 2500;
                int requestCount         = 0;

                List <JOBDC> jobList_InvalidLatLong = jobsBL.GetAllJobsWithInvalidLatLongs();
                if (jobList_InvalidLatLong != null && jobList_InvalidLatLong.Count > 0)
                {
                    try
                    {
                        foreach (var jobObj in jobList_InvalidLatLong)
                        {
                            if (requestCount > requestLimit)
                            {
                                break;
                            }
                            // Perform GeoCoding if Either Latitude or Longitude is missing
                            string completeAddress = jobObj.CompleteAddress;
                            // Do not Perform GeoCoding if Address Information is completely missing to minimize limit-violation of Google Maps API
                            if (!String.IsNullOrEmpty(completeAddress))
                            {
                                geoCode = await GMGeocoder.GoeCodeAsync(completeAddress);

                                if (geoCode != null)
                                {
                                    jobObj.LAT  = geoCode.Latitude.ToString();
                                    jobObj.LONG = geoCode.Longitude.ToString();
                                    if (jobObj != null)
                                    {
                                        jobListToBeUpdated.Add(jobObj);
                                    }
                                }
                                requestCount++;
                                await Task.Delay(300);
                            }
                        }
                    }
                    catch (Exception exp)
                    {
                        Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, Constants.AdminUserID);
                    }
                }
            }
            catch (Exception exp)
            {
                Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, Constants.AdminUserID);
            }

            //update the address
            List <EXCEPTIONDC> lstException = new List <EXCEPTIONDC>();

            try
            {
                if (jobListToBeUpdated.Count > 0)
                {
                    jobsBL.UpdateJobLatLong(jobListToBeUpdated, true);
                }
            }
            catch (Exception exp)
            {
                Util.Utility.InsertIntoErrorLog(exp.Message, exp.StackTrace, Constants.AdminUserID);
            }
        }