Example #1
0
        /// <summary>
        /// Shows the tool window when the menu item is clicked.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void ShowToolWindow(object sender, EventArgs e)
        {
            ExtensionAnalytics.EnsureAnalyticsOptIn();

            ExtensionAnalytics.ReportCommand(CommandName.OpenManageAccountsDialog, CommandInvocationSource.ToolsMenu);

            ManageAccountsWindow.PromptUser();
        }
Example #2
0
        private void OnSetAsCurrentAccountCommand()
        {
            ExtensionAnalytics.ReportCommand(CommandName.SetCurrentAccountCommand, CommandInvocationSource.Button);

            Debug.WriteLine($"Setting current account: {CurrentAccountName}");
            CredentialsStore.Default.CurrentAccount = CurrentUserAccount.UserAccount;
            _owner.Close();
        }
Example #3
0
        private void OnOpenWebsite()
        {
            ExtensionAnalytics.ReportCommand(CommandName.OpenWebsiteForGceInstanceCommand, CommandInvocationSource.Button);

            var url = Instance.GetDestinationAppUri();

            Debug.WriteLine($"Opening Web Site: {url}");
            Process.Start(url);
        }
Example #4
0
        private void OnOpenConCloudConsoleCommand()
        {
            ExtensionAnalytics.ReportCommand(CommandName.OpenWebsiteForGcsBucket, CommandInvocationSource.Button);

            var url = $"https://console.cloud.google.com/storage/browser/{_bucket.Name}/?project={CredentialsStore.Default.CurrentProjectId}";

            Debug.WriteLine($"Starting bucket browsing at: {url}");
            Process.Start(url);
        }
Example #5
0
        private void OpenDownload()
        {
            ExtensionAnalytics.ReportCommand(CommandName.OpenMySQLInstallerDownload, CommandInvocationSource.Button);

            var url = $"https://dev.mysql.com/downloads/installer/";

            Debug.WriteLine($"Opening page to download MySQL Installer: {url}");
            Process.Start(url);
            _owner.Close();
        }
Example #6
0
        private async void OnAddAccountCommand()
        {
            ExtensionAnalytics.ReportCommand(CommandName.AddAccountCommand, CommandInvocationSource.Button);

            Debug.WriteLine("Stating the oauth login flow.");
            if (await AccountsManager.StartAddAccountFlowAsync())
            {
                Debug.WriteLine($"The user logged in: {CredentialsStore.Default.CurrentAccount.AccountName}");
                _owner.Close();
            }
        }
Example #7
0
        public void DoucleClickedItem(UserAccountViewModel userAccount)
        {
            ExtensionAnalytics.ReportCommand(CommandName.DoubleClickedAccountCommand, CommandInvocationSource.ListItem);

            if (userAccount.IsCurrentAccount)
            {
                return;
            }

            CredentialsStore.Default.CurrentAccount = userAccount.UserAccount;
            _owner.Close();
        }
Example #8
0
        public CommonDialogWindowBase(string title, double width, double height)
        {
            Title  = title;
            Width  = width;
            Height = height;

            // Common settings to all dialogs.
            ResizeMode            = System.Windows.ResizeMode.NoResize;
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            ShowInTaskbar         = false;

            // Report that this window is opened.
            ExtensionAnalytics.ReportScreenView(this);
        }
Example #9
0
        private void OnOnlyWindowsClicked()
        {
            if (_windowsOnlyButton.IsChecked)
            {
                ExtensionAnalytics.ReportCommand(CommandName.ShowAllGceInstancesCommand, CommandInvocationSource.Button);
            }
            else
            {
                ExtensionAnalytics.ReportCommand(CommandName.ShowOnlyWindowsGceInstancesCommand, CommandInvocationSource.Button);
            }

            _windowsOnlyButton.IsChecked        = !_windowsOnlyButton.IsChecked;
            ActualRoot.ShowOnlyWindowsInstances = _windowsOnlyButton.IsChecked;
        }
