private async Task itemInit(CityViewModel item, HeWeatherModel weather) { item.NowCondition = weather.NowWeather.Now.Condition; item.Temperature = weather.NowWeather.Temprature; string p = TemperatureDecoratorConverter.GetCurrentDeco(); item.Decorator = p; var utcOffset = weather.Location.UpdateTime - weather.Location.UtcTime; var current = DateTimeHelper.ReviseLoc(utcOffset); var todayIndex = Array.FindIndex(weather.DailyForecast, x => { return(x.Date.Date == current.Date); }); var hourIndex = Array.FindIndex(weather.HourlyForecast, x => { return((x.DateTime - current).TotalSeconds > 0); }); if (todayIndex < 0) { todayIndex = 0; } if (hourIndex < 0) { hourIndex = 0; } item.High = weather.DailyForecast[todayIndex].HighTemp; item.Low = weather.DailyForecast[todayIndex].LowTemp; var isNight = Generator.CalcIsNight(weather.Location.UpdateTime, weather.DailyForecast[todayIndex].SunRise, weather.DailyForecast[todayIndex].SunSet, new Models.Location(item.latitude, item.longitude)); item.Glance = Glance.GenerateGlanceDescription(weather, isNight, settings.Preferences.TemperatureParameter, DateTime.Now); var uri = await settings.Immersive.GetCurrentBackgroundAsync(weather.NowWeather.Now.Condition, isNight); if (uri != null) { try { item.Background = new BitmapImage(uri); } catch (Exception) { } } item.data = null; }
private async Task Complete(CityViewModel item) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(async() => { if (item.data != null && item.data.Length > 31) { var weather = HeWeatherModel.Generate(item.data, settings.Preferences.DataSource); if (weather == null || weather.DailyForecast == null || weather.HourlyForecast == null) { return; } await itemInit(item, weather); item.Updated = true; item.Succeed = true; item.LastUpdate = DateTime.Now; } })); }