private bool Authenticate() { XmppAuthenticator authenticator = null; bool result = false; try { authenticator = CreateAuthenticator(); if (authenticator != null) { authenticator.Authenticate(); if (authenticator.AuthenticationFailed) { if (AuthenticationFailiure != null) { AuthenticationFailiure(this, new XmppAuthenticationFailiureEventArgs( authenticator.AuthenticationError)); } } result = !authenticator.AuthenticationFailed; } else { if (AuthenticationFailiure != null) { AuthenticationFailiure(this, new XmppAuthenticationFailiureEventArgs( "No valid authentication mechanism found.")); } else { throw new XmppException("No valid authentication mechanism found."); } } } catch { throw; } finally { if (authenticator != null) { authenticator.Dispose(); authenticator = null; } } return(result); }