예제 #1
0
        public async void Init(string id, string city, string country)
        {
            CurrentWeather = await MSC.BlazXam.BizLogic.HTTPClientService.GetAccuWeatherCurrentConditionsDataAsync(id);

            City    = city;
            Country = country;
        }
        public static async Task <AccuWeatherCurrentConditModel> GetAccuWeatherCurrentConditionsDataAsync(string locationId)
        {
            var locData = new AccuWeatherCurrentConditModel();

            try
            {
                HttpClient client = new HttpClient();
                client.MaxResponseContentBufferSize = 256000;
                var urlStr   = $"https://dataservice.accuweather.com/currentconditions/v1/{locationId}?apikey={Config.AccuWeatherKey}&language=en-us&details=false ";
                var uri      = new Uri(urlStr);
                var response = await client.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    var list = JsonConvert.DeserializeObject <List <AccuWeatherCurrentConditModel> >(content);
                    if (list.Count == 1)
                    {
                        locData = list[0];
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"ERROR { ex.Message}");
                //TODO: log error here with your favorite logging tool
            }

            return(locData);
        }