public async Task ActivateOrConnectInstanceWithCredentialPromptAsync(
            IWin32Window owner,
            IapRdpUrl url)
        {
            if (this.remoteDesktopService.TryActivate(url.Instance))
            {
                // RDP session was active, nothing left to do.
                return;
            }

            // Create an ephemeral settings editor. We do not persist
            // any changes.
            var settingsEditor = new ConnectionSettingsEditor(
                url.Settings,
                _ => { },
                null);

            int selectedOption = this.taskDialog.ShowOptionsTaskDialog(
                owner,
                UnsafeNativeMethods.TD_INFORMATION_ICON,
                "Credentials",
                $"Would you like to generate credentials for {url.Instance.Name} first?",
                null,
                null,
                new[]
            {
                "Yes, generate new credentials",         // Same as pressing 'OK'
                "Enter existing credentials"             // Same as pressing 'Cancel'
            },
                null,
                out bool donotAskAgain);

            if (selectedOption == 0)
            {
                // Generate new credentials using the ephemeral settings editor.
                await this.credentialsService.GenerateCredentialsAsync(
                    owner,
                    url.Instance,
                    settingsEditor,
                    MakeNullIfEmpty(url.Settings.Username))
                .ConfigureAwait(true);
            }
            else if (selectedOption == 1)
            {
                // Cancel - just continue connecting.
            }

            await ConnectInstanceAsync(
                url.Instance,
                settingsEditor.CreateConnectionSettings(url.Instance.Name))
            .ConfigureAwait(true);
        }
Exemplo n.º 2
0
        public void WhenUsernameSetInProject_ProjectValueIsInheritedDownToVm(
            [Values("user", null)]
            string username)
        {
            this.project.Username = username;

            this.instanceA.Username = null;
            this.instanceB.Username = "";

            // Inherited value is shown...
            Assert.AreEqual(username, instanceA.Username);
            Assert.AreEqual(username, instanceB.Username);

            // ...and takes effect.
            Assert.AreEqual(username, instanceA.CreateConnectionSettings("instance").Username);
            Assert.AreEqual(username, instanceB.CreateConnectionSettings("instance").Username);

            Assert.IsFalse(instanceA.ShouldSerializeUsername());
            Assert.IsFalse(instanceB.ShouldSerializeUsername());
        }