Example #1
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();
            }
        }
Example #2
0
        private void OnDeleteAccountCommand()
        {
            ExtensionAnalytics.ReportCommand(CommandName.DeleteAccountCommand, CommandInvocationSource.Button);

            Debug.WriteLine($"Attempting to delete account: {CurrentAccountName}");
            if (!UserPromptUtils.YesNoPrompt(
                    String.Format(Resources.ManageAccountsDeleteAccountPromptMessage, CurrentAccountName),
                    Resources.ManageAccountsDeleteAccountPromptTitle))
            {
                ExtensionAnalytics.ReportEvent("DeleteAccountCommandCancelled", "Cancelled");
                Debug.WriteLine($"The user cancelled the deletion of the account.");
                return;
            }

            AccountsManager.DeleteAccount(CurrentUserAccount.UserAccount);
            // Refreshing everything.
            UserAccountsList = LoadUserCredentialsViewModel();
        }
Example #3
0
        /// <summary>
        /// Starts the flow to add a new account to the credentials store.
        /// </summary>
        /// <returns>Will return true if the accound was added, false if the user cancelled.</returns>
        public static async Task <bool> StartAddAccountFlowAsync()
        {
            try
            {
                ExtensionAnalytics.ReportEvent(OAuthEventCategory, "FlowStarted");
                string refreshToken = OAuthLoginFlowWindow.PromptUser(s_extensionCredentials, s_extensionScopes);
                if (refreshToken == null)
                {
                    ExtensionAnalytics.ReportEvent(OAuthEventCategory, "FlowCancelled");
                    Debug.WriteLine("The user cancelled the OAUTH login flow.");
                    return(false);
                }

                var credentials = await GetUserAccountForRefreshToken(refreshToken);

                ExtensionAnalytics.ReportEvent(OAuthEventCategory, "FlowFinished");

                var existingUserAccount = CredentialsStore.Default.GetAccount(credentials.AccountName);
                if (existingUserAccount != null)
                {
                    Debug.WriteLine($"Duplicate account {credentials.AccountName}");
                    UserPromptUtils.ErrorPrompt(
                        string.Format(Resources.ManageAccountsAccountAlreadyExistsPromptMessage, credentials.AccountName),
                        Resources.ManageAccountsAccountAlreadyExistsPromptTitle);
                    return(false);
                }

                // Store the new account and set it as the current account. The project is not changed so if the
                // new account also have access to it, it remains as the current project.
                CredentialsStore.Default.AddAccount(credentials);
                CredentialsStore.Default.CurrentAccount = credentials;
                return(true);
            }
            catch (OAuthException ex)
            {
                ExtensionAnalytics.ReportEvent(OAuthEventCategory, "FlowFailed");
                UserPromptUtils.ErrorPrompt(
                    String.Format(Resources.CloudExplorerGceFailedToGetOauthCredentialsMessage, ex.Message),
                    Resources.CloudExplorerGceFailedToGetOauthCredentialsCaption);
                return(false);
            }
        }
Example #4
0
        private async Task LoadDataWrapper()
        {
            try
            {
                ExtensionAnalytics.ReportEvent(this.GetType().Name, "LoadingData");

                IsLoadingState = true;
                Children.Clear();

                if (CredentialsStore.Default.CurrentAccount == null)
                {
                    Children.Add(s_noCredentialsPlacehodler);
                    return;
                }

                if (CredentialsStore.Default.CurrentProjectId == null)
                {
                    Children.Add(s_noProjectPlaceholder);
                    return;
                }

                Children.Add(LoadingPlaceholder);

                await LoadDataOverride();

                if (Children.Count == 0)
                {
                    Children.Add(NoItemsPlaceholder);
                }
            }
            catch (CloudExplorerSourceException ex)
            {
                Children.Clear();
                Children.Add(ErrorPlaceholder);
            }
            finally
            {
                IsLoadingState = false;
                IsLoadedState  = true;
            }
        }