public MainPage() { var api = new WeatherAPI(); var pageService = new PageService(); ViewModel = new WeatherPageViewModel(api, pageService); InitializeComponent(); }
} //날씨 public void CheckWeather() { WeatherAPI DataAPI = new WeatherAPI(Lang, Lon); weather = DataAPI.GetWeather(); city = DataAPI.GetCity(); temp = DataAPI.GetTemp(); windSpeed = DataAPI.GetWindSpeed(); windDirectionName = DataAPI.GetWindDirectionName(); windDirectionValue = DataAPI.GetWindDirectionValue(); humidity = DataAPI.GetHumidity(); }
private async void GetTimes() { WeatherAPI weatherApi = new WeatherAPI(); await weatherApi.GetCurrentWeatherAPI(cityName, unit); var data = JsonConvert.DeserializeObject <WeatherData>(weatherApi.responseString); DateTime sunrise = Sys.ConvertDateTime(data.Sys.Sunrise); DateTime sunset = Sys.ConvertDateTime(data.Sys.Sunset); todaysDate.Text = DateTime.Now.ToShortDateString(); sunriseTime.Text = sunrise.ToShortTimeString(); sunsetTime.Text = sunset.ToShortTimeString(); }
private async void GetForecast() { WeatherAPI weatherApi = new WeatherAPI(); await weatherApi.GetForecastAPI(cityName, unit); var data = JsonConvert.DeserializeObject <ForecastData>(weatherApi.forecastResponseString); foreach (var i in data.List) { DateTime dateTime = List.GetDate(i.Dt); weather.Add(new Main_ { DtString = dateTime.ToString(), Temp = i.main.Temp, Humidity = i.main.Humidity, Pressure = i.main.Pressure, Sea_Level = i.main.Sea_Level, Grnd_Level = i.main.Grnd_Level }); } }
private async void currentWeatheButton_Clicked(object sender, EventArgs e) { var weather = new WeatherAPI(); var city = enteredCity.Text; OpenWeatherRoot currentWeather = await weather.GetCurrentWeather(city); if (currentWeather != null) { // Gets the correponding image source string imageSource = weather.GetWeatherImage(currentWeather); weatherImage.Source = imageSource; // Changes the text on the corresponding fields currentTempLabel.Text = currentWeather.Main.Temp.ToString(); minTempLabel.Text = currentWeather.Main.Temp_min.ToString(); maxTempLabel.Text = currentWeather.Main.Temp_max.ToString(); currentHumLabel.Text = currentWeather.Main.Humidity.ToString(); } }
// Uses the API class to get the current weather data private async void GetCurrentWeather() { try { WeatherAPI weatherApi = new WeatherAPI(); await weatherApi.GetCurrentWeatherAPI(cityName, unit); var data = JsonConvert.DeserializeObject <WeatherData>(weatherApi.responseString); int curTemp = (int)data.Main.Temp; int curMax = (int)data.Main.Temp_Max; int curMin = (int)data.Main.Temp_Min; int curHum = data.Main.Humidity; int windDeg = data.Wind.Deg; double speed = data.Wind.Speed; temp.Text = curTemp.ToString() + "°"; maxTemp.Text = curMax.ToString() + "°"; minTemp.Text = curMin.ToString() + "°"; humidity.Text = curHum.ToString() + "%"; windSpeed.Text = speed.ToString(); windDirection.Text = WindDirection.GetWindDirection(windDeg); desc.Text = data.Weather[0].Description.ToUpper(); UpdateWeatherIcon(); now = DateTime.Now; LoggingService.Instance.LogSuccess(now, "Connected to API"); } catch { now = DateTime.Now; LoggingService.Instance.LogCatastrophicError(now, "Can't connect to API!"); ContentDialog noConnection = new ContentDialog { Title = "Can't Connect to API", Content = "Check your connection and try again.", CloseButtonText = "Ok" }; ContentDialogResult result = await noConnection.ShowAsync(); } }
public WheatherPage() { this.InitializeComponent(); canvasControl.Draw += CanvasControl_Draw1; canvasControl.Invalidate(); Window.Current.VisibilityChanged += Current_VisibilityChanged; canvasWidth(); canvasHeight(); rand = new Random(); sun = new Sun(0, 0, 44, 12); moon = new Moon(150, 75, 44); precip = new Precipitation(cloudHeight * k, 500, 1600); tempType = localSettings.Values["tempType"] != null ? localSettings.Values["tempType"].ToString() : "c"; windType = localSettings.Values["windType"] != null ? localSettings.Values["windType"].ToString() : "kph"; presType = localSettings.Values["presType"] != null ? localSettings.Values["presType"].ToString() : "mb"; precipType = localSettings.Values["precipType"] != null ? localSettings.Values["precipType"].ToString() : "mm"; visType = localSettings.Values["visType"] != null ? localSettings.Values["visType"].ToString() : "km"; days = localSettings.Values["days"] != null?Convert.ToInt32(localSettings.Values["days"].ToString()) : 5; cityName = localSettings.Values["cityName"] != null ? localSettings.Values["cityName"].ToString() : "kiev"; weatherAPI = new WeatherAPI(cityName, days); try { respond = weatherAPI.getRespond(); allWeather = JsonConvert.DeserializeObject <AllWeather>(respond); JObject respondObject = JObject.Parse(respond); IList <JToken> respondForecastList = respondObject["forecast"]["forecastday"].Children().ToList(); forecastDays = new ObservableCollection <ForecastDay>(); foreach (JToken respondForecast in respondForecastList) { ForecastDay forecastDay = respondForecast.ToObject <ForecastDay>(); forecastDay.makeFormatedDate(); forecastDays.Add(forecastDay); } ; foreach (ForecastDay item in forecastDays) { SelectedForecastDay SelectedforecastDay = new SelectedForecastDay( item.dateFormated, getNeedProperty <Day>("maxtemp_", tempType, item.day) + "° ", getNeedProperty <Day>("mintemp_", tempType, item.day) + "° ", getNeedProperty <Day>("avgtemp_", tempType, item.day) + "° " + tempType.ToUpper(), getNeedProperty <Day>("maxwind_", windType, item.day) + " " + windType, getNeedProperty <Day>("totalprecip_", precipType, item.day) + " " + precipType, getNeedProperty <Day>("avgvis_", visType, item.day) + "° " + visType, item.day.avghumidity + "%", item.day.condition.text, "ms-appx:///Assets/weather/" + item.day.condition.icon.Substring(30), item.day.condition.code + "", item.astro.moonset, item.astro.moonrise, item.astro.sunrise, item.astro.sunset); _forecastDays.Add(SelectedforecastDay); } location.Text = allWeather.location.name + ", " + allWeather.location.country; currentTempreture.Text = getNeedProperty <CurrentWeather>("temp_", tempType, allWeather.current) + "° " + tempType; currentDate.Text = DateTime.Now.ToString("ddd d", new CultureInfo("en-US")); currentCondition.Text = allWeather.current.condition.text; currentWind.Text = "Wind" + getNeedProperty <CurrentWeather>("wind_", windType, allWeather.current) + " " + windType + " " + allWeather.current.wind_dir; currentPresure.Text = "Presure " + getNeedProperty <CurrentWeather>("pressure_", presType, allWeather.current) + " " + presType; currentHumidity.Text = "Humidity " + allWeather.current.humidity + "%" + " " + getNeedProperty <CurrentWeather>("precip_", precipType, allWeather.current) + " " + precipType; currentTempFeelslike.Text = "Feelslike " + getNeedProperty <CurrentWeather>("feelslike_", tempType, allWeather.current) + "° " + tempType; currentVis.Text = "Visibility " + getNeedProperty <CurrentWeather>("vis_", visType, allWeather.current) + " " + visType; conditionsString = weatherAPI.getConditions(); conditions2 = new ObservableCollection <Condition>(JsonConvert.DeserializeObject <List <Condition> >(conditionsString)); foreach (Condition cond in JsonConvert.DeserializeObject <List <Condition> >(conditionsString)) { conditionPicker.Items.Add(cond.night); } conditionPicker.SelectedItem = allWeather.current.condition.text; } catch (Exception ex) { Debug.WriteLine(ex); } getFrequency(); clouds = new List <Cloud>(); width = 1700; float x = width / frequency; for (float i = 0; i < frequency; i++) { var cl = new Cloud(x / 2 + i * x, cloudHeight * k + random(-1 * (cloudHeight * k) / 2, (cloudHeight * k) / 1.5f), (int)random(4, 12), cloudHeight, 0); clouds.Add(cl); } moveTimer.Interval = new TimeSpan(1); moveTimer.Tick += MoveTimer_Tick; moveTimer.Start(); }