Beispiel #1
0
        public void SaveCountriesAndCities()
        {
            this.log.Debug("Places parsing started");

            IVkDataProvider  vkDataProvider = this.vkConnectionBuilder.GetVkDataProvider();
            CountriesReponse countries      = vkDataProvider.GetCountries();

            this.SaveCountries(countries);
            this.log.Debug("Countries are saved");

            int offset = 0;

            while (true)
            {
                CitiesReponse cities = vkDataProvider.GetCities(offset);
                this.SaveCities(cities);

                if (cities != null && cities.city != null && cities.city.Length > 0 && this.NonEmptyTitleExists(cities))
                {
                    offset += cities.city.Length;
                }
                else
                {
                    break;
                }
            }

            this.log.Debug("Places parsing finished");
        }
Beispiel #2
0
        private void SaveCities(CitiesReponse cities)
        {
            if (cities == null || cities.city == null || cities.city.Length <= 0)
            {
                return;
            }

            foreach (var c in cities.city)
            {
                City city = new City
                {
                    VkId  = c.cid,
                    Title = c.name
                };

                this.placeRepository.Save(city);
            }
        }
Beispiel #3
0
 private bool NonEmptyTitleExists(CitiesReponse cities)
 {
     return(cities.city.Any(city => !string.IsNullOrWhiteSpace(city.name)));
 }