/// <summary>
        /// This method will enable the list of services given.
        /// </summary>
        /// <param name="serviceNames">The list of services to enable.</param>
        /// <returns>A task that will be completed once the operation finishes.</returns>
        public async Task EnableServicesAsync(IEnumerable <string> serviceNames)
        {
            ServiceManagementDataSource dataSource = _dataSource.Value;

            if (dataSource == null)
            {
                return;
            }

            try
            {
                await ProgressDialogWindow.PromptUser(
                    dataSource.EnableAllServicesAsync(serviceNames),
                    new ProgressDialogWindow.Options
                {
                    Title         = Resources.ApiManagerEnableServicesTitle,
                    Message       = Resources.ApiManagerEnableServicesProgressMessage,
                    IsCancellable = false
                });
            }
            catch (DataSourceException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: Resources.ApiManagerEnableServicesErrorMessage,
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the app engine to the given project Id.
        /// </summary>
        public static async Task <bool> SetAppRegionAsync(string projectId, IGaeDataSource dataSource)
        {
            string selectedLocation = AppEngineManagementWindow.PromptUser(projectId);

            if (selectedLocation == null)
            {
                Debug.WriteLine("The user cancelled creating a new app.");
                return(false);
            }

            try
            {
                await ProgressDialogWindow.PromptUserAsync(
                    dataSource.CreateApplicationAsync(selectedLocation),
                    new ProgressDialogWindow.Options
                {
                    Title         = Resources.GaeUtilsSetAppEngineRegionProgressTitle,
                    Message       = Resources.GaeUtilsSetAppEngineRegionProgressMessage,
                    IsCancellable = false
                });

                return(true);
            }
            catch (DataSourceException ex)
            {
                UserPromptService.Default.ExceptionPrompt(ex);
                return(false);
            }
        }
Ejemplo n.º 3
0
 private static ProgressDialogWindow GetProgressDialogWindow()
 {
     if (progressDialogWindow == null)
     {
         progressDialogWindow = new ProgressDialogWindow();
         return(progressDialogWindow);
     }
     return(progressDialogWindow);
 }
        /// <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);
            }
        }
        public ProgressDialogWindowViewModel(ProgressDialogWindow owner, ProgressDialogWindow.Options options, Task task)
        {
            _owner = owner;
            _task = task;
            _options = options;

            CancelCommand = new ProtectedCommand(OnCancelCommand, canExecuteCommand: _options.IsCancellable);

            CloseOnTaskCompletion();
            owner.Closed += OnOwnerClosed;
        }
        private async void OnAddCredentialsCommand()
        {
            var request = AddWindowsCredentialWindow.PromptUser(_instance);

            if (request == null)
            {
                return;
            }

            WindowsInstanceCredentials credentials;

            if (request.GeneratePassword)
            {
                var resetCredentialsTask = CreateOrResetCredentials(request.User);
                credentials = await ProgressDialogWindow.PromptUser(
                    resetCredentialsTask,
                    new ProgressDialogWindow.Options
                {
                    Title         = Resources.ResetPasswordProgressTitle,
                    Message       = String.Format(Resources.ResetPasswordProgressMessage, request.User),
                    IsCancellable = false
                });

                if (credentials != null)
                {
                    ShowPasswordWindow.PromptUser(
                        new ShowPasswordWindow.Options
                    {
                        Title    = String.Format(Resources.ShowPasswordWindowTitle, _instance.Name),
                        Message  = String.Format(Resources.ShowPasswordNewPasswordMessage, credentials.User),
                        Password = credentials.Password,
                    });
                }
            }
            else
            {
                credentials = new WindowsInstanceCredentials
                {
                    User     = request.User,
                    Password = request.Password
                };
            }

            if (credentials != null)
            {
                WindowsCredentialsStore.Default.AddCredentialsToInstance(_instance, credentials);
                CredentialsList = WindowsCredentialsStore.Default.GetCredentialsForInstance(_instance);

                EventsReporterWrapper.ReportEvent(AddWindowsCredentialEvent.Create());
            }
        }
Ejemplo n.º 7
0
        private async void OnRenameFileCommand()
        {
            var choosenName = NamePromptWindow.PromptUser(new NamePromptWindow.Options
            {
                InitialName = SelectedItem.LeafName,
                Title       = Resources.GcsFileBrowserRenameFileTitle
            });

            if (choosenName == null)
            {
                return;
            }

            try
            {
                IsLoading = true;

                var newName = GcsPathUtils.Combine(CurrentState.CurrentPath, choosenName);
                Debug.WriteLine($"Renaming {SelectedItem.BlobName} to {newName}");
                await ProgressDialogWindow.PromptUser(
                    _dataSource.MoveFileAsync(
                        bucket: Bucket.Name,
                        sourceName: SelectedItem.BlobName,
                        destName: newName),
                    new ProgressDialogWindow.Options
                {
                    Message       = Resources.GcsFileBrowserRenamingProgressMessage,
                    Title         = Resources.UiDefaultPromptTitle,
                    IsCancellable = false
                });

                EventsReporterWrapper.ReportEvent(GcsFileBrowserRenameFileEvent.Create(CommandStatus.Success));
            }
            catch (DataSourceException ex)
            {
                UserPromptUtils.ErrorPrompt(
                    message: string.Format(Resources.GcsFileBrowserRenameFailedMessage, SelectedItem.LeafName),
                    title: Resources.UiErrorCaption,
                    errorDetails: ex.Message);

                EventsReporterWrapper.ReportEvent(GcsFileBrowserRenameFileEvent.Create(CommandStatus.Failure));
            }
            finally
            {
                IsLoading = false;
            }

            UpdateCurrentState();
        }
        /// <summary>
        /// Open the source file, move to the source line and show tooltip.
        /// If git sha is present at the log entry, try to open the revision of the file.
        /// If the log item does not contain revision id,
        /// fallback to using the assembly version information.
        /// </summary>
        /// <param name="logItem">The log item to search for source file.</param>
        public static async Task NavigateToSourceLineCommandAsync(LogItem logItem)
        {
            await GoogleCloudExtensionPackage.Instance.JoinableTaskFactory.SwitchToMainThreadAsync();

            EnvDTE.Window window = null;
            try
            {
                if (logItem.Entry.Labels?.ContainsKey(SourceContextIdLabel) == true)
                {
                    string sha = logItem.Entry.Labels[SourceContextIdLabel];
                    if (!ValidateGitDependencyHelper.ValidateGitForWindowsInstalled())
                    {
                        return;
                    }
                    window = await ProgressDialogWindow.PromptUserAsync(
                        SearchGitRepoAndOpenFileAsync(sha, logItem.SourceFilePath),
                        s_gitOperationOption);
                }
                else
                {   // If the log item does not contain revision id,
                    // fallback to using assembly version information.
                    var project = FindOrOpenProject(logItem);
                    if (project == null)
                    {
                        Debug.WriteLine($"Failed to find project of {logItem.AssemblyName}");
                        return;
                    }

                    var locatedFilePath = project.FindSourceFile(logItem.SourceFilePath)?.FullName;
                    if (locatedFilePath != null)
                    {
                        window = ShellUtils.Default.Open(locatedFilePath);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                FileItemNotFoundPrompt(ex.FilePath);
                return;
            }
            if (window == null)
            {
                FailedToOpenFilePrompt(logItem.SourceFilePath);
                return;
            }
            logItem.ShowToolTip(window);
        }