/// <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();
            }
        }
        private WeatherData GetInfo()
        {
            PastWeather pastWeather = null;
            WeatherData data        = new WeatherData();
            // set input parameters for the API
            LocalWeatherInput input = new LocalWeatherInput();

            input.query       = m_info_future.query;
            input.num_of_days = m_info_future.num_of_days;
            input.date        = m_info_future.date;
            input.format      = "JSON";

            // call the local weather method with input parameters
            OpenWeatherAPI api          = new OpenWeatherAPI();
            LocalWeather   localWeather = api.GetLocalWeather(input);


            //set data in datastore based on which kind of datastore refresh was requested
            if (m_reftype == RefreshType.AddLeft)
            {
                DataStore.Instance().AddLeft(pastWeather);
            }
            else if (m_reftype == RefreshType.AddLeft)
            {
                DataStore.Instance().AddRight(localWeather);
            }
            else
            {
                DataStore.Instance().SetWeather(localWeather, pastWeather);
            }

            return(data);
        }
        /// <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);
 }
Esempio n. 5
0
        /// <summary>
        /// This method gets local weather condition
        /// </summary>
        /// <param name="input"></param>
        /// <returns>local weather</returns>
        public LocalWeather GetLocalWeather(LocalWeatherInput input)
        {
            /*Create URL based on input paramters*/
            string apiURL = ApiBaseURL + "weather.ashx?q=" + input.query + "&format=" + input.format + "&extra=" + input.extra + "&num_of_days=" + input.num_of_days + "&date=" + input.date + "&fx=" + input.fx + "&cc=" + input.cc + "&includelocation=" + input.includelocation + "&show_comments=" + input.show_comments + "&callback=" + input.callback + "&key=" + APIKey;

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

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

            return(lWeather);
        }
Esempio n. 6
0
        public LocalWeather GetLocalWeather(LocalWeatherInput input)
        {
            string url = ConfigurationManager.AppSettings["OWAurl"];
            string key = ConfigurationManager.AppSettings["OWAKey"];

            if (url == null || url == "")
            {
                url = WeatherModel.Resource1.owapiurl;
            }
            if (key == null || key == "")
            {
                key = WeatherModel.Resource1.owakey;
            }
            // create URL based on input paramters
            string apiURL = url + "&q=" + input.query + "&appid=" + key;

            // get the web response
            string result = new RequestHandler(apiURL).Process();


            // deserialize the json output into the c#classes created earlier
            RootObject lWeather = null;

            try
            {
                //lWeather = (LocalWeather)new JavaScriptSerializer().Deserialize(result, typeof(LocalWeather));
                lWeather = (RootObject) new JavaScriptSerializer().Deserialize(result, typeof(RootObject));
            }
            catch (ArgumentNullException ex)
            {
                m_error = ex.Message;
            }
            catch (FormatException ex)
            {
                m_error = ex.Message;
            }
            //LocalWeather lWeather = Newtonsoft.Json.JsonConvert.DeserializeObject<LocalWeather>(result);
            return(Adapt(lWeather));
        }
        public LocalWeather GetLocalWeather(LocalWeatherInput input)
        {
            // create URL based on input paramters
            string apiURL = ApiBaseURL + "weather.ashx?q=" + input.query + "&format=" + input.format + "&extra=" + input.extra + "&num_of_days=" + input.num_of_days + "&date=" + input.date + "&fx=" + input.fx + "&cc=" + input.cc + "&includelocation=" + input.includelocation + "&show_comments=" + input.show_comments + "&callback=" + input.callback + "&key=" + PremiumAPIKey;
            // get the web response
            string result = new RequestHandler(apiURL).Process();

            // deserialize the json output into the c#classes created earlier
            LocalWeather lWeather = null;

            if (result != null)
            {
                result = result.Replace("No moonset", "11:47 AM");
            }
            try
            {
                lWeather = (LocalWeather) new JavaScriptSerializer().Deserialize(result, typeof(LocalWeather));
            }
            catch (FormatException ex)
            {
            }
            //LocalWeather lWeather = Newtonsoft.Json.JsonConvert.DeserializeObject<LocalWeather>(result);
            return(lWeather);
        }
Esempio n. 8
0
        public void Test_LocalWeatherMethod()
        {
            LocalWeatherInput input = new LocalWeatherInput();

            Assert.IsNull(input.num_of_days);
        }