예제 #1
0
        public async Task <IEnumerable <City> > GetAll()
        {
            HttpClient client = CityManager.GetClient();

            List <City> cities = new List <City>();

            string result = await client.GetStringAsync(Url);

            var citySearch = JsonConvert.DeserializeObject <CitySearchResult.Rootobject>(result);

            foreach (var item in citySearch._embedded.citysearchresults)
            {
                var shortName = item.matching_full_name.Substring(0, item.matching_full_name.IndexOf(','));

                cities.Add(new City {
                    Name      = item.matching_full_name,
                    ShortName = shortName,
                    //BasicInfo = basicInfo,
                    //DetailedInfo = !string.IsNullOrEmpty(urbanAreaLink) ?
                    //    await GetDetailedInfo(client, urbanAreaLink) : null,
                    BasicsUrl = item._links.cityitem.href,
                });

                //await InitCity(cities.Last());
            }

            return(cities);
        }
예제 #2
0
        public static async Task InitCity(City city)
        {
            CityManager.GetClient();

            city.BasicInfo = await CityManager.GetBasicInfo(CityManager.client, city.BasicsUrl);

            city.DetailsUrl = city.BasicInfo._links.cityurban_area == null ? null :
                              string.Concat(city.BasicInfo._links.cityurban_area.href, "scores/");

            var imagesUrl = city.BasicInfo._links.cityurban_area == null ? null :
                            string.Concat(city.BasicInfo._links.cityurban_area.href, "images/");

            if (city.DetailsUrl != null)
            {
                city.DetailedInfo = await CityManager.GetDetailedInfo(CityManager.client, city.DetailsUrl);
            }

            city.ImageUrl = imagesUrl == null ? null : await CityManager.GetImage(CityManager.client, imagesUrl);
        }