Exemple #1
0
        // Loads the current weather
        /// <summary>
        /// Loads the current weather.
        /// </summary>
        private async void LoadCurrentWeather()
        {
            mainWindow.LoadCurrentWeather();

            try
            {
                currentWeather = await CurrentWeatherInfoProcessor.LoadCurrentWeather(ReturnCity());
            }
            catch (Exception)
            {
                Console.WriteLine("Exception occurred");
            }

            BitmapImage weatherImage = new BitmapImage();

            weatherImage.BeginInit();
            weatherImage.UriSource = new Uri("images/" + currentWeather.Weather[0].Icon.ToString() + ".png", UriKind.Relative);
            weatherImage.EndInit();

            CurrentWeatherImage.Source = weatherImage;

            CurrentWeatherName.Text = currentWeather.Name;

            CurrentWeatherDescription.Text = currentWeather.Weather[0].Description.ToString();

            CurrentTemperature.Text = "Temperature: " + NormalizationOperations.NormalizeTemperature(currentWeather.Main.Temp).ToString() + " °C";

            CurrentFeelsLikeTemperature.Text = "Apparent temp: " + Math.Round((currentWeather.Main.Feels_like - 273.15), 2).ToString() + " °C";

            CurrentHumidity.Text = "Humidity: " + currentWeather.Main.Humidity.ToString() + " %";

            CurrentPressure.Text = "Pressure: " + currentWeather.Main.Pressure.ToString() + " hPa";

            CurrentWindSpeed.Text = "Wind speed: " + currentWeather.Wind.Speed.ToString() + " m/s";
        }
        // Loads the current weather
        /// <summary>
        /// Loads the current weather
        /// </summary>
        public async void LoadCurrentWeather()
        {
            try
            {
                currentWeather = await CurrentWeatherInfoProcessor.LoadCurrentWeather(ReturnCity());
            }
            catch (Exception)
            {
                Console.WriteLine("Exception occurred");
            }

            if (isCurrentWeatherGood())
            {
                BitmapImage weatherImage = new BitmapImage();
                weatherImage.BeginInit();
                weatherImage.UriSource = new Uri("images/" + currentWeather.Weather[0].Icon.ToString() + ".png", UriKind.Relative);
                weatherImage.EndInit();
                CurrentWeatherImage.Source = weatherImage;
                CurrentWeather.Text        = NormalizationOperations.NormalizeTemperature(currentWeather.Main.Temp).ToString() + "°C";
                Current_data = DateTime.UtcNow.AddSeconds(currentWeather.Timezone);
                RefreshAllDayButtons();
                ShowCurrentDay();
                AddEventToStackPanel();
            }
            else
            {
                CurrentWeather.Text = "API Error";
            }
        }
Exemple #3
0
        // Copies temperature data from ApiLibrary structures to new structures prepared for chart display
        /// <summary>
        /// Copies temperature data from ApiLibrary structures to new structures prepared for chart display.
        /// </summary>
        /// <param name="dailyForecastSource">DailyWeatherInfoModel object containing day temperature information.</param>
        public DailyTemperatureForecast(DailyWeatherInfoModel dailyForecastSource)
        {
            MorningTemperature = new List <TempForecastData>();
            DayTemperature     = new List <TempForecastData>();
            EveningTemperature = new List <TempForecastData>();
            NightTemperature   = new List <TempForecastData>();
            int i = 0;

            foreach (var item in dailyForecastSource.Daily)
            {
                string requiredDate = NormalizationOperations.NormalizeDate(dailyForecastSource.Daily[i].Dt);
                MorningTemperature.Add(new TempForecastData(NormalizationOperations.NormalizeTemperature(dailyForecastSource.Daily[i].Temp.Morn), requiredDate));
                DayTemperature.Add(new TempForecastData(NormalizationOperations.NormalizeTemperature(dailyForecastSource.Daily[i].Temp.Day), requiredDate));
                EveningTemperature.Add(new TempForecastData(NormalizationOperations.NormalizeTemperature(dailyForecastSource.Daily[i].Temp.Eve), requiredDate));
                NightTemperature.Add(new TempForecastData(NormalizationOperations.NormalizeTemperature(dailyForecastSource.Daily[i].Temp.Night), requiredDate));
                i++;
            }
        }
        // Copies daily weather forecast data from ApiLibrary structures to new structures prepared for chart display
        /// <summary>
        /// Copies daily weather forecast data from ApiLibrary structures to new structures prepared for chart display.
        /// </summary>
        /// <param name="dailyForecastSource">DailyWeatherInfoModel object containing daily weather forecast information.</param>
        public DailyWeatherForecast(DailyWeatherInfoModel dailyForecastSource)
        {
            dailyTemperatureForecast         = new DailyTemperatureForecast(dailyForecastSource);
            dailyApparentTemperatureForecast = new DailyApparentTemperatureForecast(dailyForecastSource);

            humidity  = new List <HumidityForecastData>();
            pressure  = new List <PressureForecastData>();
            windSpeed = new List <WindSpeedForecastData>();

            int i = 0;

            foreach (var item in dailyForecastSource.Daily)
            {
                string requiredDate = NormalizationOperations.NormalizeDate(dailyForecastSource.Daily[i].Dt);
                humidity.Add(new HumidityForecastData(dailyForecastSource.Daily[i].Humidity, requiredDate));
                pressure.Add(new PressureForecastData(dailyForecastSource.Daily[i].Pressure, requiredDate));
                windSpeed.Add(new WindSpeedForecastData(dailyForecastSource.Daily[i].Wind_speed, requiredDate));
                i++;
            }
        }
Exemple #5
0
        // Copies hourly weather forecast data from ApiLibrary structures to new structures prepared for chart display
        /// <summary>
        /// Copies hourly weather forecast data from ApiLibrary structures to new structures prepared for chart display.
        /// </summary>
        /// <param name="dailyForecastSource">HourlyWeatherInfoModel object containing hourly weather forecast information.</param>
        public HourlyWeatherForecast(HourlyWeatherInfoModel dailyForecastSource)
        {
            temperature         = new List <TempForecastData>();
            apparentTemperature = new List <TempForecastData>();
            humidity            = new List <HumidityForecastData>();
            pressure            = new List <PressureForecastData>();
            windSpeed           = new List <WindSpeedForecastData>();

            now = DateTime.Now;

            int i = 0;

            foreach (var item in dailyForecastSource.Hourly)
            {
                now = now.AddHours(i);
                string requiredHour = now.Hour.ToString() + ":00";
                temperature.Add(new TempForecastData(NormalizationOperations.NormalizeTemperature(dailyForecastSource.Hourly[i].Temp), requiredHour));
                apparentTemperature.Add(new TempForecastData(NormalizationOperations.NormalizeTemperature(dailyForecastSource.Hourly[i].Feels_like), requiredHour));
                humidity.Add(new HumidityForecastData(dailyForecastSource.Hourly[i].Humidity, requiredHour));
                pressure.Add(new PressureForecastData(dailyForecastSource.Hourly[i].Pressure, requiredHour));
                windSpeed.Add(new WindSpeedForecastData(dailyForecastSource.Hourly[i].Wind_speed, requiredHour));
                i++;
            }
        }