Exemplo n.º 1
0
        private CloudTarget ToV2CloudTarget()
        {
            string description = string.Empty;

            // If this is a 'vanilla' publish profile, we can display it the same way; note that password can be a series of whitespaces
            if (!string.IsNullOrWhiteSpace(this.selectedPublishProfile.RefreshToken))
            {
                description = string.Format(CultureInfo.InvariantCulture, "Using explicit refresh token - {0}", this.selectedPublishProfile.ServerUri);
            }
            else if (!string.IsNullOrEmpty(this.selectedPublishProfile.Password))
            {
                description = string.Format(CultureInfo.InvariantCulture, "Using clear-text password - {0}", this.selectedPublishProfile.ServerUri);
            }
            else if (!this.selectedPublishProfile.SavedPassword)
            {
                description = string.Format(CultureInfo.InvariantCulture, "Invalid credential configuration - {0}", this.selectedPublishProfile.ServerUri);
            }

            return(CloudTarget.CreateV2Target(
                       this.selectedPublishProfile.ServerUri,
                       description,
                       this.selectedPublishProfile.User,
                       this.selectedPublishProfile.SkipSSLValidation,
                       string.Empty));
        }
Exemplo n.º 2
0
        private async void BtnFinish_Click(object sender, RoutedEventArgs e)
        {
            this.InfoSpinner.Visibility = System.Windows.Visibility.Visible;
            this.InfoMessage.Text       = "Checking cloud connectivity...";
            var targetUrl = this.tbUrl.Text;

            var errorResource = this.DataContext as ErrorResource;

            if (errorResource == null)
            {
                throw new InvalidOperationException("Invalid DataContext");
            }

            try
            {
                var client = new CloudFoundryClient(new Uri(targetUrl), new CancellationToken(), null, (bool)cbIgnoreSSK.IsChecked);

                CloudCredentials creds = new CloudCredentials();
                creds.User     = this.tbUsername.Text;
                creds.Password = this.pbPassword.Password;

                var authContext = await client.Login(creds);

                var info = await client.Info.GetInfo();

                this.version = info.ApiVersion;

                this.cloudTarget = CloudTarget.CreateV2Target(
                    new Uri(this.tbUrl.Text),
                    this.tbDescription.Text,
                    this.tbUsername.Text,
                    (bool)this.cbIgnoreSSK.IsChecked,
                    this.version);

                this.credentials  = creds;
                this.DialogResult = true;
                this.Close();
            }
            catch (Exception ex)
            {
                this.InfoSpinner.Visibility = System.Windows.Visibility.Hidden;
                this.InfoMessage.Text       = string.Empty;
                var errorMessages = new List <string>();
                ErrorFormatter.FormatExceptionMessage(ex, errorMessages);
                errorResource.ErrorMessage = string.Join(Environment.NewLine, errorMessages.ToArray());
                errorResource.HasErrors    = true;
            }
        }