public WeatherStationViewModel(AppViewModel screen, Core.Locations.Location location, IWeatherService service, IHealthService healthService) { this.HostScreen = screen; this.service = service; this.location = location; #if DEBUG if ((bool)(DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue)) { } else { #endif this.refreshTodaysWeather = ReactiveCommand.CreateFromTask(async() => await service.GetTodaysWeatherAsync(location)); this.todaysWeatherProperty = this.refreshTodaysWeather.Select(weather => new TodaysForecastModel(weather, screen, service)).ToProperty(this, vm => vm.Today); this.forecastCommand = ReactiveCommand.CreateFromTask(async() => { var forecasts = await service.GetWeatherForecastAsync(location); return(forecasts.Select(f => new DayForecastModel(f, screen, service))); }); this.forecasts = this.forecastCommand.ToProperty(this, vm => vm.Forecasts); var refreshConditionsAffectedByWeatherCommand = ReactiveCommand.CreateFromTask(async(TodaysForecast weather) => { var conditions = await healthService.GetConditionsAffectedByWeatherAsync(weather.WeatherCode, weather.Temperature); return(conditions.Select(c => new ConditionViewModel(screen, c.Id, c.Name, healthService))); }); this.conditionsAffectedByWeatherProperty = refreshConditionsAffectedByWeatherCommand.ToProperty(this, vm => vm.ConditionsAffectedByWeather); this.refreshTodaysWeather.InvokeCommand(refreshConditionsAffectedByWeatherCommand); //Create a busy property to show the user we're busy doing something. Observable .CombineLatest(this.refreshTodaysWeather.IsExecuting, this.forecastCommand.IsExecuting, refreshConditionsAffectedByWeatherCommand.IsExecuting, (today, forecast, conditions) => today || forecast || conditions) .ToProperty(this, vm => vm.IsBusy, out this.isBusy); this.hasConditions = this.WhenAnyValue(vm => vm.ConditionsAffectedByWeather).Select(items => items != null && items.Count() > 0).ToProperty(this, vm => vm.HasConditionsAffectedByWeather); this.WhenNavigatedTo(() => Task.Run(async() => { await this.refreshTodaysWeather.Execute(); await this.forecastCommand.Execute(); })); #if DEBUG } #endif }