/// <summary> /// This event handler method calls /// the ProcessLocalWeather method of the ProcessorClass class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DisplayWeatherForecastButton_Click(object sender, EventArgs e) { try { /* Set input parameters for the API */ LocalWeatherInput input = new LocalWeatherInput(); input.query = SearchTextBox.Text; input.num_of_days = NoOfDaysDropDownList.SelectedValue.ToString(); input.format = "JSON"; /*Call the LocalWeather method and pass in the input parameters*/ API_Implementation api = new API_Implementation(); LocalWeather localWeather = api.GetLocalWeather(input); /* Display Output */ DisplayResultsTextBox.Text = "\r\n Cloud Cover: " + localWeather.data.current_Condition[0].cloudcover; DisplayResultsTextBox.Text += "\r\n Humidity: " + localWeather.data.current_Condition[0].humidity; DisplayResultsTextBox.Text += "\r\n Temp C: " + localWeather.data.current_Condition[0].temp_C; DisplayResultsTextBox.Text += "\r\n Visibility: " + localWeather.data.current_Condition[0].weatherDesc[0].value; DisplayResultsTextBox.Text += "\r\n Observation Time: " + localWeather.data.current_Condition[0].observation_time; DisplayResultsTextBox.Text += "\r\n Pressure: " + localWeather.data.current_Condition[0].pressure; DisplayResultsTextBox.Text += "\r\n Wind Speed: " + localWeather.data.current_Condition[0].windspeedKmph; DisplayResultsTextBox.Text += "\r\n Wind Direction: " + localWeather.data.current_Condition[0].winddirDegree; DisplayResultsTextBox.Text += "\r\n Precipitation: " + localWeather.data.current_Condition[0].precipMM; DisplayResultsTextBox.Text += "\r\n Chance of Overcast: " + localWeather.data.current_Condition[0].chanceofovercast; DisplayResultsTextBox.Text += "\r\n Chance of Rain: " + localWeather.data.current_Condition[0].chanceofrain; DisplayResultsTextBox.Text += "\r\n Chance of Snow: " + localWeather.data.current_Condition[0].chanceofsnow; DisplayResultsTextBox.Text += "\r\n Chance of Sunny: " + localWeather.data.current_Condition[0].chanceofsunny; DisplayResultsTextBox.Text += "\r\n Chance of Thunder: " + localWeather.data.current_Condition[0].chanceofthunder; } catch (Exception ex) { ex.GetBaseException(); } }
/// <summary> /// This method consumes the API to display local weather /// </summary> public void Get_LocalWeather() { try { /* Set input parameters for the API */ LocalWeatherInput input = new LocalWeatherInput(); input.query = Constants.query; input.num_of_days = Constants.Days; input.format = Constants.Format; /*Call the LocalWeather method and pass in the input parameters*/ API_Implementation api = new API_Implementation(); LocalWeather localWeather = api.GetLocalWeather(input); /* Display Output */ DisplayResultsTextBox.Text = "\r\n Cloud Cover: " + localWeather.data.current_Condition[0].cloudcover; DisplayResultsTextBox.Text += "\r\n Humidity: " + localWeather.data.current_Condition[0].humidity; DisplayResultsTextBox.Text += "\r\n Temp C: " + localWeather.data.current_Condition[0].temp_C; DisplayResultsTextBox.Text += "\r\n Visibility: " + localWeather.data.current_Condition[0].weatherDesc[0].value; DisplayResultsTextBox.Text += "\r\n Observation Time: " + localWeather.data.current_Condition[0].observation_time; DisplayResultsTextBox.Text += "\r\n Pressue: " + localWeather.data.current_Condition[0].pressure; } catch (Exception ex) { ex.GetBaseException(); } }
/// <summary> /// This Constructor initializes the global variables /// </summary> public Constants() { query = SearchTextBox.Text.ToString(); Format = "JSON"; Days = NoOfDaysDropDownList.SelectedValue.ToString(); Results = NoOfDaysDropDownList.SelectedValue.ToString(); input = new LocalWeatherInput(); api = new API_Implementation(); localWeather = api.GetLocalWeather(input); }