private async Task MaybeUpdateFilesAsync(List <NotesData> notes) { if (MessageBox.Show( "Do you also want to update data files that you already downloaded from Ancestry and have saved locally?", "Also update local saved data files", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } MessageBox.Show( "Select each file to update, Cancel to continue to updating the Ancestry web site.", "Also update local saved data files", MessageBoxButton.OK, MessageBoxImage.Information); while (true) { var openFileDialog = new OpenFileDialog { Title = "Select local file with Ancestry data to update", InitialDirectory = FileUtils.GetDefaultDirectory(null), Filter = "Shared Clustering downloaded data (*.txt)|*.txt", }; if (openFileDialog.ShowDialog() != true || string.IsNullOrEmpty(openFileDialog.FileName)) { return; } Settings.Default.LastUsedDirectory = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); var notesById = notes.ToDictionary(note => note.TestId); var serialized = await Task.Run(() => FileUtils.ReadAsJson <Serialized>(openFileDialog.FileName, false, false)); foreach (var match in serialized.Matches) { if (notesById.TryGetValue(match.TestGuid, out var note)) { match.Note = note.NewNotes; } } FileUtils.WriteAsJson(openFileDialog.FileName, serialized, false); } }
private async Task MaybeUpdateFilesAsync(List <NotesData> notes, List <Tag> originalTags) { var notesByIdGroups = notes.GroupBy(note => note.TestId).ToList(); var duplicatedIds = notesByIdGroups.Where(g => g.Count() > 1).ToList(); if (duplicatedIds.Count > 0) { MessageBox.Show( $"Duplicate IDs found for names: {string.Join(", ", duplicatedIds.SelectMany(g => g).Select(notesData => notesData.Name))}. Please remove duplicates and try again", "Duplicate IDs found", MessageBoxButton.OK, MessageBoxImage.Error); return; } var notesById = notesByIdGroups.ToDictionary(g => g.Key, g => g.First()); if (MessageBox.Show( "Do you also want to update data files that you already downloaded from Ancestry and have saved locally?", "Also update local saved data files", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes) { return; } MessageBox.Show( "Select each file to update, Cancel to continue to updating the Ancestry web site.", "Also update local saved data files", MessageBoxButton.OK, MessageBoxImage.Information); while (true) { var openFileDialog = new OpenFileDialog { Title = "Select local file with Ancestry data to update", InitialDirectory = FileUtils.GetDefaultDirectory(null), Filter = "Shared Clustering downloaded data (*.txt)|*.txt", }; if (openFileDialog.ShowDialog() != true || string.IsNullOrEmpty(openFileDialog.FileName)) { return; } Settings.Default.LastUsedDirectory = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); var serialized = await Task.Run(() => FileUtils.ReadAsJson <Serialized>(openFileDialog.FileName, false, false)); foreach (var match in serialized.Matches) { if (notesById.TryGetValue(match.TestGuid, out var note)) { match.Note = note.NewNotes; if (note.NewStarred != null) { match.Starred = note.NewStarred.Value; } if (note.NewTags.Any()) { match.TagIds = (match.TagIds ?? new List <int>()) .Except(note.NewTagsRemoved) .Concat(note.NewTags) .Distinct() .OrderBy(t => t) .ToList(); } } } FileUtils.WriteAsJson(openFileDialog.FileName, serialized, false); } }