private void AddMenuItemsForSwitchingToInstancesInYamlFilesOf(ConnectionStringsYamlFile origYamlFile, DirectoryInfo dir) { foreach (var yaml in dir.GetFiles("*.yaml")) { // if the yaml file is invalid bail out early if (!ConnectionStringsYamlFile.TryLoadFrom(yaml, out var connectionStrings)) { continue; } bool isSameAsCurrent = origYamlFile?.FileLoaded == null ? false : yaml.FullName.Equals(origYamlFile.FileLoaded.FullName); var launchNew = new ToolStripMenuItem(connectionStrings.Name ?? yaml.Name, null, (s, e) => { LaunchNew(connectionStrings); }) { Checked = isSameAsCurrent, ToolTipText = connectionStrings.Description ?? yaml.FullName }; var switchTo = new ToolStripMenuItem(connectionStrings.Name ?? yaml.Name, null, (s, e) => { SwitchTo(connectionStrings); }) { Enabled = !isSameAsCurrent, Checked = isSameAsCurrent, ToolTipText = connectionStrings.Description ?? yaml.FullName }; launchAnotherInstanceToolStripMenuItem.DropDownItems.Add(launchNew); switchToInstanceToolStripMenuItem.DropDownItems.Add(switchTo); } }
private void btnCreateYamlFile_Click(object sender, EventArgs e) { try { var toSerialize = new ConnectionStringsYamlFile() { CatalogueConnectionString = tbCatalogueConnectionString.Text, DataExportConnectionString = tbDatabasePrefix.Text, }; var serializer = new Serializer(); var yaml = serializer.Serialize(toSerialize); var sfd = new SaveFileDialog(); sfd.Filter = "Yaml|*.yaml"; sfd.Title = "Save yaml"; sfd.InitialDirectory = UsefulStuff.GetExecutableDirectory().FullName; if (sfd.ShowDialog() == DialogResult.OK) { File.WriteAllText(sfd.FileName, yaml); } } catch (Exception ex) { ExceptionViewer.Show(ex); } }
private void LaunchNew(ConnectionStringsYamlFile yaml) { var exeName = Path.Combine(UsefulStuff.GetExecutableDirectory().FullName, Process.GetCurrentProcess().ProcessName); if (yaml == null) { Process.Start(exeName); } else { Process.Start(exeName, $"--{nameof(RDMPCommandLineOptions.ConnectionStringsFile)} \"{yaml.FileLoaded.FullName}\""); } }
private void SwitchTo(ConnectionStringsYamlFile yaml) { LaunchNew(yaml); Application.Exit(); }