Exemple #1
0
        public async Task <ForecastModel> GetWeather(string city, DateTime?date)
        {
            if (string.IsNullOrEmpty(city)) // todo: think about it
            {
                city = DefaultCity;
            }

            if (date.Equals(null)) // todo: think about it
            {
                date = DateTime.UtcNow;
            }


            var address         = GetAddressFromString(city);
            var forecastOptions = new DarkSkyService.OptionalParameters
            {
                MeasurementUnits = "si",
                ForecastDateTime = date
            };
            var response =
                await _client.GetForecast(address.Coordinates.Latitude, address.Coordinates.Longitude, forecastOptions);

            var forecastResult = response.Response;
            var forecast       = new ForecastModel
            {
                Temperature = forecastResult.Currently.Temperature.ToString(),
                WindSpeed   = forecastResult.Currently.WindSpeed.ToString(),
                Summary     = forecastResult.Currently.Summary,
                Location    = address.ToString(),
            };

            return(await Task.FromResult(forecast));
        }
Exemple #2
0
        /// <summary>
        /// Find Imperial or Metric UOM
        /// </summary>
        /// <returns>A boolean = Imperial or Metric UOM</returns>
        private DarkSkyService.OptionalParameters GetUnitOfMeasure()
        {
            bool blnMetric = RegionInfo.CurrentRegion.IsMetric;

            DarkSkyService.OptionalParameters optParms = new DarkSkyService.OptionalParameters();
            if (blnMetric)
            {
                optParms.MeasurementUnits = "si";
                TempUnitOfMeasure         = "C";
            }
            else
            {
                optParms.MeasurementUnits = "us";
                TempUnitOfMeasure         = "F";
            }
            return(optParms);
        }
        private async Task GetWeatherInfo()
        {
            string         apiKey  = "7b2386b7eb27edfe56672ce1520b8893";
            DarkSkyService weather = new DarkSkyService(apiKey);

            DarkSkyService.OptionalParameters optParams = GetUnitOfMeasure();
            var foreCast = await weather.GetForecast(Latt, Long, optParams);

            string iconFileName = GetCurrentWeatherIcon(foreCast.Response.Currently.Icon);
            string svgFile      = Path.Combine(_hostEnv.ContentRootPath, "climacons", iconFileName);

            CurrentWeatherIcon = System.IO.File.ReadAllText($"{svgFile}");
            WeatherAttribution = foreCast.AttributionLine;
            DayWeatherSummary  = foreCast.Response.Daily.Summary;

            if (foreCast.Response.Currently.Temperature.HasValue)
            {
                CurrentTemp = Math.Round(foreCast.Response.Currently.Temperature.Value, 0).ToString();
            }
        }
        private async Task GetWeatherInfo()
        {
            string         apiKey  = "https://api.darksky.net/forecast/444d2c868cd209e1e72ba926eb8e0744/37.8267,-122.4233";
            DarkSkyService weather = new DarkSkyService(apiKey);

            DarkSkyService.OptionalParameters optParams = GetunitOfMeasure();
            var foreCast = await weather.GetForecast(Latt, Long, optParams);

            string iconFileName =
                GetCurrentWeatherIcon(foreCast.Response.Currently.Icon);
            string svgFile = Path.Combine(_hostEnv.ContentRootPath, "climacons", iconFileName);

            CurrentWeatherIcon = System.IO.File.ReadAllText($"{svgFile}");
            WeatherAttribution = foreCast.AttributionLine;
            DayWeatherSummary  = foreCast.Response.Daily.Summary;
            if (foreCast.Response.Currently.Temperature.HasValue)
            {
                CurrentTemp = Round(foreCast.Response.Currently.Temperature.Value, 0).ToString();
            }
        }
Exemple #5
0
 public async Task <DarkSkyResponse> GetForecast(double latitude, double longitude, DarkSkyService.OptionalParameters options)
 {
     return(options != null
         ? await _service.GetForecast(latitude, longitude, options)
         : await _service.GetForecast(latitude, longitude));
 }