Example #10
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 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CloudExplorerToolWindow"/> class.
        /// </summary>
        public CloudExplorerToolWindow() : base(null)
        {
            SetCaption();

            _selectionUtils = new SelectionUtils(this);

            var model = new CloudExplorerViewModel(_selectionUtils);

            Content = new CloudExplorerToolWindowControl(_selectionUtils)
            {
                DataContext = model,
            };

            CredentialsStore.Default.CurrentAccountChanged += OnCurrentAccountChanged;
            CredentialsStore.Default.Reset += OnCurrentAccountChanged;

            ExtensionAnalytics.ReportScreenView(this);
        }
Example #12
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 #13
0
        private void OnGetPublishSettings()
        {
            ExtensionAnalytics.ReportCommand(CommandName.GetPublishSettingsForGceInstance, CommandInvocationSource.Button);

            Debug.WriteLine($"Generating Publishing settings for {Instance.Name}");

            var storePath = PromptForPublishSettingsPath(Instance.Name);

            if (storePath == null)
            {
                Debug.WriteLine("User canceled saving the pubish settings.");
                return;
            }

            var profile = Instance.GeneratePublishSettings();

            File.WriteAllText(storePath, profile);
            GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGcePublishingSettingsSavedMessage, storePath));
        }
Example #14
0
        /// <summary>
        /// Perform all of the setting alterantions necessary before finally saving the settings
        /// to storage.
        /// </summary>
        public override void SaveSettingsToStorage()
        {
            if (OptIn)
            {
                if (ClientId == null)
                {
                    Debug.WriteLine("Creating new Client ID");
                    ClientId = Guid.NewGuid().ToString();
                }
            }
            else
            {
                ClientId = null;
            }

            ExtensionAnalytics.AnalyticsOptInStateChanged();

            base.SaveSettingsToStorage();
        }
Example #15
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 #16
0
        /// <summary>
        /// Shows the tool window when the menu item is clicked.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void ShowToolWindow(object sender, EventArgs e)
        {
            ExtensionAnalytics.EnsureAnalyticsOptIn();

            ExtensionAnalytics.ReportCommand(CommandName.OpenCloudExplorerToolWindow, CommandInvocationSource.ToolsMenu);

            // Get the instance number 0 of this tool window. This window is single instance so this instance
            // is actually the only one.
            // The last flag is set to true so that if the tool window does not exists it will be created.
            ToolWindowPane window = _package.FindToolWindow(typeof(CloudExplorerToolWindow), 0, true);

            if (window?.Frame == null)
            {
                throw new NotSupportedException("Cannot create tool window");
            }

            IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
        }
Example #17
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;
            }
        }
Example #18
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // An remember the package.
            Instance = this;

            // Register the command handlers.
            CloudExplorerCommand.Initialize(this);
            ManageAccountsCommand.Initialize(this);

            // Activity log utils, to aid in debugging.
            ActivityLogUtils.Initialize(this);
            ActivityLogUtils.LogInfo("Starting Google Cloud Tools.");

            // Analytics reporting.
            ExtensionAnalytics.ReportStartSession();

            _dteInstance = (DTE)Package.GetGlobalService(typeof(DTE));
            _dteInstance.Events.DTEEvents.OnBeginShutdown += DTEEvents_OnBeginShutdown;
        }
Example #19
0
        private void OnManageAccountsCommand()
        {
            ExtensionAnalytics.ReportCommand(CommandName.OpenManageAccountsDialog, CommandInvocationSource.Button);

            ManageAccountsWindow.PromptUser();
        }
Example #20
0
        private void OnRefresh()
        {
            ExtensionAnalytics.ReportCommand(CommandName.RefreshDataSource, CommandInvocationSource.Button);

            RefreshSources();
        }
Example #21
0
        private void OnOpenTerminalServerSessionCommand()
        {
            ExtensionAnalytics.ReportCommand(CommandName.OpenTerminalServerSessionForGceInstanceCommand, CommandInvocationSource.Button);

            Process.Start("mstsc", $"/v:{Instance.GetPublicIpAddress()}");
        }
Example #22
0
 private void DTEEvents_OnBeginShutdown()
 {
     ActivityLogUtils.LogInfo("Shutting down Google Cloud Tools.");
     ExtensionAnalytics.ReportEndSession();
 }
Example #23
0
 private void OnCloseCommand()
 {
     ExtensionAnalytics.ReportCommand(CommandName.OAuthFlowCancel, CommandInvocationSource.Button);
     _owner.CancelOperation();
 }