Exemple #1
0
        /// <summary>
        /// This method gets the tidal data of
        /// a given location in a given period of time
        /// </summary>
        /// <param name="input"></param>
        /// <returns>tidal data</returns>
        public MarineWeather GetMarineWeather(MarineWeatherInput input)
        {
            /* Create URL based on input paramters */
            string apiURL = ApiBaseURL + "marine.ashx?q=" + input.query + "&format=" + input.format + "&fx=" + input.fx + "&callback=" + input.callback + "&key=" + APIKey;

            /*Get the web response*/
            string result = RequestHandler.Process(apiURL);

            /*Serialize the json output and parse in the helper class*/
            MarineWeather mWeather = (MarineWeather) new JavaScriptSerializer().Deserialize(result, typeof(MarineWeather));

            return(mWeather);
        }
        /// <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();
            }
        }
Exemple #4
0
        public void Test_TidalDataMethod()
        {
            MarineWeatherInput input = new MarineWeatherInput();

            Assert.IsNull(input.format);
        }