private void AddTargetButton_Click(object sender, RoutedEventArgs e)
        {
            Window parent    = Window.GetWindow(this);
            var    loginForm = new LogOnForm(parent);

            var result = loginForm.ShowDialog();

            if (result == true)
            {
                var target = loginForm.CloudTarget;

                if (target != null)
                {
                    CloudTargetManager.SaveTarget(target);
                    CloudCredentialsManager.Save(target.TargetUrl, target.Email, loginForm.Credentials.Password);

                    this.ReloadTargets();
                }
            }
        }
예제 #2
0
        private async Task RefreshClient()
        {
            this.RefreshingClient = true;

            try
            {
                if (this.selectedPublishProfile.ServerUri == null)
                {
                    throw new InvalidOperationException("Please provide a target.");
                }

                this.LastRefreshTarget = PublishProfileRefreshTarget.Client;

                this.client = new CloudFoundryClient(
                    this.selectedPublishProfile.ServerUri,
                    this.cancellationToken,
                    null,
                    this.selectedPublishProfile.SkipSSLValidation);

                AuthenticationContext authenticationContext = null;
                if (!string.IsNullOrWhiteSpace(this.selectedPublishProfile.RefreshToken))
                {
                    authenticationContext = await this.client.Login(this.selectedPublishProfile.RefreshToken);
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(this.selectedPublishProfile.Password))
                    {
                        authenticationContext = await this.client.Login(new CloudCredentials()
                        {
                            User     = this.selectedPublishProfile.User,
                            Password = this.selectedPublishProfile.Password
                        });
                    }
                    else if (this.selectedPublishProfile.SavedPassword == true)
                    {
                        string password = CloudCredentialsManager.GetPassword(
                            this.selectedPublishProfile.ServerUri,
                            this.selectedPublishProfile.User);

                        authenticationContext = await this.client.Login(new CloudCredentials()
                        {
                            User     = this.selectedPublishProfile.User,
                            Password = password
                        });
                    }
                    else
                    {
                        throw new InvalidOperationException(@"Credentials are not configured correctly in your publish profile.
Either set CFSavedPassword to true and use credentials saved in the Windows Credential Manager (recommended), or set a CFPassword or CFRefreshToken.
Please note that credentials are saved automatically in the Windows Credential Manager if you use the Cloud Foundry Visual Studio Extensions to connect to a cloud.");
                    }
                }
            }
            finally
            {
                this.RefreshingClient = false;
            }

            Parallel.Invoke(
                new Action(() => this.Refresh(PublishProfileRefreshTarget.Organizations)),
                new Action(() => this.Refresh(PublishProfileRefreshTarget.Stacks)),
                new Action(() => this.Refresh(PublishProfileRefreshTarget.Buildpacks)),
                new Action(() => this.Refresh(PublishProfileRefreshTarget.SharedDomains)));
        }