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; } }
private void AnomyizeSelectedStudents() { InternalAnonymize(SelectedStudents.ToList()); }