/// <summary> /// Opens the Add Data Connection Dialog with the data source being a MySQL database and the server field /// set to the ip of the intance. If the proper dependencies are not installed (for the MySQL database) /// the user will be prompted to install them before they can continue. /// </summary> private void OpenDataConnectionDialog() { // Create a data connection dialog and add all possible data sources to it. DataConnectionDialogFactory factory = (DataConnectionDialogFactory)Package.GetGlobalService(typeof(DataConnectionDialogFactory)); DataConnectionDialog dialog = factory.CreateConnectionDialog(); dialog.AddAllSources(); // Check if the MySQL data source exists. // TODO(talarico): This is added when the user has MySQL for Visual Studio installed. We should also // probably check for the needed pieces in the MySQL Connector/Net. if (dialog.AvailableSources.Contains(CloudSqlUtils.DataSource)) { EventsReporterWrapper.ReportEvent(OpenCloudSqlConnectionDialogEvent.Create()); // Pre select the MySQL data source. dialog.SelectedSource = CloudSqlUtils.DataSource; // Create the connection string to pre populate the server address in the dialog. InstanceItem instance = GetItem(); var serverAddress = String.IsNullOrEmpty(instance.IpAddress) ? instance.Ipv6Address : instance.IpAddress; dialog.DisplayConnectionString = CloudSqlUtils.FormatServerConnectionString(serverAddress); bool addDataConnection = dialog.ShowDialog(); if (addDataConnection) { // Create a name for the data connection var parsedConnection = CloudSqlUtils.ParseConnection(dialog.DisplayConnectionString); string connectionName; if (parsedConnection.Server == serverAddress) { connectionName = $"{Instance.Project}[{Instance.Name}][{parsedConnection.Database}]"; } else { connectionName = $"{parsedConnection.Server}[{parsedConnection.Database}]"; } // Add the MySQL data connection to the data explorer DataExplorerConnectionManager manager = (DataExplorerConnectionManager)Package.GetGlobalService(typeof(DataExplorerConnectionManager)); manager.AddConnection(connectionName, CloudSqlUtils.DataProvider, dialog.EncryptedConnectionString, true); } } else { // MySQL for Visual Studio isn't installed, prompt the user to install it. MySQLInstallerWindow.PromptUser(); } }
private void OpenDataConnectionDialog() { ExtensionAnalytics.ReportCommand(CommandName.OpenMySQLDataConnectionDialog, CommandInvocationSource.Button); // Create a data connection dialog and add all possible data sources to it. DataConnectionDialogFactory factory = (DataConnectionDialogFactory)Package.GetGlobalService(typeof(DataConnectionDialogFactory)); DataConnectionDialog dialog = factory.CreateConnectionDialog(); dialog.AddAllSources(); // Check if the MySQL data source exists. // TODO(talarico): This is added when the user has MySQL for Visual Studio installed. We should also // probably check for the needed pieces in the MySQL Connector/Net. if (dialog.AvailableSources.Contains(MySQLUtils.MySQLDataSource)) { // Pre select the MySQL data source. dialog.SelectedSource = MySQLUtils.MySQLDataSource; // Create the connection string to pre populate the server address in the dialog. MySqlConnectionStringBuilder builderPrePopulate = new MySqlConnectionStringBuilder(); InstanceItem instance = _item.Value; builderPrePopulate.Server = String.IsNullOrEmpty(instance.IpAddress) ? instance.Ipv6Address : instance.IpAddress; dialog.DisplayConnectionString = builderPrePopulate.GetConnectionString(false); bool addDataConnection = dialog.ShowDialog(); if (addDataConnection) { ExtensionAnalytics.ReportCommand(CommandName.AddMySQLDataConnection, CommandInvocationSource.Button); // Create a name for the data connection MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder(dialog.DisplayConnectionString); string database = $"{_instance.Project}[{builder.Server}][{builder.Database}]"; // Add the MySQL data connection to the data explorer DataExplorerConnectionManager manager = (DataExplorerConnectionManager)Package.GetGlobalService(typeof(DataExplorerConnectionManager)); manager.AddConnection(database, MySQLUtils.MySQLDataProvider, dialog.EncryptedConnectionString, true); } } else { // MySQL for Visual Studio isn't installed, prompt the user to install it. ExtensionAnalytics.ReportEvent("MySQLForVisualStudio", "Missing"); MySQLInstallerWindow.PromptUser(); } }
/// <summary> /// Implements <see cref="IWizard.RunStarted"/> /// </summary> protected void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { IOleServiceProvider oleServiceProvider = automationObject as IOleServiceProvider; ServiceProvider serviceProvider = (oleServiceProvider != null) ? new ServiceProvider(oleServiceProvider) : null; DataConnectionDialogFactory dialogFactory = GetService <DataConnectionDialogFactory>(serviceProvider); Debug.Assert(dialogFactory != null, "Can't get DataConnectionDialogFactory!"); System.Data.IDbConnection dbConn; DataConnectionDialog dialog = dialogFactory.CreateConnectionDialog(); dialog.AddAllSources(); DataConnection dataConn = dialog.ShowDialog(false); if (dataConn != null) { if ((dbConn = dataConn.ConnectionSupport.ProviderObject as System.Data.IDbConnection) == null) { // show error return; } DataProviderManager manager = GetService <DataProviderManager>(serviceProvider); if (manager != null) { DataProvider provider = manager.GetDataProvider(dataConn.Provider); string invariantName = provider.GetProperty("InvariantName") as string; IList <string> schemaList = DcilSchema.GetAvailableSchemaNames(dbConn, invariantName); string selectedSchema = null; switch (schemaList.Count) { case 1: selectedSchema = schemaList[0]; break; default: // Allow this for an empty list selectedSchema = SchemaSelector.SelectSchema(serviceProvider, schemaList); break; } if (!string.IsNullOrEmpty(selectedSchema)) { DcilSchema schema = DcilSchema.FromSchemaName(selectedSchema, dbConn, invariantName); StringBuilder stringBuilder = new StringBuilder(); string replacementString = null; using (MemoryStream ms = new MemoryStream()) { DcilSchema.Serialize(schema, ms); ms.Seek(0, SeekOrigin.Begin); StreamReader sr = new StreamReader(ms); replacementString = sr.ReadToEnd(); } replacementsDictionary.Add("$DcilFile$", replacementString); myAddToProject = true; } } } }