private async Task ConnectAsync() { try { var configuration = new RegistryClientConfiguration(Registry); AuthenticationProvider authenticationProvider; if (IsAnonymous) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(Username, Password); } var client = configuration.CreateClient(authenticationProvider); await client.System.PingAsync(); var connection = new RegistryConnection(client, Registry, IsAnonymous, Username, Password); Connection = connection; //Save the connections! Save(); RequestClose(true); } catch (Exception ex) { MessageBox.Show(ex.Message, "Unable to connect"); } }
protected override async void Ok() { var ex = await Executor.ExecuteAsync(async() => { var configuration = new RegistryClientConfiguration(new Uri(Endpoint)); AuthenticationProvider authenticationProvider; if (IsAnonymous) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(Username, Password); } var client = configuration.CreateClient(authenticationProvider); await client.System.PingAsync(); RegistryClient = client; }); if (ex == null) { base.Ok(); } }
private async void btnLogin_Click(object sender, EventArgs e) { Cursor PreviousCursor = this.Cursor; Cursor = Cursors.WaitCursor; Button Sender = sender as Button; GroupBox grp = default; ComboBox comboEndpoint = default; CheckBox chkAnonymous = default; TextBox txtUserName = default; TextBox txtPassword = default; if (Sender == btnBaseLogin) { grp = grpBaseRegistry; comboEndpoint = comboBaseRegistry; chkAnonymous = chkBaseAnonymous; txtUserName = txtBaseUserName; txtPassword = txtBasePassword; _baseRegistryClient = null; } else { grp = grpTargetRegistry; comboEndpoint = comboTargetRegistry; chkAnonymous = chkTargetAnonymous; txtUserName = txtTargetUserName; txtPassword = txtTargetPassword; _targetRegistryClient = null; } if (Sender.Text == "Logout") { foreach (var control in grp.Controls) { if (control.GetType() == typeof(ListBox)) { ((ListBox)control).Items.Clear(); } if (control.GetType() == typeof(TextBox)) { ((TextBox)control).Text = ""; } // ... } _baseRegistryClient = null; Sender.Text = "Login"; comboEndpoint.Focus(); } else { var configuration = new RegistryClientConfiguration(comboEndpoint.SelectedItem?.ToString() ?? comboEndpoint.Text); AuthenticationProvider authenticationProvider; if (chkAnonymous.Checked) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(txtUserName.Text, txtPassword.Text); } var client = configuration.CreateClient(authenticationProvider); try { await client.System.PingAsync(); } catch (UnauthorizedAccessException ex) { // authentication failed MessageBox.Show($"Authentication failed with {ex.Message}", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } catch (RegistryConnectionException ex) { // connection failed MessageBox.Show($"Unable to connect, exception {ex.Message})", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } Sender.Text = "Logout"; if (Sender == btnBaseLogin) { _baseRegistryClient = client; } else { _targetRegistryClient = client; } } Cursor = PreviousCursor; }
private async void btnLogin_Click(object sender, EventArgs e) { Cursor PreviousCursor = this.Cursor; Cursor = Cursors.WaitCursor; if ((sender as Button).Text == "Logout") { Text = $"Not connected"; foreach (var control in grpControls.Controls) { if (control.GetType() == typeof(ListBox)) { ((ListBox)control).Items.Clear(); } if (control.GetType() == typeof(TextBox)) { ((TextBox)control).Text = ""; } // ... } grpControls.Enabled = false; _registryClient = null; btnLogin.Text = "Login"; comboEndpoint.Focus(); } else { var configuration = new RegistryClientConfiguration(comboEndpoint.SelectedItem?.ToString() ?? comboEndpoint.Text); AuthenticationProvider authenticationProvider; if (chkAnonymous.Checked) { authenticationProvider = new AnonymousOAuthAuthenticationProvider(); } else { authenticationProvider = new PasswordOAuthAuthenticationProvider(txtUserName.Text, txtPassword.Text); } var client = configuration.CreateClient(authenticationProvider); try { await client.System.PingAsync(); } catch (UnauthorizedAccessException ex) { // authentication failed MessageBox.Show("Authentication failed", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } catch (RegistryConnectionException ex) { // connection failed MessageBox.Show("Unable to connect", "", MessageBoxButtons.OK, MessageBoxIcon.Error); Cursor = PreviousCursor; return; } Text = $"Connected to endpoint {comboEndpoint.SelectedItem.ToString()}"; grpControls.Enabled = true; btnLogin.Text = "Logout"; _registryClient = client; btnCatalog.Focus(); } Cursor = PreviousCursor; }