private void EnsureUniqueNames() { var setUsedNames = new HashSet <string>(); foreach (var item in comboName.Items) { setUsedNames.Add(item.ToString()); } var names = Helpers.EnsureUniqueNames(NamedPathSets.Select(n => n.Key).ToList(), setUsedNames); for (int i = 0; i < NamedPathSets.Length; i++) { var namedPathSet = NamedPathSets[i]; string baseName = namedPathSet.Key; string name = names[i]; if (!Equals(name, baseName)) { NamedPathSets[i] = new KeyValuePair <string, MsDataFileUri[]>(name, namedPathSet.Value); } } }
public void OkDialog() { var helper = new MessageBoxHelper(this); if (NamedPathSets == null) { if (radioAddExisting.Checked) { if (comboName.SelectedIndex == -1) { MessageBox.Show(this, Resources.ImportResultsDlg_OkDialog_You_must_select_an_existing_set_of_results_to_which_to_append_new_data, Program.Name); comboName.Focus(); return; } if (!CanCreateMultiInjectionMethods()) { return; } NamedPathSets = GetDataSourcePathsFile(comboName.SelectedItem.ToString()); } else if (radioCreateMultiple.Checked) { NamedPathSets = GetDataSourcePathsFile(null); } else if (radioCreateMultipleMulti.Checked) { if (!CanCreateMultiInjectionMethods()) { return; } NamedPathSets = GetDataSourcePathsDir(); } else { string name; if (!helper.ValidateNameTextBox(textName, out name)) { return; } if (name.IndexOfAny(Path.GetInvalidFileNameChars()) != -1) { helper.ShowTextBoxError(textName, Resources.ImportResultsDlg_OkDialog_A_result_name_may_not_contain_any_of_the_characters___0___, Path.GetInvalidFileNameChars()); return; } if (ResultsExist(name)) { helper.ShowTextBoxError(textName, Resources.ImportResultsDlg_OkDialog_The_specified_name_already_exists_for_this_document); return; } NamedPathSets = GetDataSourcePathsFile(name); if (NamedPathSets == null) { return; } foreach (var namedPathSet in NamedPathSets) { // Look for a multiple injection replicate if (namedPathSet.Value.Length > 1) { // Make sure they are allowed if (!CanCreateMultiInjectionMethods()) { return; } // If so, then no need to check any others break; } } } } if (NamedPathSets == null) { return; } if (NamedPathSets.Length > 1) { var resultNames = NamedPathSets.Select(ns => ns.Key).ToArray(); string prefix = GetCommonPrefix(resultNames); string suffix = GetCommonSuffix(resultNames); if (!String.IsNullOrEmpty(prefix) || !String.IsNullOrEmpty(suffix)) { using (var dlgName = new ImportResultsNameDlg(prefix, suffix, resultNames)) { var result = dlgName.ShowDialog(this); if (result == DialogResult.Cancel) { return; } if (dlgName.IsRemove) { dlgName.ApplyNameChange(NamedPathSets); Prefix = string.IsNullOrEmpty(prefix) ? null : prefix; Suffix = string.IsNullOrEmpty(suffix) ? null : suffix; } } } } // Always make sure multiple replicates have unique names. For single // replicate, the user will get an error. if (IsMultiple) { EnsureUniqueNames(); } DialogResult = DialogResult.OK; }