public List <DarkSkyForecast> getForecast(string cityName)
        {
            darkSkyAPIEndpoint.endpointType = EndpointType.FORECAST;

            AccuWeatherController accuWeatherController = new AccuWeatherController();

            List <DarkSkyForecast> forecastList = new List <DarkSkyForecast>();

            GeoPosition geoPosition = accuWeatherController.getGeoPosition(cityName);
            string      response    = getResponse(darkSkyAPIEndpoint.getWeatherForecast(geoPosition.Latitude, geoPosition.Longitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <DarkSkyAPIForecastModel> jsonParser = new JsonParser <DarkSkyAPIForecastModel>())
            {
                DarkSkyAPIForecastModel darkSkyForecastModel = new DarkSkyAPIForecastModel();
                darkSkyForecastModel = jsonParser.parse(response, netCoreVersion);

                foreach (DarkSkyData data in darkSkyForecastModel.daily.data)
                {
                    forecastList.Add(new DarkSkyForecast(data.time, data.temperatureMin, data.temperatureMax));
                }
            }

            return(forecastList);
        }
        public float getCurrentWeather(string cityName)
        {
            darkSkyAPIEndpoint.endpointType = EndpointType.FORECAST;
            AccuWeatherController accuWeatherController = new AccuWeatherController();
            GeoPosition           geoPosition           = accuWeatherController.getGeoPosition(cityName);
            float temperature = 0f;

            string response = getResponse(darkSkyAPIEndpoint.getWeatherForecast(geoPosition.Latitude, geoPosition.Longitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <DarkSkyAPIForecastModel> jsonParser = new JsonParser <DarkSkyAPIForecastModel>())
            {
                DarkSkyAPIForecastModel darkSkyCurrentWeatherModel = new DarkSkyAPIForecastModel();
                darkSkyCurrentWeatherModel = jsonParser.parse(response, netCoreVersion);

                temperature = darkSkyCurrentWeatherModel.currently.temperature;
            }

            return(temperature);
        }
示例#3
0
        public float getCurrentWeather(string cityName)
        {
            climaCellAPIEndpoint.endpointType = EndpointType.WEATHER;
            AccuWeatherController accuWeatherController = new AccuWeatherController();
            GeoPosition           geoPosition           = accuWeatherController.getGeoPosition(cityName);
            float temperature = 0f;

            string response = getResponse(climaCellAPIEndpoint.getCurrentWeather(geoPosition.Latitude, geoPosition.Longitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <ClimaCellAPIModel> jsonParser = new JsonParser <ClimaCellAPIModel>())
            {
                ClimaCellAPIModel climaCellAPIModel = new ClimaCellAPIModel();
                climaCellAPIModel = jsonParser.parse(response, netCoreVersion);

                temperature = climaCellAPIModel.temp.value;
            }

            return(temperature);
        }
        public List <Weather2020Forecast> getForecast(string cityName)
        {
            AccuWeatherController accuWeatherController = new AccuWeatherController();

            List <Weather2020Forecast> forecastList = new List <Weather2020Forecast>();

            GeoPosition geoPosition = accuWeatherController.getGeoPosition(cityName);
            string      response    = getResponse(weather2020APIEndpoint.getWeatherForecast(geoPosition.Latitude, geoPosition.Longitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <List <Weather2020APIModel> > jsonParser = new JsonParser <List <Weather2020APIModel> >())
            {
                List <Weather2020APIModel> weather2020APIModel = new List <Weather2020APIModel>();
                weather2020APIModel = jsonParser.parse(response, netCoreVersion);

                foreach (Weather2020APIModel forecast in weather2020APIModel)
                {
                    forecastList.Add(new Weather2020Forecast(forecast.startDate, forecast.temperatureLowCelcius, forecast.temperatureHighCelcius));
                }
            }

            return(forecastList);
        }
示例#5
0
        public List <ClimaCellForecast> getForecast(string cityName)
        {
            AccuWeatherController accuWeatherController = new AccuWeatherController();

            List <ClimaCellForecast> forecastList = new List <ClimaCellForecast>();

            GeoPosition geoPosition = accuWeatherController.getGeoPosition(cityName);
            string      response    = getResponse(climaCellAPIEndpoint.getWeatherForecast(geoPosition.Latitude, geoPosition.Longitude));

            System.Diagnostics.Debug.WriteLine(response);

            using (JsonParser <List <ClimaCellForecastModel> > jsonParser = new JsonParser <List <ClimaCellForecastModel> >())
            {
                List <ClimaCellForecastModel> climaCellAPIModel = new List <ClimaCellForecastModel>();
                climaCellAPIModel = jsonParser.parse(response, netCoreVersion);

                foreach (ClimaCellForecastModel forecast in climaCellAPIModel)
                {
                    forecastList.Add(new ClimaCellForecast(forecast.observation_time.value, forecast.temp[0].min.value, forecast.temp[1].max.value));
                }
            }

            return(forecastList);
        }