public async Task <ActionResult <dynamic> > GetCurrentConditions(string q) { dynamic res; try { var cityWeather = db.CitiesWeather.Where(s => s.CityKey == q) .FirstOrDefault(); if (cityWeather == null) { var weatherService = new WeatherService(); res = await weatherService.GetCurrentConditionsAsync(q); } else { res = new List <CurrentConditionsModel>() { }; var currentCondition = new CurrentConditionsModel() { LocalObservationDateTime = null, EpochTime = 0, WeatherText = null, WeatherIcon = 0, HasPrecipitation = false, PrecipitationType = null, IsDayTime = false, Temperature = new _Temperature() { Metric = new _Unit(), Imperial = new _Unit() }, MobileLink = null, Link = null }; currentCondition.WeatherText = cityWeather.WeatherText; currentCondition.Temperature.Metric.Value = cityWeather.CelsiusTemperature; res.Add(currentCondition); } } catch (Exception ex) { EventLog.WriteEntry("GetCurrentConditions error : ", ex.ToString(), EventLogEntryType.Error); return(StatusCode(500)); //Internal Server Error } return(Ok(res)); }
private void FillWithDummyData() { CurrentConditions = new CurrentConditionsModel { ApparentTemperature = "18", ApparentTemperatureUnit = " C", Temperature = "15", TemperatureUnit = " C", ShortPhrase = "Overwegend bewolkt", WindDirection = "zzo", WindSpeed = "50", WindSpeedUnit = "km/u", GustSpeed = "56", GustSpeedUnit = "km/u", Precip1hr = "10", Precip1hrUnit = "mm/h", UpdatedDateTime = DateTime.Now }; HourlyModels = new ObservableCollection <HourlyModel>() { new HourlyModel { }, new HourlyModel { }, new HourlyModel { }, new HourlyModel { }, new HourlyModel { } }; try { StorageFile _storageFile = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Weather/Icon/01.png")).GetResults(); IBuffer readbuffer = FileIO.ReadBufferAsync(_storageFile).GetResults(); CurrentConditions.WeatherIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } try { StorageFile _storageFile = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Weather/UV/01.png")).GetResults(); IBuffer readbuffer = FileIO.ReadBufferAsync(_storageFile).GetResults(); CurrentConditions.UVIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } }
private void FillWithDummyData() { CurrentConditions = new CurrentConditionsModel { ApparentTemperature = "18", ApparentTemperatureUnit = " C", Temperature = "15", TemperatureUnit = " C", ShortPhrase = "Overwegend bewolkt", WindDirection = "zzo", WindSpeed = "50", WindSpeedUnit = "km/u", GustSpeed = "56", GustSpeedUnit = "km/u", Precip1hr = "10", Precip1hrUnit = "mm/h", UpdatedDateTime = DateTime.Now }; HourlyModels = new ObservableCollection <HourlyModel>() { new HourlyModel { Date = DateTime.Now, PrecipationAmountRain = "10", ProbabilityOfPrecipation = "10%", PredictedRealFeel = "-10", PredictedTemperature = "-8", UVIndex = 0, WeatherCode = 1 }, new HourlyModel { Date = DateTime.Now.AddHours(1), PrecipationAmountRain = "10", ProbabilityOfPrecipation = "10%", PredictedRealFeel = "-10", PredictedTemperature = "-8", UVIndex = 1, WeatherCode = 2 }, new HourlyModel { Date = DateTime.Now.AddHours(2), PrecipationAmountRain = "20", ProbabilityOfPrecipation = "20%", PredictedRealFeel = "0", PredictedTemperature = "4", UVIndex = 2, WeatherCode = 3 }, new HourlyModel { Date = DateTime.Now.AddHours(3), PrecipationAmountRain = "5", ProbabilityOfPrecipation = "30%", PredictedRealFeel = "10", PredictedTemperature = "0", UVIndex = 3, WeatherCode = 4 }, new HourlyModel { Date = DateTime.Now.AddHours(4), PrecipationAmountRain = "7", ProbabilityOfPrecipation = "40%", PredictedRealFeel = "10", PredictedTemperature = "8", UVIndex = 3, WeatherCode = 5 }, }; try { StorageFile _storageFile = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Weather/Icon/01.png")).GetResults(); IBuffer readbuffer = FileIO.ReadBufferAsync(_storageFile).GetResults(); CurrentConditions.WeatherIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } UVIndexList = new ObservableCollection <UVIndex> { new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/00.png"), "Ga gerust buiten tennissen.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/01.png"), "Ga gerust buiten tennissen." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/02.png"), "Ga gerust buiten tennissen." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/03.png"), "Niet langer dan 40 minuten tennissen of in de zon." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/04.png"), "Niet langer dan 40 minuten tennissen of in de zon." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/05.png"), "Niet langer dan 40 minuten tennissen of in de zon." + Environment.NewLine + "Rust in de schaduw.", "SPF15+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/06.png"), "Niet langer dan 20 minuten in de zon." + Environment.NewLine + "Ga niet tennissen.", "SPF30+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/07.png"), "Niet langer dan 20 minuten in de zon." + Environment.NewLine + "Ga niet tennissen.", "SPF30+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/08.png"), "Niet langer dan 20 minuten in de zon." + Environment.NewLine + "Ga niet tennissen.", "SPF30+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/09.png"), "Zeer Hoog, ga niet buiten tennissen", "SPF50+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/10.png"), "Zeer Hoog, ga niet buiten tennissen", "SPF50+"), new UVIndex(new Uri("ms-appx:///Assets/Weather/UV/11.png"), "Extreem Hoog, ga niet buiten tennissen", "SPF50+"), }; try { StorageFile _storageFile = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Weather/UV/01.png")).GetResults(); IBuffer readbuffer = FileIO.ReadBufferAsync(_storageFile).GetResults(); CurrentConditions.UVIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } TemperatureRange = new TemperatureRange { Maximum = new Measurement { Value = 20 }, Minimum = new Measurement { Value = -10 } }; }
public async Task <CurrentConditionsModel> GetCurrentConditionsAsync(String locationId, Boolean forceUpdate = false, Boolean getDetails = true, WeatherUnitTypes metric = WeatherUnitTypes.Metric) { CurrentConditionsModel currentConditionsModel; if (WeatherRepository.IsNetworkAvailable()) { if (this._currentConditions != null && !forceUpdate && (this._currentConditions.UpDateTime.AddMinutes(15) < DateTime.UtcNow || this._currentConditions.LocationId != locationId)) { this._currentConditions = null; } if (this._currentConditions == null || forceUpdate) { this._currentConditions = await this._weatherServiceProvider.GetCurrentConditions(locationId); this._currentConditions.UpDateTime = DateTime.UtcNow; this._currentConditions.LocationId = locationId; } CurrentConditionsModel weatherText = new CurrentConditionsModel(); if (this._currentConditions != null) { try { //_currentConditions. weatherText.ShortPhrase = this._currentConditions.WeatherText; if (this._currentConditions.WeatherIcon.HasValue) { weatherText.WeatherCode = this._currentConditions.WeatherIcon.Value; try { Uri WeatherIconUri = new Uri(string.Format("ms-appx:///Assets/Weather/Icon/{0}.png", weatherText.WeatherCode.ToString("D2"))); StorageFile _storageFile = await StorageFile.GetFileFromApplicationUriAsync(WeatherIconUri); IBuffer readbuffer = await FileIO.ReadBufferAsync(_storageFile); weatherText.WeatherIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } } if (this._currentConditions.UVIndex.HasValue) { weatherText.UV = this._currentConditions.UVIndexText; weatherText.UVIndex = this._currentConditions.UVIndex; try { Uri WeatherIconUri = new Uri(string.Format("ms-appx:///Assets/Weather/UV/{0}.png", weatherText.UVIndex.Value.ToString("D2"))); StorageFile _storageFile = await StorageFile.GetFileFromApplicationUriAsync(WeatherIconUri); IBuffer readbuffer = await FileIO.ReadBufferAsync(_storageFile); weatherText.UVIcon = readbuffer.ToArray(); } catch (Exception ex) { string message = ex.Message; } } Double num = WeatherRepository.MathRound(this._currentConditions.Temperature.Metric.NumericValue); weatherText.Temperature = num.ToString(); weatherText.TemperatureUnit = "\u00B0C" + this._currentConditions.Temperature.Metric.Unit; if (getDetails) { if (this._currentConditions.CloudCover.HasValue) { weatherText.CloudCover = String.Concat(this._currentConditions.CloudCover, "%"); } weatherText.PressureTendency = this._currentConditions.PressureTendency.Code; if (this._currentConditions.RelativeHumidity.HasValue) { weatherText.Humidity = String.Concat(this._currentConditions.RelativeHumidity, "%"); } weatherText.UV = this._currentConditions.UVIndexText; weatherText.IsDayTime = this._currentConditions.IsDayTime; Double num1 = WeatherRepository.MathRound(this._currentConditions.WindGust.Speed.Metric.NumericValue); //.Metric.NumericValue); weatherText.GustSpeed = num1.ToString(); weatherText.GustSpeedUnit = this._currentConditions.WindGust.Speed.Metric.Unit; //.Metric.Unit; Double?value1 = this._currentConditions.Pressure.Metric.Value; weatherText.Pressure = value1.ToString(); weatherText.PressureUnit = this._currentConditions.Pressure.Metric.Unit; Double num2 = WeatherRepository.MathRound(this._currentConditions.ApparentTemperature.Metric.NumericValue); weatherText.ApparentTemperature = num2.ToString(); weatherText.ApparentTemperatureUnit = this._currentConditions.ApparentTemperature.Metric.Unit; Double num3 = WeatherRepository.MathRound(this._currentConditions.Visibility.Metric.NumericValue); weatherText.Visibility = num3.ToString(); weatherText.VisibilityUnit = this._currentConditions.Visibility.Metric.Unit; Double num4 = WeatherRepository.MathRound(this._currentConditions.Temperature.Metric.NumericValue); weatherText.Temperature = num4.ToString(); weatherText.TemperatureUnit = this._currentConditions.Temperature.Metric.Unit; Double num5 = WeatherRepository.MathRound(this._currentConditions.Wind.Speed.Metric.NumericValue); weatherText.WindSpeed = num5.ToString(); weatherText.WindSpeedUnit = this._currentConditions.Wind.Speed.Metric.Unit; weatherText.UpdatedDateTime = this._currentConditions.UpDateTime; Double num6 = WeatherRepository.MathRound(this._currentConditions.Precip1hr.Metric.NumericValue); weatherText.Precip1hr = num6.ToString(); weatherText.Precip1hrUnit = this._currentConditions.Precip1hr.Metric.Unit; Double num7 = WeatherRepository.MathRound(this._currentConditions.RelativeHumidity.Value); weatherText.RelativeHumidity = num7.ToString(); Double num8 = WeatherRepository.MathRound(this._currentConditions.Wind.Direction.Degrees.Value); weatherText.WindDegree = num8.ToString(); weatherText.WindDirection = this._currentConditions.Wind.Direction.Localized; } } catch (Exception exception) { string message = exception.Message; //Messenger.Default.Send<ErrorMessageTypeMessage>(new ErrorMessageTypeMessage() //{ // ErrorCode = ErrorCodeType.FailedToGetCurrentConditionsData //}); } } currentConditionsModel = weatherText; } else { //Messenger.Default.Send<ErrorMessageTypeMessage>(new ErrorMessageTypeMessage() //{ // ErrorCode = ErrorCodeType.UnableToConnectNetwork //}); currentConditionsModel = null; } return(currentConditionsModel); }