/// <summary> /// Event delegate method fired when the <see cref="ManageItemsDialog"/> button is closed. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void ManageItemsDialog_FormClosed(object sender, FormClosedEventArgs e) { if (DialogResult != DialogResult.OK) { return; } if (_instancesHaveChanges) { InstancesList.SaveToFile(); } if (_servicesHaveChanges) { MachinesList.SavetoFile(); } }
/// <summary> /// Event delegate method fired when the <see cref="MySQLInstanceToolStripMenuItem"/> context menu item is clicked. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void MySQLInstanceToolStripMenuItem_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; MonitoredServicesListView.BeginUpdate(); MySqlWorkbenchConnection selectedConnection = null; using (var monitorInstancesDialog = new MonitorMySqlServerInstancesDialog(MachinesList, InstancesList)) { if (monitorInstancesDialog.ShowDialog() == DialogResult.OK) { selectedConnection = monitorInstancesDialog.SelectedWorkbenchConnection; if (selectedConnection != null) { bool connectionAlreadyInInstance = false; // If the selected connection exists for an already monitored instance but it is not its main connection, replace the main connection with this one. foreach (var instance in InstancesList.Where(inst => inst.RelatedConnections.Exists(conn => conn.Id == selectedConnection.Id))) { if (selectedConnection.ConnectionStatus == MySqlWorkbenchConnection.ConnectionStatusType.Unknown) { Exception ex; selectedConnection.TestConnectionSilently(out ex); } instance.WorkbenchConnection = selectedConnection; connectionAlreadyInInstance = true; foreach (ListViewItem lvi in MonitoredInstancesListView.Items) { MySqlInstance existingInstance = lvi.Tag as MySqlInstance; if (existingInstance != instance) { continue; } lvi.Text = instance.HostIdentifier; lvi.SubItems[1].Text = instance.WorkbenchConnection.ConnectionMethod.GetDescription(); lvi.SubItems[2].Text = instance.ConnectionStatusText; break; } break; } if (!connectionAlreadyInInstance) { MySqlInstance newInstance = new MySqlInstance(selectedConnection); InstancesList.Add(newInstance); AddInstance(newInstance, true); InstancesList.SaveToFile(); } } } // Workbench connections may have been edited so we may need to refresh the items in the list. foreach (ListViewItem lvi in MonitoredInstancesListView.Items) { var existingInstance = lvi.Tag as MySqlInstance; if (existingInstance == null || (selectedConnection != null && existingInstance.WorkbenchConnection.Id == selectedConnection.Id)) { continue; } var connectionInDisk = MySqlWorkbench.Connections.GetConnectionForId(existingInstance.WorkbenchConnection.Id); if (connectionInDisk == null || connectionInDisk.Equals(existingInstance.WorkbenchConnection)) { continue; } lvi.Text = connectionInDisk.HostIdentifier; lvi.SubItems[1].Text = connectionInDisk.ConnectionMethod.GetDescription(); lvi.SubItems[2].Text = connectionInDisk.ConnectionStatusText; } InstancesListChanged = monitorInstancesDialog.InstancesListChanged; } MonitoredServicesListView.EndUpdate(); Cursor.Current = Cursors.Default; }