public TabStatusViewModel(ConfigController cfgController, WeatherSensorDataProvider sensorDataProvider, WateringExecution wateringExecution, bool debug) { _sensorDataProvider = sensorDataProvider; _cfgCtrl = cfgController; _wateringExecution = wateringExecution; _debug = debug; _wateringExecution.PropertyChanged += WateringExecution_PropertyChanged; sensorDataProvider.PropertyChanged += SensorDataProvider_PropertyChanged; if (!_debug) { DigitalIOConnector.Instance.PropertyChanged += DigitalIOConnector_PropertyChanged; } LastReadingPoints = new RangeAddableObservableCollection <Measurement>(_sensorDataProvider.LastReadingPoints); ChangePumpStatusCmd = ReactiveCommand.Create(DoChangePumpStatus); }
public override void OnFrameworkInitializationCompleted() { TabConfigViewModel tabConfigViewModel = null; TabStatusViewModel statusViewModel = null; TabHistoryPumpViewModel historyPumpViewModel = null; TabHistoryViewModel historyViewModel = null; TabGraphicViewModel graphicViewModel = null; DataService wateringDataService = null; WateringExecution wateringExecution; WeatherSensorDataProvider sensorDataProvider; bool debug = false; #if DEBUG debug = true; #endif if (!Design.IsDesignMode) { Log.Logger = new LoggerConfiguration() .Enrich.WithThreadId() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .MinimumLevel.Debug() .WriteTo.File("Watering.log", rollingInterval: RollingInterval.Day, shared: true, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}]<{ThreadId}>{SourceContext} {Message} {Properties} {NewLine}{Exception}") .WriteTo.Console(LogEventLevel.Information, "{NewLine}{Timestamp:yyyy-MM-dd HH:mm:ss} {Message}{NewLine}{Exception}") .CreateLogger(); Log.Information("Program starting..."); ConfigController cfgController = new ConfigController(); tabConfigViewModel = new TabConfigViewModel(cfgController); wateringDataService = new DataService(); wateringExecution = new WateringExecution(cfgController, wateringDataService, debug); sensorDataProvider = new WeatherSensorDataProvider(wateringDataService, cfgController, debug); statusViewModel = new TabStatusViewModel(cfgController, sensorDataProvider, wateringExecution, debug); historyPumpViewModel = new TabHistoryPumpViewModel(wateringDataService); historyViewModel = new TabHistoryViewModel(wateringDataService); graphicViewModel = new TabGraphicViewModel(cfgController, wateringDataService, wateringExecution); } IClassicDesktopStyleApplicationLifetime desktop = null; if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime) { desktop = lifetime; desktop.MainWindow = new MainWindow(); desktop.MainWindow.DataContext = tabConfigViewModel == null ? new MainWindowViewModel() : new MainWindowViewModel(statusViewModel, tabConfigViewModel, historyPumpViewModel, historyViewModel, graphicViewModel, desktop.MainWindow); } if (desktop != null) { desktop.Exit += Desktop_Exit; } base.OnFrameworkInitializationCompleted(); }