/// <summary> /// Maps the debug connection name we got from the project properties (if any) to /// one of our Raspberry connections. If no name is specified, we'll /// use the default connection or prompt the user to create a connection. /// We'll display an error if a connection is specified and but doesn't exist. /// </summary> /// <param name="projectProperties">The project properties.</param> /// <returns>The connection or <c>null</c> when one couldn't be located.</returns> public static ConnectionInfo GetDebugConnectionInfo(ProjectProperties projectProperties) { Covenant.Requires <ArgumentNullException>(projectProperties != null, nameof(projectProperties)); var existingConnections = PackageHelper.ReadConnections(); var connectionInfo = (ConnectionInfo)null; if (string.IsNullOrEmpty(projectProperties.DebugConnectionName)) { connectionInfo = existingConnections.SingleOrDefault(info => info.IsDefault); if (connectionInfo == null) { if (MessageBoxEx.Show( $"Raspberry connection information required. Would you like to create a connection now?", "Raspberry Connection Required", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) == DialogResult.No) { return(null); } connectionInfo = new ConnectionInfo(); var connectionDialog = new ConnectionDialog(connectionInfo, edit: false, existingConnections: existingConnections); if (connectionDialog.ShowDialog() == DialogResult.OK) { existingConnections.Add(connectionInfo); PackageHelper.WriteConnections(existingConnections, disableLogging: true); } else { return(null); } } } else { connectionInfo = existingConnections.SingleOrDefault(info => info.Name.Equals(projectProperties.DebugConnectionName, StringComparison.InvariantCultureIgnoreCase)); if (connectionInfo == null) { MessageBoxEx.Show( $"The [{projectProperties.DebugConnectionName}] Raspberry connection does not exist.\r\n\r\nPlease add the connection via:\r\n\r\nTools/Options/Raspberry Debugger", "Cannot Find Raspberry Connection", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } } return(connectionInfo); }
/// <summary> /// Handles <b>Edit</b> button clicks. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The arguments.</param> private void editButton_Click(object sender, EventArgs args) { if (SelectedConnection == null) { return; } var connectionDialog = new ConnectionDialog(SelectedConnection, edit: true, connections); if (connectionDialog.ShowDialog(dialogParent) == DialogResult.OK) { SaveConnections(); ReloadConnections(); } }
/// <summary> /// Handles <b>Add</b> button clicks. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The arguments.</param> private void addButton_Click(object sender, EventArgs args) { var newConnection = new ConnectionInfo() { ConnectionsPanel = this }; var connectionDialog = new ConnectionDialog(newConnection, edit: false, connections); if (connectionDialog.ShowDialog(dialogParent) == DialogResult.OK) { connections.Add(newConnection); SaveConnections(); ReloadConnections(); } }