private void embedAllButton_Click(object sender, EventArgs e) { var searchPath = new StringBuilder(searchPathTextBox.Text); string extensions = extensionsTextBox.Text; Application.UseWaitCursor = true; deleteAllButton.Enabled = embedAllButton.Enabled = false; embeddedChanges = true; try { // add location of original idpDBs to the search path var mergedFilepaths = session.CreateSQLQuery("SELECT DISTINCT Filepath FROM MergedFiles").List <string>(); foreach (var filepath in mergedFilepaths) { searchPath.AppendFormat(";{0}", System.IO.Path.GetDirectoryName(filepath)); } } catch { // ignore if MergedFiles does not exist } var quantitationMethodBySource = new Dictionary <int, Embedder.QuantitationConfiguration>(); var xicConfigBySource = new Dictionary <int, Embedder.XICConfiguration> { { 0, _defaultXicConfig } }; foreach (DataGridViewRow row in dataGridView.Rows) { int id = (int)row.Cells[idColumn.Index].Value; var method = QuantitationMethodForRow(row.Index); if (IsLabelFree(method)) { xicConfigBySource[id] = (Embedder.XICConfiguration)row.Cells[quantitationSettingsColumn.Index].Value; quantitationMethodBySource[id] = new Embedder.QuantitationConfiguration(QuantitationMethod.LabelFree, _defaultIsobaricConfig.ToString()); } else if (IsIsobaric(method)) { quantitationMethodBySource[id] = (Embedder.QuantitationConfiguration)row.Cells[quantitationSettingsColumn.Index].Value; } } okButton.Text = "Cancel"; EmbedInProgress = true; new Thread(() => { try { var ilr = new IterationListenerRegistry(); ilr.addListener(new EmbedderIterationListener(this), 1); var tempFolder = string.Empty; var splitSourceList = new List <List <string> >(); if (quantitationMethodBySource.Any(x => IsLabelFree(x.Value.QuantitationMethod)) && xicConfigBySource.Any(x => x.Value.AlignRetentionTime)) { tempFolder = getTempFolder(); splitSourceList = GetRTAlignGroups(); } string idpDbFilepath = session.Connection.GetDataSource(); if (embedScanTimeOnlyBox.Checked) { Embedder.EmbedScanTime(idpDbFilepath, searchPath.ToString(), extensions, quantitationMethodBySource, ilr); } else { Embedder.Embed(idpDbFilepath, searchPath.ToString(), extensions, quantitationMethodBySource, ilr); } if (quantitationMethodBySource.Any(x => IsLabelFree(x.Value.QuantitationMethod))) { BeginInvoke(new MethodInvoker(() => ModeandDefaultPanel.Visible = false)); if (xicConfigBySource.Any(x => x.Value.AlignRetentionTime)) { try { RTAlignPreparations(splitSourceList, tempFolder); foreach (var kvp in xicConfigBySource) { kvp.Value.RTFolder = tempFolder; } } catch (Exception rtError) { MessageBox.Show("Error: Cannot prepare RT alignment. Skipping to next stage." + Environment.NewLine + rtError.Message); foreach (var kvp in xicConfigBySource) { kvp.Value.AlignRetentionTime = false; } } } Embedder.EmbedMS1Metrics(idpDbFilepath, searchPath.ToString(), extensions, quantitationMethodBySource, xicConfigBySource, ilr); if (!string.IsNullOrEmpty(tempFolder) && Directory.Exists(tempFolder)) { Directory.Delete(tempFolder, true); } BeginInvoke(new MethodInvoker(() => ModeandDefaultPanel.Visible = true)); } } catch (Exception ex) { if (ex.Message.Contains("QuantitationConfiguration")) { string message = ex.Message.Replace("[QuantitationConfiguration] ", ""); message = Char.ToUpper(message[0]) + message.Substring(1); MessageBox.Show(message); } else if (ex.Message.Contains("no filepath")) { bool multipleMissingFilepaths = ex.Message.Contains("\n"); string missingFilepaths = ex.Message.Replace("\n", "\r\n"); missingFilepaths = missingFilepaths.Replace("[embed] no", "No"); missingFilepaths = missingFilepaths.Replace("[embedScanTime] no", "No"); MessageBox.Show(missingFilepaths + "\r\n\r\nCheck that " + (multipleMissingFilepaths ? "these source files" : "this source file") + " can be found in the search path with one of the specified extensions."); } else { Program.HandleException(ex); } } BeginInvoke(new MethodInvoker(() => Refresh())); }).Start(); }