Exemple #1
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            if (!string.IsNullOrWhiteSpace(ville.Text))
            {
                WeatherDATA weatherData = await _restService.GetWeatherDataAsync(GenerateRequestUri(MainPage.OpenWeatherMapEndpoint));

                BindingContext = weatherData;
            }
        }
Exemple #2
0
        public async Task <WeatherDATA> GetWeatherDataAsync(string uri)
        {
            WeatherDATA weatherData = null;

            try
            {
                HttpResponseMessage response = await _client.GetAsync(uri);

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

                    weatherData = JsonConvert.DeserializeObject <WeatherDATA>(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }

            return(weatherData);
        }