public bool IsOperationSupported( Guid source, CommandID command, object context) { if (command == null) { throw new ArgumentNullException("command"); } if (command.Equals(DeployCommand)) { IVsDataExplorerConnection explorerConnection = context as IVsDataExplorerConnection; if (explorerConnection == null) { throw new ArgumentException(); } RegistryKey key = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Company\DeployTechnology"); if (key == null) { return(false); } key.Close(); } return(true); }
internal void ShowDialog() { var dialog = _dialogFactory.CreateConnectionDialog(); if (dialog == null) { throw new InvalidOperationException(Resources.EntityDataConnectionDialog_NoDataConnectionDialog); } RaiseBeforeAddSourcesEvent(); dialog.AddSources(IsSupportedProvider); RaiseAfterAddSourcesEvent(); dialog.LoadSourceSelection(); RaiseBeforeShowDialogEvent(); var dc = dialog.ShowDialog(true); RaiseAfterShowDialogEvent(); if (dialog.SaveSelection && dc != null) { dialog.SaveProviderSelections(); dialog.SaveSourceSelection(); } if (dc != null) { try { SelectedExplorerConnection = _dataExplorerConnectionManager.AddConnection( null, dc.Provider, dc.EncryptedConnectionString, true); SelectedConnection = dc; } catch (XmlException xmlException) { // AddConnection() call above can throw an XmlException if the connection cannot be made throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.EntityDataConnectionDialog_DataConnectionInvalid, xmlException.Message), xmlException); } } }
/// <summary> /// Event delegate method fired when the <see cref="ConnectDialog"/> is being closed. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void ConnectDialogNew_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == DialogResult.Cancel) { return; } if (GetConnection(true, true) == null) { e.Cancel = true; return; } if (!AddToServerExplorerCheckBox.Checked) { return; } // Check if the Server Explorer connection name is not empty, and if so prompt the user to use a suggested connection name var validateConnectionName = true; var serverExplorerConnectionName = ConnectionNameTextBox.Text.Trim(); if (string.IsNullOrEmpty(serverExplorerConnectionName)) { serverExplorerConnectionName = GetProposedServerExplorerConnectionName(null); var infoResult = InfoDialog.ShowDialog(InfoDialogProperties.GetYesNoDialogProperties(InfoDialog.InfoType.Warning, Resources.ConnectDialog_EmptyConnectionNameTitle, Resources.ConnectDialog_EmptyConnectionNameDetail, string.Format(Resources.ConnectDialog_EmptyConnectionNameSubDetail, serverExplorerConnectionName))); if (infoResult.DialogResult == DialogResult.No) { e.Cancel = true; return; } validateConnectionName = false; } // Validate if there is an existing connection in the Server Explorer with the same name, if so prompt the user for an action. IVsDataExplorerConnection existingConnection = null; if (validateConnectionName) { existingConnection = MySqlDataProviderPackage.Instance.GetServerExplorerConnection(serverExplorerConnectionName); if (existingConnection != null) { var newConnectionName = GetProposedServerExplorerConnectionName(serverExplorerConnectionName); var infoProperties = InfoDialogProperties.GetInfoDialogProperties(InfoDialog.InfoType.Warning, CommandAreaProperties.ButtonsLayoutType.Generic3Buttons, Resources.ConnectDialog_ConnectionAlreadyExistsTitle, string.Format(Resources.ConnectDialog_ConnectionAlreadyExistsDetail, serverExplorerConnectionName), string.Format(Resources.ConnectDialog_ConnectionAlreadyExistsSubDetail, newConnectionName), string.Format(Resources.ConnectDialog_ConnectionAlreadyExistsMoreInfo, newConnectionName, serverExplorerConnectionName)); infoProperties.FitTextStrategy = InfoDialog.FitTextsAction.IncreaseDialogWidth; infoProperties.WordWrapMoreInfo = false; infoProperties.CommandAreaProperties.Button1Text = Resources.ConnectDialog_Rename; infoProperties.CommandAreaProperties.Button1DialogResult = DialogResult.Yes; infoProperties.CommandAreaProperties.Button2Text = Resources.ConnectDialog_Replace; infoProperties.CommandAreaProperties.Button1DialogResult = DialogResult.No; infoProperties.CommandAreaProperties.Button3Text = Resources.ConnectDialog_Cancel; infoProperties.CommandAreaProperties.Button3DialogResult = DialogResult.Cancel; var infoResult = InfoDialog.ShowDialog(infoProperties); switch (infoResult.DialogResult) { case DialogResult.Yes: // Set values needed to Rename the connection. serverExplorerConnectionName = newConnectionName; existingConnection = null; break; case DialogResult.No: // Do nothing, the serverExplorerConnectionName and existingConnection variables have the values needed to Replace. break; case DialogResult.Cancel: // Abort the closing of the dialog. e.Cancel = true; return; } } } // Create the Server Explorer connection MySqlDataProviderPackage.Instance.AddServerExplorerConnection(serverExplorerConnectionName, ConnectionString, existingConnection); }
internal void ShowDialog() { var dialog = _dialogFactory.CreateConnectionDialog(); if (dialog == null) { throw new InvalidOperationException(Resources.EntityDataConnectionDialog_NoDataConnectionDialog); } RaiseBeforeAddSourcesEvent(); dialog.AddSources(IsSupportedProvider); RaiseAfterAddSourcesEvent(); dialog.LoadSourceSelection(); RaiseBeforeShowDialogEvent(); var dc = dialog.ShowDialog(true); RaiseAfterShowDialogEvent(); if (dialog.SaveSelection && dc != null) { dialog.SaveProviderSelections(); dialog.SaveSourceSelection(); } if (dc != null) { try { SelectedExplorerConnection = _dataExplorerConnectionManager.AddConnection( null, dc.Provider, dc.EncryptedConnectionString, true); SelectedConnection = dc; } catch (XmlException xmlException) { // AddConnection() call above can throw an XmlException if the connection cannot be made throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, Resources.EntityDataConnectionDialog_DataConnectionInvalid, xmlException.Message), xmlException); } } }