private static void HandleAuthenticateException(string evernoteHost, string consumerKey, EDAMUserException ex) { String parameter = ex.Parameter; EDAMErrorCode errorCode = ex.ErrorCode; ShowMessage("Authentication failed (parameter: " + parameter + " errorCode: " + errorCode + ")"); if (errorCode == EDAMErrorCode.INVALID_AUTH) { if (parameter == "consumerKey") { ShowMessage("Your consumer key was not accepted by " + evernoteHost + ". This sample client application requires a client API key. " + "If you requested a web service API key, you must authenticate using OAuth. " + "If you do not have an API key from Evernote, you can request one from http://www.evernote.com/about/developer/api"); } else if (parameter == "username") { ShowMessage("You must authenticate using a username and password from " + evernoteHost); if (evernoteHost == "www.evernote.com" == false) { ShowMessage("Note that your production Evernote account will not work on " + evernoteHost + ", " + "you must register for a separate test account at https://" + evernoteHost + "/Registration.action"); } } else if (parameter == "password") { ShowMessage("The password that you entered is incorrect"); } } }
/// <summary> /// Determines what went wrong given the login failure from Evernote. /// </summary> private static Exception DecodeLoginFailure( EDAMUserException ex ) { String invalidParameter = ex.Parameter; if ( ex.ErrorCode == EDAMErrorCode.INVALID_AUTH ) { if ( invalidParameter == "consumerKey" ) return new BadConsumerKeyException( Host ); else if ( invalidParameter == "password" ) return new BadPasswordException( ); else if ( invalidParameter == "username" ) return new BadUsernameException( ); } return new AuthenticationFailedException( "Authentication failed (parameter: " + invalidParameter + " errorCode: " + ex.ErrorCode + ")" + Environment.NewLine ); }