private SiteWeatherForecast ParserWeatherData(string response) { var jsonData = JObject.Parse(response); if (jsonData == null) { return(new SiteWeatherForecast(Name, "Response is not a Json file")); } var forecasts = new List <CityWeatherForecast>(); var currentWeatherData = jsonData["data"]["timelines"][0]["intervals"]; foreach (var day in currentWeatherData) { var values = day["values"]; var celsiusTemperature = values["temperature"].ToString(); var humidity = "No data"; var cloudCover = values["cloudCover"].ToString(); var windSpeed = values["windSpeed"].ToString(); var windDirection = values["windDirection"].ToString(); var newDay = new CityWeatherForecast(celsiusTemperature, cloudCover, humidity, windDirection, windSpeed); forecasts.Add(newDay); } return(new SiteWeatherForecast(Name, "No errors", forecasts)); }
private SiteWeatherForecast ParserWeatherData(string response) { var jsonData = JObject.Parse(response); if (jsonData == null) { return(new SiteWeatherForecast(Name, "Response is not a Json file")); } var forecasts = new List <CityWeatherForecast>(); var currentWeatherData = jsonData["hours"]; var counter = Parameter == WeatherParameter.Current ? 1 : 24; for (int i = 0; i < currentWeatherData.Count(); i += counter) { var day = currentWeatherData[i]; var celsiusTemperature = day["airTemperature"]["noaa"].ToString(); var humidity = day["humidity"]["noaa"].ToString(); var cloudCover = day["cloudCover"]["noaa"].ToString(); var windSpeed = day["windSpeed"]["noaa"].ToString(); var windDirection = day["windDirection"]["noaa"].ToString(); var newDay = new CityWeatherForecast(celsiusTemperature, cloudCover, humidity, windDirection, windSpeed); forecasts.Add(newDay); } return(new SiteWeatherForecast(Name, "No errors", forecasts)); }
private void Initialize() { forecasts = new List <SiteWeatherForecast>(); currentForecast = new CityWeatherForecast("Not Stated", "Not Stated", "Not Stated", "Not Stated", "Not Stated"); currentSite = String.Empty; currentParameter = WeatherParameter.Current; updateSites = true; }
private void ChangeAllValues(CityWeatherForecast forecast) { currentForecast.CelsiusTemperature = forecast.CelsiusTemperature; currentForecast.FahrenheitTemperature = forecast.FahrenheitTemperature; currentForecast.CloudCover = forecast.CloudCover; currentForecast.Humidity = forecast.Humidity; currentForecast.WindDirection = forecast.WindDirection; currentForecast.WindSpeed = forecast.WindSpeed; }
private SiteWeatherForecast ParserWeatherData(string response) { var jsonData = JObject.Parse(response); if (jsonData == null) { return(new SiteWeatherForecast(Name, "Site is down"));; } var forecasts = new List <CityWeatherForecast>(); JToken currentWeatherData; if (Parameter == WeatherParameter.Current) { currentWeatherData = jsonData["current"]; var celsiusTemperature = currentWeatherData["temp"].ToString(); var humidity = currentWeatherData["humidity"].ToString(); var cloudCover = currentWeatherData["clouds"].ToString(); var windSpeed = currentWeatherData["wind_speed"].ToString(); var windDirection = currentWeatherData["wind_deg"].ToString(); var newDay = new CityWeatherForecast(celsiusTemperature, cloudCover, humidity, windDirection, windSpeed); forecasts.Add(newDay); return(new SiteWeatherForecast(Name, "No errors", forecasts)); } else { currentWeatherData = jsonData["daily"]; } int counter = 0; foreach (var day in currentWeatherData) { var celsiusTemperature = day["temp"]["day"].ToString(); var humidity = day["humidity"].ToString(); var cloudCover = day["clouds"].ToString(); var windSpeed = day["wind_speed"].ToString(); var windDirection = day["wind_deg"].ToString(); var newDay = new CityWeatherForecast(celsiusTemperature, cloudCover, humidity, windDirection, windSpeed); forecasts.Add(newDay); counter++; if (counter == 7) { break; } } return(new SiteWeatherForecast(Name, "No errors", forecasts)); }
private GroupBox GetDayGroupBox(CityWeatherForecast forecast, DateTime day) { var groupBox = new GroupBox(); groupBox.Text = day.ToString("d"); groupBox.AutoSize = true; groupBox.AutoSizeMode = AutoSizeMode.GrowAndShrink; groupBox.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right; // additional settings groupBox.TabIndex = 1; groupBox.TabStop = false; // string[] infoArray = new string[12] { "Celsius Temperature:", forecast.CelsiusTemperature, "Fahrenheit Temperature:", forecast.FahrenheitTemperature, "Humidity:", forecast.Humidity, "Cloud Cover:", forecast.CloudCover, "Wind Speed:", forecast.WindSpeed, "Wind Direction: ", forecast.WindDirection }; for (int i = 0; i < 6; i++) { var firstLabel = new Label(); firstLabel.AutoSize = true; firstLabel.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right; firstLabel.Location = new Point(5, (i + 1) * 15); firstLabel.Text = infoArray[i * 2]; groupBox.Controls.Add(firstLabel); var secondLabel = new Label(); var source = new BindingSource(); source.DataSource = typeof(CityWeatherForecast); // binding source to label secondLabel.DataBindings.Add(new Binding("Text", source, infoArray[i * 2].Replace(" ", "").Replace(":", ""), true, DataSourceUpdateMode.OnPropertyChanged)); source.Add(forecast); secondLabel.AutoSize = true; secondLabel.Anchor = ((AnchorStyles.Top | AnchorStyles.Bottom) | AnchorStyles.Left) | AnchorStyles.Right; secondLabel.Location = new Point(firstLabel.Location.X + firstLabel.Size.Width, firstLabel.Location.Y); secondLabel.Text = infoArray[(i + 1) * 2 - 1]; groupBox.Controls.Add(secondLabel); } return(groupBox); }