Esempio n. 1
0
        private async void InternalAnonymize(IEnumerable <AnonymousStudent> students)
        {
            try
            {
                IsBusy       = true;
                BusyProgress = null;
                BusyMessage  = "Anonymisiere ausgewählte Schüler...";

                // Create a working copy of all students (because we want to update the UI afterwards)
                var allStudents      = Students.ToList();
                var selectedStudents = SelectedStudents.ToList();

                SelectedStudents.Clear();
                Students.Clear();

                await Task.Factory.StartNew(() =>
                {
                    var currentStudentIdx = 0;
                    var studentsCount     = (double)students.Count();

                    foreach (var student in students)
                    {
                        int attempt = 0;
                        do
                        {
                            studentFaker.FakeStudent(student, attempt);
                            attempt++;
                        } while (Students.Count(x => x.AnonymousEmail == student.AnonymousEmail) > 1); // Ensure email addresses are unique!

                        dataSource.UpdateStudent(student);

                        // Update progressbar
                        dispatcher.RunOnUI(() => BusyProgress = (currentStudentIdx / studentsCount) * 100);
                        currentStudentIdx++;
                    }
                }, TaskCreationOptions.LongRunning);

                BusyProgress = null;
                BusyMessage  = "Speichere Änderungen in der internen Datenbank...";

                await dataSource.SaveChangesAsync();

                Students.AddRange(allStudents);
                SelectedStudents.AddRange(selectedStudents);
            }
            catch (Exception e)
            {
                Messenger.Send(new ErrorDialogMessage {
                    Exception = e, Title = "Fehler", Header = "Fehler beim Anonymisieren der Schüler", Text = "Beim Anonymisieren der Schüler ist ein Fehler aufgetreten."
                });
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 2
0
        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();
                });
            };
        }
Esempio n. 3
0
        private async void RemoveSelected()
        {
            try
            {
                IsBusy       = true;
                BusyMessage  = "Ausgewählte Schüler löschen...";
                BusyProgress = 0;

                await Task.Factory.StartNew(() =>
                {
                    var currentStudentIdx = 0;
                    var studentsCount     = SelectedStudents.Count;

                    foreach (var student in SelectedStudents)
                    {
                        dataSource.RemoveStudent(student);

                        // Update progressbar
                        dispatcher.RunOnUI(() => BusyProgress = (currentStudentIdx / studentsCount) * 100);
                        currentStudentIdx++;
                    }
                }, TaskCreationOptions.LongRunning);

                BusyProgress = null;
                BusyMessage  = "Speichere Änderungen in der internen Datenbank...";

                await dataSource.SaveChangesAsync();

                SelectedStudents.Clear();
                LoadStudents();
            }
            catch (Exception e)
            {
                Messenger.Send(new ErrorDialogMessage {
                    Exception = e, Title = "Fehler", Header = "Fehler beim Löschen der Schüler", Text = "Beim Löschen der Schüler ausgewählten ist ein Fehler aufgetreten."
                });
            }
            finally
            {
                IsBusy      = false;
                BusyMessage = string.Empty;
            }
        }