private async Task SaveUpdatedNotesToFileAsync(List <NotesData> notes, ProgressData progressData) { progressData.Reset("Saving local copy of changes.", notes.Count); var saveFileDialog = new SaveFileDialog { Title = "Save a record of updated notes", InitialDirectory = FileUtils.GetDefaultDirectory(null), FileName = $"Ancestry Notes Changes {DateTime.Now.ToString("yyyy-MM-dd")}.xlsx", DefaultExt = ".xlsx", Filter = "Excel Workbook (*.xlsx)|*.xlsx", }; if (saveFileDialog.ShowDialog() != true) { return; } Settings.Default.LastUsedDirectory = Path.GetDirectoryName(saveFileDialog.FileName); Settings.Default.Save(); var fileName = saveFileDialog.FileName; using (var p = new ExcelPackage()) { await Task.Run(() => { var ws = p.Workbook.Worksheets.Add("Updated Notes"); var row = 1; ws.Cells[row, 1].Value = "Name"; ws.Cells[row, 2].Value = "Test ID"; ws.Cells[row, 3].Value = "Old Notes"; ws.Cells[row, 4].Value = "New Notes"; foreach (var note in notes) { row++; ws.Cells[row, 1].Value = note.Name; ws.Cells[row, 2].Value = note.TestId; ws.Cells[row, 3].Value = note.OldNotes; ws.Cells[row, 4].Value = note.NewNotes; progressData.Increment(); } }); FileUtils.Save(p, fileName); FileUtils.LaunchFile(fileName); } }
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); } }
// Present an Open File dialog to allow selecting the saved DNA data from disk public string SelectFile(string fileName) { var openFileDialog = new OpenFileDialog { Title = "Select file with Ancestry notes to upload", InitialDirectory = FileUtils.GetDefaultDirectory(fileName), FileName = fileName, Filter = "Excel Workbook (*.xlsx)|*.xlsx", }; if (openFileDialog.ShowDialog() == true) { Settings.Default.LastUsedDirectory = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); return(openFileDialog.FileName); } return(null); }
private async Task SaveUpdatedNotesToFileAsync(List <NotesData> notes, List <Tag> originalTags, ProgressData progressData) { progressData.Reset("Saving local copy of changes.", notes.Count); var saveFileDialog = new SaveFileDialog { Title = "Save a record of updated notes", InitialDirectory = FileUtils.GetDefaultDirectory(null), FileName = $"Ancestry Notes Changes {DateTime.Now.ToString("yyyy-MM-dd")}.xlsx", DefaultExt = ".xlsx", Filter = "Excel Workbook (*.xlsx)|*.xlsx", }; if (saveFileDialog.ShowDialog() != true) { return; } Settings.Default.LastUsedDirectory = Path.GetDirectoryName(saveFileDialog.FileName); Settings.Default.Save(); var fileName = saveFileDialog.FileName; var affectedNotes = notes.Any(note => note.NewNotes != null); var affectedStarred = notes.Any(note => note.NewStarred != null); var affectedTagIds = new HashSet <int>(notes.SelectMany(note => note.NewTags.Concat(note.NewTagsRemoved))); var affectedTags = originalTags.Where(tag => affectedTagIds.Contains(tag.TagId)).ToList(); using (var p = new ExcelPackage()) { await Task.Run(() => { var ws = p.Workbook.Worksheets.Add("Updated Notes"); var row = 1; var col = 1; ws.Cells[row, col++].Value = "Name"; ws.Cells[row, col++].Value = "Test ID"; if (affectedNotes) { ws.Cells[row, col++].Value = "Old Notes"; ws.Cells[row, col++].Value = "New Notes"; } if (affectedStarred) { ws.Cells[row, col++].Value = "Old Starred"; ws.Cells[row, col++].Value = "New Starred"; } foreach (var tag in affectedTags) { ws.Cells[row, col++].Value = $"Old {tag.Label}"; ws.Cells[row, col++].Value = $"New {tag.Label}"; } foreach (var note in notes) { row++; col = 1; ws.Cells[row, col++].Value = note.Name; ws.Cells[row, col++].Value = note.TestId; if (affectedNotes) { ws.Cells[row, col++].Value = note.OldNotes; ws.Cells[row, col++].Value = note.NewNotes; } if (affectedStarred) { ws.Cells[row, col++].Value = note.OldStarred ? "*" : null; ws.Cells[row, col++].Value = (note.NewStarred ?? note.OldStarred) ? "*" : null; } foreach (var tag in affectedTags) { ws.Cells[row, col++].Value = note.OldTags.Contains(tag.TagId) ? "." : null; ws.Cells[row, col++].Value = note.NewTagsRemoved.Contains(tag.TagId) ? null : note.NewTags.Contains(tag.TagId) || note.OldTags.Contains(tag.TagId) ? "." : null; } progressData.Increment(); } }); FileUtils.Save(p, fileName); FileUtils.LaunchFile(fileName); } }
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); } }