public async Task AmendCredentialsAsync()

in sources/Google.Solutions.IapDesktop.Extensions.Session/ToolWindows/Session/RdpCredentialEditor.cs [264:361]


        public async Task AmendCredentialsAsync(
            RdpCredentialGenerationBehavior allowedBehavior)
        {
            if (this.Settings.RdpNetworkLevelAuthentication.Value
                == RdpNetworkLevelAuthentication.Disabled)
            {
                //
                // When NLA is disabled, RDP credentials don't matter.
                //
                return;
            }
            else if (this.Settings.RdpAutomaticLogon.Value
                == RdpAutomaticLogon.Disabled)
            {
                //
                // Don't even try to collect credentials, because the
                // RDP control needs to prompt again anyway.
                //
                return;
            }
            else if (allowedBehavior == RdpCredentialGenerationBehavior.Force &&
                await IsGrantedPermissionToCreateWindowsCredentialsAsync()
                    .ConfigureAwait(true))
            {
                //
                // Silently generate new credentials right away and
                // skip any further prompts.
                //
                await GenerateCredentialsAsync(true)
                    .ConfigureAwait(false);
                return;
            }

            //
            // Prepare to show a dialog.
            //

            const DialogResult GenerateNewCredentialsResult = (DialogResult)0x1000;
            const DialogResult EnterCredentialsResult = (DialogResult)0x1001;

            var dialogParameters = new TaskDialogParameters(
                "Credentials",
                $"You do not have any saved credentials for {this.Instance.Name}",
                "How do you want to proceed?");
            dialogParameters.Buttons.Add(TaskDialogStandardButton.Cancel);

            if ((allowedBehavior == RdpCredentialGenerationBehavior.Allow ||
                (allowedBehavior == RdpCredentialGenerationBehavior.AllowIfNoCredentialsFound
                    && !this.AreCredentialsComplete)) &&
               await IsGrantedPermissionToCreateWindowsCredentialsAsync().ConfigureAwait(true))
            {
                dialogParameters.Buttons.Add(new TaskDialogCommandLinkButton(
                    "Generate new credentials",
                    GenerateNewCredentialsResult));
            }
            else if (this.AreCredentialsComplete)
            {
                //
                // We have credentials, so just go ahead and connect.
                // 
                return;
            }

            dialogParameters.Buttons.Add(new TaskDialogCommandLinkButton(
                "Enter credentials manually",
                EnterCredentialsResult));

            DialogResult result;
            if (dialogParameters.Buttons.OfType<TaskDialogCommandLinkButton>().Count() > 1)
            {
                result = this.taskDialog.ShowDialog(this.owner, dialogParameters);
            }
            else
            {
                //
                // There's no point in showing a dialog when there's only
                // a single option to choose from.
                //
                result = EnterCredentialsResult;
            }

            switch (result)
            {
                case GenerateNewCredentialsResult:
                    await GenerateCredentialsAsync(false);
                    break;

                case EnterCredentialsResult:
                    PromptForCredentials();
                    break;

                case DialogResult.Cancel:
                    throw new OperationCanceledException();

                default:
                    break;
            }
        }