private bool AuthenticateCredentials(GenericCredentials credentials, bool showAlertOnFailure = true) { // Expire the old LPs in case we've changed the host and reset the API version SDLMTEdgeTranslatorHelper.ExpireLanguagePairs(); Options.ApiVersion = APIVersion.Unknown; string token; try { if (Options.UseBasicAuthentication) { token = SDLMTEdgeTranslatorHelper.GetAuthToken(Options, credentials); } else { token = APIKeyField.Text; SDLMTEdgeTranslatorHelper.VerifyBasicAPIToken(Options, credentials); } } catch (Exception e) { _logger.Error($"{Constants.AuthenticateCredentials}: {e.Message}\n {e.StackTrace}"); if (showAlertOnFailure) { DialogResult = DialogResult.None; MessageBox.Show(e.Message, PluginResources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); } Options.ApiToken = token; if (tabControl != null) { try { //avoiding to do binding when the window will be closed. Because removing and adding the tab will do the bind again. inRemoveLanguagesPreferencesTab = true; tabControl.Controls.RemoveByKey("LPTab"); if (Options?.ApiVersion == APIVersion.v2) { tabControl.Invoke(new Action(() => { if (LPTab != null) { tabControl.Controls.Add(LPTab); } })); } } finally { inRemoveLanguagesPreferencesTab = false; } } return(true); }
private bool AuthenticateCredentials(GenericCredentials credentials, bool showAlertOnFailure = true) { // Expire the old LPs in case we've changed the host and reset the API version SDLMTEdgeTranslatorHelper.ExpireLanguagePairs(); Options.ApiVersion = APIVersion.Unknown; string token; try { if (Options.UseBasicAuthentication) { token = SDLMTEdgeTranslatorHelper.GetAuthToken(Options, credentials); } else { token = APIKeyField.Text; SDLMTEdgeTranslatorHelper.VerifyBasicAPIToken(Options, credentials); } } catch (Exception e) { Log.Logger.Error($"{Constants.AuthenticateCredentials}: {e.Message}\n {e.StackTrace}"); if (showAlertOnFailure) { DialogResult = DialogResult.None; if (Environment.UserInteractive) { MessageBox.Show(e.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(false); } Options.ApiToken = token; if (tabControl != null) { tabControl.Controls.RemoveByKey("LPTab"); if (Options?.ApiVersion == APIVersion.v2) { tabControl.Invoke(new Action(() => { if (LPTab != null) { tabControl.Controls.Add(LPTab); } })); } } return(true); }