private void OnStartInstanceCommand() { try { if (!UserPromptUtils.ActionPrompt( String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPrompt, Instance.Name), String.Format(Resources.CloudExplorerGceStartInstanceConfirmationPromptCaption, Instance.Name), actionCaption: Resources.UiStartButtonCaption)) { Debug.WriteLine($"The user cancelled starting instance {Instance.Name}."); return; } var operation = _owner.DataSource.StartInstance(Instance); UpdateInstanceState(operation); EventsReporterWrapper.ReportEvent(StartGceInstanceEvent.Create(CommandStatus.Success)); } catch (DataSourceException ex) { GcpOutputWindow.Activate(); GcpOutputWindow.OutputLine(String.Format(Resources.CloudExplorerGceFailedToStartInstanceMessage, Instance.Name, ex.Message)); EventsReporterWrapper.ReportEvent(StartGceInstanceEvent.Create(CommandStatus.Failure)); } }
/// <summary> /// Prompts the user about deleting the subscription, then calls the datasource to delete it. /// </summary> private async void OnDeleteSubscriptionCommand() { IsLoading = true; try { try { bool doDelete = UserPromptUtils.ActionPrompt( string.Format(Resources.PubSubDeleteSubscriptionWindowMessage, _subscriptionItem.Name), Resources.PubSubDeleteSubscriptionWindowHeader, actionCaption: Resources.UiDeleteButtonCaption); if (doDelete) { await DataSource.DeleteSubscriptionAsync(_subscriptionItem.FullName); } } catch (DataSourceException e) { Debug.Write(e.Message, "Delete Subscription"); UserPromptUtils.ErrorPrompt( Resources.PubSubDeleteSubscriptionErrorMessage, Resources.PubSubDeleteSubscriptionErrorHeader); } await _owner.Refresh(); } finally { IsLoading = false; } }
/// <summary> /// Prompts the user about deleting the subscription, then calls the datasource to delete it. /// </summary> internal async void OnDeleteSubscriptionCommand() { IsLoading = true; try { bool doDelete = UserPromptUtils.ActionPrompt( string.Format(Resources.PubSubDeleteSubscriptionWindowMessage, _subscriptionItem.Name), Resources.PubSubDeleteSubscriptionWindowHeader, actionCaption: Resources.UiDeleteButtonCaption); if (doDelete) { try { await DataSource.DeleteSubscriptionAsync(_subscriptionItem.FullName); EventsReporterWrapper.ReportEvent(PubSubSubscriptionDeletedEvent.Create(CommandStatus.Success)); } catch (DataSourceException e) { Debug.Write(e.Message, "Delete Subscription"); EventsReporterWrapper.ReportEvent(PubSubSubscriptionDeletedEvent.Create(CommandStatus.Failure)); UserPromptUtils.ErrorPrompt( Resources.PubSubDeleteSubscriptionErrorMessage, Resources.PubSubDeleteSubscriptionErrorHeader, e.Message); } await _owner.Refresh(); } } finally { IsLoading = false; } }
/// <summary> /// This method will check that all given services are enabled and if not will prompt the user to enable the /// necessary services. /// </summary> /// <param name="serviceNames">The services to check.</param> /// <param name="prompt">The prompt to use in the prompt dialog to ask the user for permission to enable the services.</param> /// <returns>A task that will be true if all services where enabled, false if the user cancelled or if the operation failed.</returns> public async Task <bool> EnsureAllServicesEnabledAsync( IEnumerable <string> serviceNames, string prompt) { ServiceManagementDataSource dataSource = _dataSource.Value; if (dataSource == null) { return(false); } try { // Check all services in parallel. IList <string> servicesToEnable = (await dataSource.CheckServicesStatusAsync(serviceNames)) .Where(x => !x.Enabled) .Select(x => x.Name) .ToList(); if (servicesToEnable.Count == 0) { Debug.WriteLine("All the services are already enabled."); return(true); } // Need to enable the services, prompt the user. Debug.WriteLine($"Need to enable the services: {string.Join(",", servicesToEnable)}."); if (!UserPromptUtils.ActionPrompt( prompt: prompt, title: Resources.ApiManagerEnableServicesTitle, actionCaption: Resources.UiEnableButtonCaption)) { return(false); } // Enable all services in parallel. await ProgressDialogWindow.PromptUser( dataSource.EnableAllServicesAsync(servicesToEnable), new ProgressDialogWindow.Options { Title = Resources.ApiManagerEnableServicesTitle, Message = Resources.ApiManagerEnableServicesProgressMessage, IsCancellable = false }); return(true); } catch (DataSourceException ex) { UserPromptUtils.ErrorPrompt( message: Resources.ApiManagerEnableServicesErrorMessage, title: Resources.UiErrorCaption, errorDetails: ex.Message); return(false); } }
private void OnDeleteCredentialsCommand() { if (!UserPromptUtils.ActionPrompt( String.Format(Resources.ManageWindowsCredentialsDeleteCredentialsPromptMessage, SelectedCredentials.User), Resources.ManageWindowsCredentialsDeleteCredentialsPromptTitle, message: Resources.UiOperationCannotBeUndone, actionCaption: Resources.UiDeleteButtonCaption)) { return; } WindowsCredentialsStore.Default.DeleteCredentialsForInstance(_instance, SelectedCredentials); CredentialsList = WindowsCredentialsStore.Default.GetCredentialsForInstance(_instance); }
private static void OpenCurrentVersionProjectPrompt(string assemblyName, string assemblyVersion) { if (UserPromptUtils.ActionPrompt( prompt: String.Format(Resources.LogsViewerPleaseOpenProjectPrompt, assemblyName, assemblyVersion), title: Resources.uiDefaultPromptTitle, message: Resources.LogsViewerAskToOpenProjectMessage)) { ShellUtils.OpenProject(); } else { throw new FileNotFoundException(null); } }
/// <summary> /// Ensures that the opt-in dialog is shown to the user. /// </summary> public static void EnsureAnalyticsOptIn() { var settings = GoogleCloudExtensionPackage.Instance.AnalyticsSettings; if (!settings.DialogShown) { Debug.WriteLine("Showing the opt-in dialog."); settings.OptIn = UserPromptUtils.ActionPrompt( Resources.AnalyticsPromptMessage, Resources.AnalyticsPromptTitle, actionCaption: Resources.UiYesButtonCaption, cancelCaption: Resources.UiNoButtonCaption); settings.DialogShown = true; settings.SaveSettingsToStorage(); } }
private void OnDeleteAccountCommand() { Debug.WriteLine($"Attempting to delete account: {CurrentAccountName}"); if (!UserPromptUtils.ActionPrompt( String.Format(Resources.ManageAccountsDeleteAccountPromptMessage, CurrentAccountName), Resources.ManageAccountsDeleteAccountPromptTitle, actionCaption: Resources.UiDeleteButtonCaption)) { Debug.WriteLine($"The user cancelled the deletion of the account."); return; } AccountsManager.DeleteAccount(CurrentUserAccount.UserAccount); // Refreshing everything. UserAccountsList = LoadUserCredentialsViewModel(); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void OnGenerateConfiguration(object sender, EventArgs e) { ErrorHandlerUtils.HandleExceptions(() => { var selectedProject = SolutionHelper.CurrentSolution.SelectedProject; Debug.WriteLine($"Generating configuration for project: {selectedProject.FullPath}"); var configurationStatus = AppEngineFlexDeployment.CheckProjectConfiguration(selectedProject); // If the app.yaml already exists allow the user to skip its generation to preserve the existing file. if (!configurationStatus.HasAppYaml || UserPromptUtils.ActionPrompt( prompt: Resources.GenerateConfigurationAppYamlOverwriteMessage, title: Resources.GenerateConfigurationOverwritePromptTitle, actionCaption: Resources.UiOverwriteButtonCaption, cancelCaption: Resources.UiSkipFileButtonCaption)) { Debug.WriteLine($"Generating app.yaml for {selectedProject.FullPath}"); if (!AppEngineFlexDeployment.GenerateAppYaml(selectedProject)) { UserPromptUtils.ErrorPrompt( String.Format(Resources.GenerateConfigurationFileGenerationErrorMessage, AppEngineFlexDeployment.AppYamlName), Resources.GenerateConfigurationFileGeneratinErrorTitle); return; } GcpOutputWindow.OutputLine(Resources.GenerateConfigurationAppYamlGeneratedMessage); } // If the Dockerfile already exists allow the user to skip its generation to preserve the existing file. if (!configurationStatus.HasDockerfile || UserPromptUtils.ActionPrompt( prompt: Resources.GenerateConfigurationDockerfileOverwriteMessage, title: Resources.GenerateConfigurationOverwritePromptTitle, actionCaption: Resources.UiOverwriteButtonCaption, cancelCaption: Resources.UiSkipFileButtonCaption)) { Debug.WriteLine($"Generating Dockerfile for {selectedProject.FullPath}"); if (!AppEngineFlexDeployment.GenerateDockerfile(selectedProject)) { UserPromptUtils.ErrorPrompt( String.Format(Resources.GenerateConfigurationFileGenerationErrorMessage, AppEngineFlexDeployment.DockerfileName), Resources.GenerateConfigurationFileGeneratinErrorTitle); return; } GcpOutputWindow.OutputLine(Resources.GenerateConfigurationDockerfileGeneratedMessage); } }); }
private async Task <WindowsInstanceCredentials> CreateOrResetCredentials(string user) { try { Debug.WriteLine("The user requested the password to be generated."); if (!UserPromptUtils.ActionPrompt( prompt: String.Format(Resources.ResetPasswordConfirmationPromptMessage, user, _instance.Name), title: Resources.ResetPasswordConfirmationPromptTitle, message: Resources.UiOperationCannotBeUndone, actionCaption: Resources.UiResetButtonCaption, isWarning: true)) { Debug.WriteLine("The user cancelled resetting the password."); return(null); } Debug.WriteLine($"Resetting the password for the user {user}"); // Check that gcloud is in the right state to invoke the reset credentials method. if (!await VerifyGCloudDependencies()) { Debug.WriteLine("Missing gcloud dependencies for resetting password."); return(null); } var context = new GCloudContext { CredentialsPath = CredentialsStore.Default.CurrentAccountPath, ProjectId = CredentialsStore.Default.CurrentProjectId, AppName = GoogleCloudExtensionPackage.ApplicationName, AppVersion = GoogleCloudExtensionPackage.ApplicationVersion, }; return(await GCloudWrapper.ResetWindowsCredentialsAsync( instanceName : _instance.Name, zoneName : _instance.GetZoneName(), userName : user, context : context)); } catch (GCloudException ex) { UserPromptUtils.ErrorPrompt( message: String.Format(Resources.ResetPasswordFailedPromptMessage, _instance.Name), title: Resources.ResetPasswordConfirmationPromptTitle, errorDetails: ex.Message); return(null); } }
private void OnDeleteVersion() { string confirmationMessage = String.Format( Resources.CloudExplorerGaeDeleteVersionConfirmationPromptMessage, _service.Id, _version.Id); if (!UserPromptUtils.ActionPrompt( confirmationMessage, Resources.CloudExplorerGaeDeleteVersion, actionCaption: Resources.UiYesButtonCaption, cancelCaption: Resources.UiNoButtonCaption)) { Debug.WriteLine("The user cancelled deleting the version."); return; } DeleteVersion(); }
/// <summary> /// Promptes the user if they would like to delete this service. /// </summary> private void OnDeleteService() { string confirmationMessage = String.Format( Resources.CloudExplorerGaeDeleteServiceConfirmationPromptMessage, Service.Id); if (!UserPromptUtils.ActionPrompt( prompt: confirmationMessage, title: Resources.CloudExplorerGaeDeleteService, actionCaption: Resources.UiYesButtonCaption, cancelCaption: Resources.UiNoButtonCaption)) { Debug.WriteLine("The user cancelled deleting the service."); return; } DeleteService(); }
private async void OnDeleteCommand() { if (!UserPromptUtils.ActionPrompt( prompt: Resources.GcsFileBrowserDeletePromptMessage, title: Resources.UiDefaultPromptTitle, actionCaption: Resources.UiDeleteButtonCaption, cancelCaption: Resources.UiCancelButtonCaption)) { return; } try { IsLoading = true; var cancellationTokenSource = new CancellationTokenSource(); var deleteOperationsQueue = await _fileOperationsEngine.StartDeleteOperationsAsync( SelectedItems.Select(x => new GcsItemRef(x.Bucket, x.BlobName)), cancellationTokenSource.Token); GcsFileProgressDialogWindow.PromptUser( caption: Resources.GcsFileBrowserDeletingProgressCaption, message: Resources.GcsFileBrowserDeletingProgressMessage, progressMessage: Resources.GcsFileBrowserDeletingOverallProgressMessage, operations: deleteOperationsQueue.Operations, cancellationTokenSource: cancellationTokenSource); EventsReporterWrapper.ReportEvent(GcsFileBrowserStartDeleteEvent.Create(CommandStatus.Success)); } catch (DataSourceException ex) { UserPromptUtils.ErrorPrompt( message: Resources.GcsFileBrowserDeleteListErrorMessage, title: Resources.UiErrorCaption, errorDetails: ex.Message); EventsReporterWrapper.ReportEvent(GcsFileBrowserStartDeleteEvent.Create(CommandStatus.Failure)); } finally { IsLoading = false; } UpdateCurrentState(); }
private static bool ContinueWhenVersionMismatch(ProjectHelper project, string assemblyVersion) { if (!StackdriverLogsViewerStates.Current.ContinueWithVersionMismatchAssemblyFlag) { var prompt = String.Format( Resources.LogsViewerVersionMismatchPrompt, project.UniqueName, project.Version, assemblyVersion); if (UserPromptUtils.ActionPrompt( prompt: prompt, title: Resources.SourceVersionUtilsVersionMismatchTitle, message: Resources.LogsViewerVersionMissmatchAskIgnoreMessage)) { StackdriverLogsViewerStates.Current.SetContinueWithVersionMismatchAssemblyFlag(); } } return(StackdriverLogsViewerStates.Current.ContinueWithVersionMismatchAssemblyFlag); }
public void TestActionPrompt_PromptsWithTitle() { UserPromptWindow userPrompt = GetWindow(() => _objectUnderTest.ActionPrompt(DefaultPrompt, ExpectedTitle)); string titleResult = userPrompt.Title; Assert.AreEqual(ExpectedTitle, titleResult); }
/// <summary> /// Start the publish operation. /// </summary> public override async void Publish() { if (!ValidateInput()) { Debug.WriteLine("Invalid input cancelled the operation."); return; } var project = _publishDialog.Project; try { var verifyGCloudTask = VerifyGCloudDependencies(); _publishDialog.TrackTask(verifyGCloudTask); if (!await verifyGCloudTask) { Debug.WriteLine("Aborting deployment, no kubectl was found."); return; } var gcloudContext = new GCloudContext { CredentialsPath = CredentialsStore.Default.CurrentAccountPath, ProjectId = CredentialsStore.Default.CurrentProjectId, AppName = GoogleCloudExtensionPackage.ApplicationName, AppVersion = GoogleCloudExtensionPackage.ApplicationVersion, }; var kubectlContextTask = GCloudWrapper.GetKubectlContextForClusterAsync( cluster: SelectedCluster.Name, zone: SelectedCluster.Zone, context: gcloudContext); _publishDialog.TrackTask(kubectlContextTask); using (var kubectlContext = await kubectlContextTask) { var deploymentExistsTask = KubectlWrapper.DeploymentExistsAsync(DeploymentName, kubectlContext); _publishDialog.TrackTask(deploymentExistsTask); if (await deploymentExistsTask) { if (!UserPromptUtils.ActionPrompt( String.Format(Resources.GkePublishDeploymentAlreadyExistsMessage, DeploymentName), Resources.GkePublishDeploymentAlreadyExistsTitle, actionCaption: Resources.UiUpdateButtonCaption)) { return; } } var options = new GkeDeployment.DeploymentOptions { Cluster = SelectedCluster.Name, Zone = SelectedCluster.Zone, DeploymentName = DeploymentName, DeploymentVersion = DeploymentVersion, ExposeService = ExposeService, GCloudContext = gcloudContext, KubectlContext = kubectlContext, Replicas = int.Parse(Replicas), WaitingForServiceIpCallback = () => GcpOutputWindow.OutputLine(Resources.GkePublishWaitingForServiceIpMessage) }; GcpOutputWindow.Activate(); GcpOutputWindow.Clear(); GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeployingToGkeMessage, project.Name)); _publishDialog.FinishFlow(); GkeDeploymentResult result; using (var frozen = StatusbarHelper.Freeze()) using (var animationShown = StatusbarHelper.ShowDeployAnimation()) using (var progress = StatusbarHelper.ShowProgressBar(Resources.GkePublishDeploymentStatusMessage)) using (var deployingOperation = ShellUtils.SetShellUIBusy()) { result = await GkeDeployment.PublishProjectAsync( project.FullPath, options, progress, GcpOutputWindow.OutputLine); } if (result != null) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentSuccessMessage, project.Name)); if (result.DeploymentUpdated) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentUpdatedMessage, options.DeploymentName)); } if (result.DeploymentScaled) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentScaledMessage, options.DeploymentName, options.Replicas)); } if (result.WasExposed) { if (result.ServiceIpAddress != null) { GcpOutputWindow.OutputLine( String.Format(Resources.GkePublishServiceIpMessage, DeploymentName, result.ServiceIpAddress)); } else { GcpOutputWindow.OutputLine(Resources.GkePublishServiceIpTimeoutMessage); } } StatusbarHelper.SetText(Resources.PublishSuccessStatusMessage); if (OpenWebsite && result.WasExposed && result.ServiceIpAddress != null) { Process.Start($"http://{result.ServiceIpAddress}"); } } else { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); } } } catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex)) { GcpOutputWindow.OutputLine(String.Format(Resources.GkePublishDeploymentFailureMessage, project.Name)); StatusbarHelper.SetText(Resources.PublishFailureStatusMessage); _publishDialog.FinishFlow(); } }