コード例 #1
0
        public ForecastDetails GetCurrentWeatherByLocationName(string locationName)
        {
            if (String.IsNullOrEmpty(locationName))
            {
                return(null);
            }

            var externalApiUrl = GetBaseApiUrl()
                                 .SetQueryParams(new
            {
                q = locationName
            });

            try
            {
                var jsonDynamic = externalApiUrl.GetJsonAsync().Result;
                logger.LogInformation($"External weather API returned this result: {jsonDynamic}");
                return(ForecastDetails.ToForecastDetails(jsonDynamic));
            }
            catch (Exception ex)
            {
                logger.LogError($"Exception in GetCurrentWeatherByLocationName: {ex} \nMessage: {ex.Message}");
                return(null);
            }
        }
コード例 #2
0
ファイル: MainViewModel.cs プロジェクト: JakubKus/forecaster
        private void GetForecastDetails(string cityCode = "sb")
        {
            ObservableCollection <ForecastDetails> forecastDetailsCollection = new ObservableCollection <ForecastDetails>();

            forecastDetailsCollection = ForecastDetails.GetForecast(cityCode);
            ForecastDetailsCollection = new ObservableCollection <ForecastDetails>(forecastDetailsCollection);
            RaisePropertyChanged(() => ForecastDetailsCollection);
        }
コード例 #3
0
        public ForecastDetails GetCurrentWeatherByLocationId(int locationId)
        {
            if (locationId < 0)
            {
                return(null);
            }

            var externalApiUrl = GetBaseApiUrl()
                                 .SetQueryParams(new
            {
                id = locationId
            });

            try
            {
                var jsonDynamic = externalApiUrl.GetJsonAsync().Result;
                return(ForecastDetails.ToForecastDetails(jsonDynamic));
            }
            catch (Exception ex)
            {
                logger.LogError($"Exception in GetCurrentWeatherByLocationId: {ex} \nMessage: {ex.Message}");
                return(null);
            }
        }