private void LoginButtonClicked(object sender, EventArgs e) { // Get the values entered in the text fields var username = UsernameEntry.Text; var password = PasswordEntry.Text; var domain = DomainEntry.Text; // Make sure the user entered all values if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(domain)) { DisplayAlert("Login", "Please enter a username, password, and domain","OK"); 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.Trim(), password.Trim(), domain.Trim()); // Raise the event OnLoginInfoEntered(sender, loginEventArgs); } }
// Handle the OnLoginEntered event from the login UI // LoginEventArgs contains the username, password, and domain that were entered private void LoginInfoEntered(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 { // Dismiss the login controls Navigation.PopToRootAsync(); } }