private async void menuClick_ImportFromSNPediaAsync(object sender, RoutedEventArgs args) { // Don't allow importing the SNPedia data unless this isn't an end user (i.e. the app is being debugged) if (!Debugger.IsAttached) { WinForms.MessageBox.Show("Importing data from SNPedia is disabled for non-developers to limit the load on SNPedia. This option is re-enabled if you run the program within a debugger.", "SNPedia import disabled"); return; } // Disable the main window. IsEnabled = false; // Create the progress window. var cancellationTokenSource = new CancellationTokenSource(); var progressWindow = new ProgressWindow(() => cancellationTokenSource.Cancel()); progressWindow.Owner = this; progressWindow.Show(); // Try to read the data from the provided 23andme username. var newDatabase = await SNPediaReader.CreateSNPDatabaseAsync( (progressText, progress) => progressWindow.Update(progressText, progress), cancellationTokenSource.Token ); // Close the progress window and reenable the main window. progressWindow.ForceClose(); IsEnabled = true; // If the database was successfully imported, replace the local database with it. if (newDatabase != null) { SNPDatabaseManager.localDatabase = newDatabase; // Reanalyse after updating the SNP database. InitAnalysis(); } }
private async void menuClick_ImportFromdbSNPAsync(object sender, RoutedEventArgs args) { var dialog = new WinForms.OpenFileDialog(); dialog.Filter = "dbSNP flat files|*.flat|All files (*.*)|*.*"; dialog.Multiselect = true; if (dialog.ShowDialog() == WinForms.DialogResult.OK) { // Disable the main window. IsEnabled = false; // Create the progress window. var cancellationTokenSource = new CancellationTokenSource(); var progressWindow = new ProgressWindow(() => cancellationTokenSource.Cancel()); progressWindow.Owner = this; progressWindow.Show(); var fileNameList = dialog.FileNames.ToList(); for (var fileIndex = 0; fileIndex < fileNameList.Count; ++fileIndex) { var filename = fileNameList[fileIndex]; using (var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read)) { progressWindow.Update(string.Format("Processing {0}", filename), (double)fileIndex / fileNameList.Count); await Task.Run(() => (new dbSNPReader(new StreamReader(fileStream))).ProcessSNPOrientationInfo(cancellationTokenSource.Token)); } } // Close the progress window and reenable the main window. progressWindow.ForceClose(); IsEnabled = true; // Reanalyse after updating the SNP database. InitAnalysis(); } }