Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        private void NearestLocationApiCall(string latitude, string longitude,
                                            bool isCityInfo, MasterCityDTO masterCityDto, List <GoogleTypes> googleType, int countryId,
                                            int attractionId, MapsXAPIXFeature mapsXapixFeature, string attractionName, int attractionTravelStepsId = 0)
        {
            string radiusData = string.Empty;
            string url        = string.Empty;


            if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude))
            {
                foreach (var googleTypes in googleType)
                {
                    try
                    {
                        radiusData = string.Empty;
                        url        = string.Empty;
                        switch (mapsXapixFeature.MapsId)
                        {
                        //google
                        case 1:
                        {
                            url =
                                mapsXapixFeature.API +
                                latitude +
                                "," +
                                longitude + "&radius=25000&key=" +
                                mapsXapixFeature.apiKeyOrapiId;

                            if (!string.IsNullOrEmpty(googleTypes.TypeName))
                            {
                                url = url + "&type=" + googleTypes.TypeName;
                            }

                            radiusData = webRequest.WebServiceInformation(url);
                            var returnsInformation =
                                JsonConvert.DeserializeObject <NearBySearchEntity>(
                                    radiusData);

                            if (returnsInformation != null && returnsInformation.results.Any())
                            {
                                if (isCityInfo)
                                {
                                    dALSchedulers.UpdateCityNearestLocationDont(masterCityDto
                                                                                .CityId);
                                }

                                InsertSearchResult(returnsInformation, countryId, url,
                                                   longitude,
                                                   latitude,
                                                   attractionId, attractionTravelStepsId, mapsXapixFeature.MapsId,
                                                   mapsXapixFeature);

                                dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId,
                                                                    mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData,
                                                                    string.Empty, string.Empty, countryId, attractionId, url, false, attractionTravelStepsId);
                            }
                            else
                            {
                                dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId,
                                                                    mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData,
                                                                    string.Empty, string.Empty, countryId, attractionId, url, true, attractionTravelStepsId);
                            }

                            break;
                        }

                        //locationiq
                        case 2:
                        {
                            url =
                                mapsXapixFeature.API +
                                "key=" + mapsXapixFeature.apiKeyOrapiId +
                                "&format=json" +
                                "&lat=" + latitude +
                                "&lon=" + longitude +
                                "&tag=" + googleTypes.TypeName;
                            radiusData = webRequest.WebServiceInformation(url);
                            var returnsInformation = JsonConvert
                                                     .DeserializeObject <List <NearBy> >(radiusData);


                            if (returnsInformation != null && returnsInformation.Any())
                            {
                                var result = returnsInformation.Where(x => !string.IsNullOrEmpty(x.name)).Select(
                                    y => new ResultsList
                                    {
                                        geometry = new geometryList
                                        {
                                            location = new locationList
                                            {
                                                lat = y.lat,
                                                lng = y.lon
                                            }
                                        },
                                        name  = y.name,
                                        types = (new List <string>()
                                        {
                                            googleTypes.TypeName
                                        }).ToArray()
                                    }).ToList();



                                InsertSearchResult(new NearBySearchEntity {
                                        results = result
                                    }, countryId, url,
                                                   longitude,
                                                   latitude,
                                                   attractionId, attractionTravelStepsId, mapsXapixFeature.MapsId,
                                                   mapsXapixFeature);

                                dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall",
                                                                    mapsXapixFeature.MapsId,
                                                                    mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId,
                                                                    string.Empty,
                                                                    string.Empty, string.Empty, countryId, attractionId, url, false,
                                                                    attractionTravelStepsId);
                            }
                            else
                            {
                                dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId,
                                                                    mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData,
                                                                    string.Empty, string.Empty, countryId, attractionId, url, true, attractionTravelStepsId);
                            }
                            //Every request after taking a break of one second
                            Thread.Sleep(1000);
                            break;
                        }

                        case 3:
                        {
                            if (!string.IsNullOrEmpty(attractionName))
                            {
                                url =
                                    mapsXapixFeature.API +
                                    "at=" + latitude + "," + longitude +
                                    "&q=" + attractionName +
                                    "&app_id=" + mapsXapixFeature.apiKeyOrapiId +
                                    "&app_code=" + mapsXapixFeature.apiCode;
                                radiusData = webRequest.WebServiceInformation(url);
                                var returnsInformation = JsonConvert
                                                         .DeserializeObject <BusinessEntites.Scheduler.here.NearBy>(radiusData);
                            }
                            break;
                        }
                        }
                    }
                    catch (Exception ex)
                    {
                        dALSchedulers.Scheduler_MapsLogging("NearestLocationApiCall", mapsXapixFeature.MapsId,
                                                            mapsXapixFeature.MapsCredentialsId, mapsXapixFeature.MapFeaturesId, radiusData,
                                                            ex.Message, ex.StackTrace, countryId, attractionId, url, true, attractionTravelStepsId);

                        if (ex.Message == "The remote server returned an error: (429) Too Many Requests.")
                        {
                            Thread.Sleep(1000 * 60);
                        }
                    }
                }
            }
        }