public MainViewModel(IStudentFaker studentFaker, IPersistentDataSource dataSource, ISchILDDataSource schILDDataSource, IIndex <string, IExportService> exportServices, IDispatcher dispatcher, IMessenger messenger) : base(messenger) { this.studentFaker = studentFaker; this.dataSource = dataSource; this.schILDDataSource = schILDDataSource; this.exportServices = exportServices; this.dispatcher = dispatcher; LoadStudentsCommand = new RelayCommand(LoadStudents, CanLoadStudents); SyncCommand = new RelayCommand(Sync, CanSync); AnonymizeCommand = new RelayCommand(Anonymize, CanAnonymize); AnonymizeSelectedStudentsCommand = new RelayCommand(AnomyizeSelectedStudents, CanAnonymizeSelectedStudents); RemoveNonActiveStudentsCommand = new RelayCommand(RemoveNonActive, CanRemoveNonActive); RemoveSelectedStudentsCommand = new RelayCommand(RemoveSelected, CanRemoveSelected); ExportCsvCommand = new RelayCommand(ExportCsv, CanExport); ExportSchulITIdpCommand = new RelayCommand(ExportSchulITIdp, CanExport); Students.CollectionChanged += (sender, args) => { AnonymizeCommand?.RaiseCanExecuteChanged(); RemoveNonActiveStudentsCommand?.RaiseCanExecuteChanged(); ExportCsvCommand?.RaiseCanExecuteChanged(); ExportSchulITIdpCommand?.RaiseCanExecuteChanged(); }; SelectedStudents.CollectionChanged += (sender, args) => { RemoveSelectedStudentsCommand?.RaiseCanExecuteChanged(); AnonymizeSelectedStudentsCommand?.RaiseCanExecuteChanged(); }; dataSource.ConnectionStateChanged += (sender, args) => { dispatcher.RunOnUI(() => { if (args.IsConnected == false) { // Clear all students in case we get disconnected Students.Clear(); SelectedStudents.Clear(); } IsNotPersistentDatabase = sender.IsInMemory; LoadStudentsCommand?.RaiseCanExecuteChanged(); SyncCommand?.RaiseCanExecuteChanged(); AnonymizeCommand?.RaiseCanExecuteChanged(); }); }; }
public SettingsViewModel(IPersistentDataSource persistentDataSource, ISchILDDataSource schILDDataSource, ISettingsService settingsService, IMessenger messenger) : base(messenger) { this.persistentDataSource = persistentDataSource; this.schILDDataSource = schILDDataSource; this.settingsService = settingsService; TestSchILDConnectionCommand = new RelayCommand(TestConnectSchILD, CanTestConnectSchILD); TestDataSourceConnectionCommand = new RelayCommand(TestConnectDataSource, TestCanConnectDataSource); ConnectDataSourceCommand = new RelayCommand(ConnectDataSource, CanConnectDataSource); AddDatabaseTypes(); AddAnonymizationTypes(); LoadSettings(); settingsService.Changed += delegate { TestSchILDConnectionCommand?.RaiseCanExecuteChanged(); TestDataSourceConnectionCommand?.RaiseCanExecuteChanged(); ConnectDataSourceCommand?.RaiseCanExecuteChanged(); }; }