Esempio n. 1
0
        public WeatherModel convertData(WeatherJsonModel.Root rootModel)
        {
            WeatherModel model = new WeatherModel();

            model.City               = rootModel.name;
            model.Country            = rootModel.sys.country;
            model.CurrentTemperature = rootModel.main.temp - 272.15;

            List <WeatherJsonModel.weather> tempList = rootModel.weather;

            foreach (var i in tempList)
            {
                // model.Description = i.description;
                model.Description = i.main;
            }

            model.Humidity  = rootModel.main.humidity;
            model.Pressure  = rootModel.main.pressure;
            model.WindSpeed = rootModel.wind.speed;
            //TODO - calculate direction from the angle
            model.WindAngle = rootModel.wind.deg;
            model.Sunrise   = UnixTimeStampToDateTime(rootModel.sys.sunrise);
            model.Sunset    = UnixTimeStampToDateTime(rootModel.sys.sunset);

            return(model);
        }
Esempio n. 2
0
        private void getWeatherButton_Clicked(object sender, EventArgs e)
        {
            WeatherClass weatherClass = new WeatherClass();

            WeatherJsonModel.Root jsonData = weatherClass.getWeatherData(entrys[0].Text);
            WeatherModel          model    = weatherClass.convertData(jsonData);

            labels[0].Text = model.CurrentTemperature.ToString() + " ºC" + " now";
            labels[1].Text = model.Description;
            labels[2].Text = model.WindSpeed.ToString() + " from " + model.WindAngle.ToString();
            labels[3].Text = model.Pressure.ToString() + " pA";
            labels[4].Text = model.Humidity.ToString() + " %";
            labels[5].Text = model.Sunrise.ToString();
        }
Esempio n. 3
0
        // TEST -> http://api.openweathermap.org/data/2.5/weather?q=Lisbon&APPID=3cfe7ad7612a67aaecfada45e053e034

        public WeatherJsonModel.Root getWeatherData(string cityName)
        {
            using (WebClient web = new WebClient())
            {
                string url = API_CALL + cityName + "&APPID=3cfe7ad7612a67aaecfada45e053e034";

                //TODO - Try Catch when city/country name doesn't exist
                var json = web.DownloadString(url);


                var result = JsonConvert.DeserializeObject <WeatherJsonModel.Root>(json);
                WeatherJsonModel.Root output = result;

                return(output);
            }
        }