// Handle the OnLoginEntered event from the login UI // LoginEventArgs contains the username, password, and domain that were entered private void LoginEntered(object sender, LoginEventArgs e) { // Make sure the task completion source has all the information needed if (_loginTaskCompletionSrc == null || _loginTaskCompletionSrc.Task == null || _loginTaskCompletionSrc.Task.AsyncState == null) { return; } try { // Get the associated CredentialRequestInfo (will need the URI of the service being accessed) CredentialRequestInfo requestInfo = _loginTaskCompletionSrc.Task.AsyncState as CredentialRequestInfo; // Create a new network credential using the values entered by the user var netCred = new System.Net.NetworkCredential(e.Username, e.Password, e.Domain); // Create a new ArcGIS network credential to hold the network credential and service URI var arcgisCred = new ArcGISNetworkCredential { Credentials = netCred, ServiceUri = requestInfo.ServiceUri }; // Set the task completion source result with the ArcGIS network credential // AuthenticationManager is waiting for this result and will add it to its Credentials collection _loginTaskCompletionSrc.TrySetResult(arcgisCred); } catch (Exception ex) { // Unable to create credential, set the exception on the task completion source _loginTaskCompletionSrc.TrySetException(ex); } finally { // Get rid of the login controls _loginUI.Hide(); _loginUI = null; } }
private void LoginButtonClick(object sender, EventArgs e) { // Get the values entered in the text fields var username = _usernameTextField.Text.Trim(); var password = _passwordTextField.Text.Trim(); var domain = _domainTextField.Text.Trim(); // Make sure the user entered all values if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(domain)) { new UIAlertView("Login", "Please enter a username, password, and domain", null, "OK", null).Show(); return; } // Fire the OnLoginInfoEntered event and provide the login values if (OnLoginInfoEntered != null) { // Create a new LoginEventArgs to contain the user's values var loginEventArgs = new LoginEventArgs(username, password, domain); // Raise the event OnLoginInfoEntered(sender, loginEventArgs); } }