/// <summary> /// Event handler handling the Click event of the connect button /// </summary> private void connectButton_Click(object sender, EventArgs e) { if (!Uri.IsWellFormedUriString(urlTextBox.Text, UriKind.Absolute)) { MessageBox.Show("Url is not valid"); return; } connectButton.Text = "Connecting..."; connectButton.Enabled = false; urlTextBox.Enabled = false; try { Connection = new EvolutionConnection(urlTextBox.Text); ShowDisconnectButton(); } catch (WebException ex) { var response = ex.Response as HttpWebResponse; if (response == null) throw ex; // 401 status suggests that username/password authentication may be required if (response.StatusCode == HttpStatusCode.Unauthorized) passwordPanel.Visible = true; else if (response.StatusCode == HttpStatusCode.NotFound) { MessageBox.Show("The requested url could not be found"); return; } else if (response.StatusCode != HttpStatusCode.Forbidden) { ResetConnectionArea(); throw ex; } ResetCredentialsArea(); } }
/// <summary> /// Creates a new ConnectionChangedEventArgs object /// </summary> /// <param name="newConnection">The new connection </param> /// <param name="oldConnection">The previous connection</param> public ConnectionChangedEventArgs(EvolutionConnection newConnection, EvolutionConnection oldConnection) { NewConnection = newConnection; OldConnection = oldConnection; }
/// <summary> /// Resets the Credentials Area to it's default state /// </summary> private void ResetCredentialsArea() { credentialsFlowLayoutPanel.Visible = true; ShowDisconnectButton(); //Clear current credentials and enable the text boxes userNameTextBox.Clear(); userNameTextBox.Enabled = true; apiKeyTextBox.Clear(); apiKeyTextBox.Enabled = true; passwordTextBox.Clear(); passwordTextBox.Enabled = true; ResetLoginButton(); Connection = null; }
/// <summary> /// Resets the Connection Area to it's default state /// </summary> private void ResetConnectionArea() { connectButton.Text = "Connect"; connectButton.Enabled = true; connectButton.Visible = true; disconnectButton.Enabled = true; disconnectButton.Visible = false; urlTextBox.Enabled = true; credentialsFlowLayoutPanel.Visible = false; passwordPanel.Visible = false; urlTextBox.Clear(); Connection = null; }
/// <summary> /// Event handler for the Click event of the login button /// </summary> private void loginButton_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(userNameTextBox.Text)) { MessageBox.Show("Username must not be blank"); return; } if (String.IsNullOrEmpty(apiKeyTextBox.Text)) { MessageBox.Show("API Key must not be blank"); return; } if (passwordPanel.Visible && String.IsNullOrEmpty(passwordTextBox.Text)) { MessageBox.Show("Password must not be blank"); return; } loginButton.Text = "Logging in"; loginButton.Enabled = false; try { //If password panel is visible, use network credentials with the request if (passwordPanel.Visible) { var credentials = new NetworkCredential(userNameTextBox.Text, passwordTextBox.Text); Connection = new EvolutionConnection(urlTextBox.Text, credentials, apiKeyTextBox.Text); } else Connection = new EvolutionConnection(urlTextBox.Text, userNameTextBox.Text, apiKeyTextBox.Text); userNameTextBox.Enabled = false; apiKeyTextBox.Enabled = false; passwordTextBox.Enabled = false; loginButton.Visible = false; } catch (WebException ex) { ResetLoginButton(); var response = ex.Response as HttpWebResponse; if (response == null) throw ex; // 401 status suggests that username/password authentication may be required if (response.StatusCode == HttpStatusCode.Unauthorized ) MessageBox.Show("The Username and Password provided were not correct", "Unable to connect"); // 403 status suggests that API Key authentication may be required else if (response.StatusCode == HttpStatusCode.Forbidden) MessageBox.Show(@"Unable to connect to the Telligent Evolution platform API this may occur because: * The REST API is not enabled * The Username you supplied does not have permisison to use the REST API * The API Key you entered was invalid ", "Unable to connect"); } }
/// <summary> /// Creates a new GroupApplicationService object /// </summary> /// <param name="connection"> /// The EvolutionConnection used to access the Telligent /// Evolution Platform REST API /// </param> public GroupApplicationService(EvolutionConnection connection) { Connection = connection; }