/// <summary> /// Signs a user in to Lync as one of two possible users. User that is /// signed in depends on whether side-by-side client is chosen. /// </summary> internal void SignUserIn() { //Set the display cursor to indicate that user must wait for //sign in to complete if (SetWindowCursor != null) { SetWindowCursor(Cursors.WaitCursor); } //Set the sign in credentials of the user to the //appropriate credentials for the endpoint mode string userUri = string.Empty; string userPassword = string.Empty; SignInCreds getCreds; getCreds = new SignInCreds("Sign in"); if (getCreds.ShowDialog() == DialogResult.OK) { userUri = getCreds.UserName; userPassword = getCreds.Password; getCreds.Close(); } _UserUri = userUri; _LyncClient.BeginSignIn( userUri, userUri, userPassword, (ar) => { try { _LyncClient.EndSignIn(ar); } catch (Exception exc) { throw exc; } }, null); }
/// <summary> /// Raised when user's credentials are rejected by Lync or a service that /// Lync depends on requests credentials /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void _LyncClient_CredentialRequested(object sender, CredentialRequestedEventArgs e) { //If the request for credentials comes from Lync server then sign out, get new creentials //and sign in. if (e.Type == CredentialRequestedType.LyncAutodiscover) { try { _LyncClient.BeginSignOut((ar) => { _LyncClient.EndSignOut(ar); //Ask user for credentials and attempt to sign in again SignUserIn(); }, null); } catch (Exception ex) { if (SetWindowCursor != null) { SetWindowCursor(Cursors.Arrow); } MessageBox.Show( "Exception on attempt to sign in, abandoning sign in: " + ex.Message, "Lync Client sign in delay", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { SignInCreds getCreds; getCreds = new SignInCreds(e.Type.ToString()); if (getCreds.ShowDialog() == DialogResult.OK) { string userUri = getCreds.UserName; string userPassword = getCreds.Password; getCreds.Close(); e.Submit(userUri, userPassword, false); } } }