Esempio n. 1
0
        public FiveDays.RootObject ExecuteFiveDayRequest()
        {
            var client = new RestClient(url);

            response = client.Execute(request);

            FiveDays.RootObject objRoot = new FiveDays.RootObject();
            objRoot = JsonConvert.DeserializeObject <FiveDays.RootObject> (response.Content);

            return(objRoot);
        }
Esempio n. 2
0
        public void RefreshWeather(int index)
        {
            try
            {
                objRest = new RESTHandler(@"http://api.openweathermap.org/data/2.5/weather");

                objRest.AddParameter("q", CityList[index] + ",nz");
                objRest.AddParameter("APPID", "e6f3cfaed833707ec118cc388affc215");
                objRest.AddParameter("mode", "json");
                objRest.AddParameter("units", "metric");

                objRootList = objRest.ExecuteOneDayRequest();

                txtTemperature.Text  = Math.Round(objRootList.main.temp, 2).ToString() + "°C";
                Humidity.Text        = objRootList.main.humidity.ToString() + "%";
                Day1Description.Text = objRootList.weather[0].description;
                Day1MinTemp.Text     = Math.Round(objRootList.main.temp_min, 2).ToString() + "°C";
                Day1MaxTemp.Text     = Math.Round(objRootList.main.temp_max, 2).ToString() + "°C";

                objRest = new RESTHandler(@"http://api.openweathermap.org/data/2.5/forecast/daily?");

                objRest.AddParameter("q", CityList[index] + ",nz");
                objRest.AddParameter("cnt", "5");
                objRest.AddParameter("APPID", "e6f3cfaed833707ec118cc388affc215");
                objRest.AddParameter("mode", "json");
                objRest.AddParameter("units", "metric");

                objFiveDayList = objRest.ExecuteFiveDayRequest();

                Day2Description.Text = objFiveDayList.list[0].weather[0].description;
                Day3Description.Text = objFiveDayList.list[1].weather[0].description;
                Day4Description.Text = objFiveDayList.list[2].weather[0].description;
                Day5Description.Text = objFiveDayList.list[3].weather[0].description;

                Day2MinTemp.Text = objFiveDayList.list[0].temp.min.ToString() + "°C";
                Day3MinTemp.Text = objFiveDayList.list[1].temp.min.ToString() + "°C";
                Day4MinTemp.Text = objFiveDayList.list[2].temp.min.ToString() + "°C";
                Day5MinTemp.Text = objFiveDayList.list[3].temp.min.ToString() + "°C";

                Day2MaxTemp.Text = objFiveDayList.list[0].temp.max.ToString() + "°C";
                Day3MaxTemp.Text = objFiveDayList.list[1].temp.max.ToString() + "°C";
                Day4MaxTemp.Text = objFiveDayList.list[2].temp.max.ToString() + "°C";
                Day5MaxTemp.Text = objFiveDayList.list[3].temp.max.ToString() + "°C";

                GetImage(count);
            } catch (Exception ex) {
                Console.WriteLine("Error Occurred:" + ex.Message);
            }
        }