예제 #1
0
        public ResponseForecast.RootObjectForecast ExecuteRequestForecast()
        {
            var client = new RestClient(url);

            response = client.Execute(request);

            ResponseForecast.RootObjectForecast objRootForecast = new ResponseForecast.RootObjectForecast();
            objRootForecast = JsonConvert.DeserializeObject <ResponseForecast.RootObjectForecast>(response.Content);

            return(objRootForecast);
        }
예제 #2
0
        public async Task <ResponseForecast.RootObjectForecast> ExecuteRequestAsync()
        {
            var client  = new RestClient(url);
            var request = new RestRequest();

            response = await client.ExecuteTaskAsync(request);

            ResponseForecast.RootObjectForecast objRootForecast = new ResponseForecast.RootObjectForecast();
            objRootForecast = JsonConvert.DeserializeObject <ResponseForecast.RootObjectForecast>(response.Content);

            return(objRootForecast);
        }
예제 #3
0
        public void LoadWeatherByLocation(string city)
        {
            objRest = new RESTHandler(@"http://api.openweathermap.org/data/2.5/weather?");

            objRest.AddParameter("q", city + ",NZ");
            objRest.AddParameter("units", "metric");
            objRest.AddParameter("appid", "5284e966d7b963bd0b0ae0e0b339492d");

            objRootList = objRest.ExecuteRequest();

            temp         = objRootList.main.temp.ToString();
            txtTemp.Text = temp + "°C";

            tempMin     = objRootList.main.temp_min.ToString() + "°C";
            txtMin.Text = tempMin;

            tempMax     = objRootList.main.temp_max.ToString() + "°C";
            txtMax.Text = tempMax;

            city         = objRootList.name;
            txtCity.Text = city;

            string currenttime = DateTime.Now.AddHours(16).ToString("dd'/'MM'/'yyyy HH:mm:ss");

            txtDateTime.Text = currenttime;

            message         = objRootList.weather[0].description.ToString();
            txtMessage.Text = message;

            icon = objRootList.weather[0].icon;


//***************************************************************************************************************************************************************


            objRestFor = new RESTHandlerForecast(@"http://api.openweathermap.org/data/2.5/forecast/daily?");
            objRestFor.AddParameter("q", city + ",NZ");
            objRestFor.AddParameter("units", "metric");
            objRestFor.AddParameter("cnt", "6");
            objRestFor.AddParameter("appid", "5284e966d7b963bd0b0ae0e0b339492d");

            objRootListFor     = objRestFor.ExecuteRequestForecast();
            lstForecast        = objRootListFor.list;
            lvForecast.Adapter = new DataAdapter(this, lstForecast);

            FindImage(icon);
        }