protected override async Task <IEnumerable <CloudItem> > UpdateChildren()
        {
            CloudFoundryClient client = new CloudFoundryClient(this.target.TargetUrl, this.CancellationToken, null, this.target.IgnoreSSLErrors);

            string password = CloudCredentialsManager.GetPassword(this.target.TargetUrl, this.target.Email);

            var authenticationContext = await client.Login(new CloudCredentials()
            {
                User     = this.target.Email,
                Password = password
            });

            List <Organization> result = new List <Organization>();

            PagedResponseCollection <ListAllOrganizationsResponse> orgs = await client.Organizations.ListAllOrganizations();

            while (orgs != null && orgs.Properties.TotalResults != 0)
            {
                foreach (var org in orgs)
                {
                    result.Add(new Organization(org, client));
                }

                orgs = await orgs.GetNextPage();
            }

            return(result);
        }
Esempio n. 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)));
        }