/// <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 event handler method calls /// the ProcessHistoricalData method of the ProcessorClass class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DisplayHistoricalDataButton_Click(object sender, EventArgs e) { //ProcessorClass.ProcessHistoricalData(); try { String location = SearchTextBox.Text.ToString(); PastWeatherInput input = new PastWeatherInput(); input.query = location; input.date = "2013-03-01"; input.enddate = "2018-03-03"; input.format = "JSON"; /* Call the GetPastWeather method and pass in input parameters*/ API_Implementation api = new API_Implementation(); PastWeather pastWeather = api.GetPastWeather(input); /*Display Results*/ DisplayResultsTextBox.Text = "\r\n Date: " + pastWeather.data.weather[0].date; DisplayResultsTextBox.Text += "\r\n Max Temp(C): " + pastWeather.data.weather[0].maxtempC; DisplayResultsTextBox.Text += "\r\n Max Temp(F): " + pastWeather.data.weather[0].maxtempF; DisplayResultsTextBox.Text += "\r\n Min Temp(C): " + pastWeather.data.weather[0].mintempC; DisplayResultsTextBox.Text += "\r\n Min Temp(F): " + pastWeather.data.weather[0].mintempF; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + pastWeather.data.weather[0].hourly[0].cloudcover; DisplayResultsTextBox.Text += "\r\n Humidity: " + pastWeather.data.weather[0].hourly[0].humidity; DisplayResultsTextBox.Text += "\r\n Pressure: " + pastWeather.data.weather[0].hourly[0].pressure; DisplayResultsTextBox.Text += "\r\n Visibility: " + pastWeather.data.weather[0].hourly[0].visibility; DisplayResultsTextBox.Text += "\r\n Wind Speed: " + pastWeather.data.weather[0].hourly[0].windspeedMiles; } catch (Exception ex) { ex.GetBaseException(); } }
/// <summary> /// This event handler method calls /// the ProcessLocation method of the ProcessorClass class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SearchLocationButton_Click(object sender, EventArgs e) { //ProcessorClass.ProcessSearchLocation(); try { String results = NoOfDaysDropDownList.SelectedValue.ToString(); String Format = "JSON"; /*Set input parameters for the API*/ LocationSearchInput input = new LocationSearchInput(); input.query = SearchTextBox.Text; input.num_of_results = results; input.format = Format; /* Call the SearchLocation method and pass in the input parameters*/ API_Implementation api = new API_Implementation(); LocationSearch locationSearch = api.SearchLocation(input); /*Display Results*/ DisplayResultsTextBox.Text = "\r\n Area Name: " + locationSearch.search_API.result[0].areaName[0].value; DisplayResultsTextBox.Text += "\r\n Country: " + locationSearch.search_API.result[0].country[0].value; DisplayResultsTextBox.Text += "\r\n Latitude: " + locationSearch.search_API.result[0].latitude; DisplayResultsTextBox.Text += "\r\n Longitude: " + locationSearch.search_API.result[0].longitude; DisplayResultsTextBox.Text += "\r\n Population: " + locationSearch.search_API.result[0].population; DisplayResultsTextBox.Text += "\r\n Region: " + locationSearch.search_API.result[0].region[0].value; } 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 method consumes the WorldWeather Premium API /// to show past weather data of any given location /// for a given period /// </summary> public void GetHistoricalData() { try { String location = SearchTextBox.Text.ToString(); PastWeatherInput input = new PastWeatherInput(); input.query = location; input.date = "2017-01-01"; input.enddate = "2019-01-01"; input.format = "JSON"; /* Call the GetPastWeather method and pass in input parameters*/ API_Implementation api = new API_Implementation(); PastWeather pastWeather = api.GetPastWeather(input); /*Display Results*/ DisplayResultsTextBox.Text = "\r\n Date: " + pastWeather.data.weather[0].date; DisplayResultsTextBox.Text += "\r\n Max Temp(C): " + pastWeather.data.weather[0].maxtempC; DisplayResultsTextBox.Text += "\r\n Max Temp(F): " + pastWeather.data.weather[0].maxtempF; DisplayResultsTextBox.Text += "\r\n Min Temp(C): " + pastWeather.data.weather[0].mintempC; DisplayResultsTextBox.Text += "\r\n Min Temp(F): " + pastWeather.data.weather[0].mintempF; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + pastWeather.data.weather[0].hourly[0].cloudcover; } 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); }
/// <summary> /// This method consumes the World Weather /// Premium API to show location TimeZone in JSON Format /// </summary> public void GetTimeZone() { try { /* Set input parameters for the API */ String Format = "JSON"; TimeZoneInput input = new TimeZoneInput(); input.query = SearchTextBox.Text; input.format = Format; /* Call GetTimeZone method with input parameters */ API_Implementation api = new API_Implementation(); Timezone timeZone = api.GetTimeZone(input); /*Display Results*/ DisplayResultsTextBox.Text = "\r\n Local Time: " + timeZone.data.time_zone[0].localtime; DisplayResultsTextBox.Text += "\r\n Time Offset: " + timeZone.data.time_zone[0].utcOffset; } catch (Exception ex) { ex.GetBaseException(); } }
/// <summary> /// This method consumes the World Weather /// PremiumAPI to show marine data in JSON format, /// and display results in a Textbox /// </summary> public void GetTidalData() { try { /* Set input parameters for the API */ MarineWeatherInput input = new MarineWeatherInput(); input.query = "45,-2"; input.format = "JSON"; /* Call GetMarineWeather() method with input parameters */ API_Implementation api = new API_Implementation(); MarineWeather marineWeather = api.GetMarineWeather(input); /* Display Results */ DisplayResultsTextBox.Text = "\r\n Date: " + marineWeather.data.weather[0].date; DisplayResultsTextBox.Text += "\r\n Min Temp (c): " + marineWeather.data.weather[0].mintempC; DisplayResultsTextBox.Text += "\r\n Max Temp (c): " + marineWeather.data.weather[0].maxtempC; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + marineWeather.data.weather[0].hourly[0].cloudcover; } catch (Exception ex) { ex.GetBaseException(); } }
/// <summary> /// This event handler method calls /// the ProcessTidalData method of the ProcessorClass class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DisplayTidalDataButton_Click(object sender, EventArgs e) { // ProcessorClass.ProcessTidalData(); try { /* Set input parameters for the API */ MarineWeatherInput input = new MarineWeatherInput(); input.query = "45,-2"; input.format = "JSON"; /* Call GetMarineWeather() method with input parameters */ API_Implementation api = new API_Implementation(); MarineWeather marineWeather = api.GetMarineWeather(input); /* Display Results */ DisplayResultsTextBox.Text = "\r\n Date: " + marineWeather.data.weather[0].date; DisplayResultsTextBox.Text += "\r\n Min Temp (c): " + marineWeather.data.weather[0].mintempC; DisplayResultsTextBox.Text += "\r\n Max Temp (c): " + marineWeather.data.weather[0].maxtempC; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + marineWeather.data.weather[0].hourly[0].cloudcover; DisplayResultsTextBox.Text += "\r\n Cloud Cover: " + marineWeather.data.weather[0].hourly[0].swellDir16Point; DisplayResultsTextBox.Text += "\r\n Swell Height: " + marineWeather.data.weather[0].hourly[0].swellHeight_m; DisplayResultsTextBox.Text += "\r\n Swell Direction: " + marineWeather.data.weather[0].hourly[0].swellDir; DisplayResultsTextBox.Text += "\r\n Humidity: " + marineWeather.data.weather[0].hourly[0].humidity; DisplayResultsTextBox.Text += "\r\n Pressure: " + marineWeather.data.weather[0].hourly[0].pressure; DisplayResultsTextBox.Text += "\r\n Visibility: " + marineWeather.data.weather[0].hourly[0].visibility; DisplayResultsTextBox.Text += "\r\n Wind Speed: " + marineWeather.data.weather[0].hourly[0].windspeedMiles; DisplayResultsTextBox.Text += "\r\n Water Temp: " + marineWeather.data.weather[0].hourly[0].waterTemp_C; DisplayResultsTextBox.Text += "\r\n Sunrise: " + marineWeather.data.weather[0].astronomy[0].sunrise; DisplayResultsTextBox.Text += "\r\n Sunset: " + marineWeather.data.weather[0].astronomy[0].sunset; DisplayResultsTextBox.Text += "\r\n Moonrise: " + marineWeather.data.weather[0].astronomy[0].moonrise; DisplayResultsTextBox.Text += "\r\n Moonset: " + marineWeather.data.weather[0].astronomy[0].moonset; } catch (Exception ex) { ex.GetBaseException(); } }
public void TestBaseURLMethod() { API_Implementation api = new API_Implementation(); Assert.IsNull(api.ApiBaseURL); }
public void TestAPIKeyMethod() { API_Implementation api = new API_Implementation(); Assert.IsNull(api.APIKey); }