/// <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();
            }
        }
예제 #2
0
        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();
            }
        }