private void SetCredentials(ITranslationProviderCredentialStore credentialStore, string clientId, string clientSecret, bool resendDraft, bool persistKey) { var uri = new Uri(Constants.MTCloudUriScheme + ":///"); string credential; // Validate if the entered clientId is an email address. // If corresponds to email standards, it means that authentication is done through User email and User password. var isEmailValid = IsEmailValid(clientId); // Encrypt client credentials to Base64 (it is usefull when user credentials contains # char and the authentication is failing, // because the # char is used to differentiate the clientId by ClientSecret. clientId = StringExtensions.EncryptData(clientId); clientSecret = StringExtensions.EncryptData(clientSecret); if (isEmailValid) { credential = $"{clientId}#{clientSecret}#UserLogin"; } else { credential = $"{clientId}#{clientSecret}#ClientLogin"; } credential = $"{credential}#{resendDraft}"; var credentials = new TranslationProviderCredential(credential, persistKey); credentialStore.RemoveCredential(uri); credentialStore.AddCredential(uri, credentials); }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { #region "CheckHandlesUri" if (!SupportsTranslationProviderUri(translationProviderUri)) { throw new Exception(PluginResources.UriNotSupportedMessage); } #endregion //create options class based on URI passed to the method var loadOptions = new MtTranslationOptions(translationProviderUri); var myUri = new Uri("amazontranslateprovider:///"); if (credentialStore.GetCredential(myUri) != null && credentialStore.GetCredential(myUri).Credential != String.Empty) { var credPersists = credentialStore.GetCredential(myUri).Persist; var cred = new TranslationProviderCredential("", credPersists); //will this work?? cred = credentialStore.GetCredential(myUri); //if credential is there then just get it var cred2 = new GenericCredentials(cred.Credential); //convert to generic credentials //add creds to options loadOptions.AccessKey = cred2.UserName; loadOptions.SecretKey = cred2.Password; } else if (loadOptions.SelectedAuthType == MtTranslationOptions.AWSAuthType.AccessKeys) { throw new TranslationProviderAuthenticationException(); } //construct new provider with options..these options are going to include the cred.credential and the cred.persists var tp = new MtTranslationProvider(loadOptions); return(tp); }
public OptionsWindowModel(OptionsWindow window, SdlMTCloudTranslationOptions options, TranslationProviderCredential credentialStore, LanguagePair[] languagePairs, Languages.Provider.Languages languages) { _languages = languages; Options = options; LanguageMappingsViewModel = new LanguageMappingsViewModel(options, this, languagePairs, _languages); LoginViewModel = new LoginViewModel(options, languagePairs, LanguageMappingsViewModel, this); _window = window; if (credentialStore == null) { return; } if (options.AuthenticationMethod.Equals("ClientLogin")) { _window.LoginTab.ClientIdBox.Password = options.ClientId; _window.LoginTab.ClientSecretBox.Password = options.ClientSecret; LoginViewModel.SelectedOption = LoginViewModel.AuthenticationOptions[0]; } else { LoginViewModel.Email = options.ClientId; _window.LoginTab.UserPasswordBox.Password = options.ClientSecret; LoginViewModel.SelectedOption = LoginViewModel.AuthenticationOptions[1]; } var projectController = AppInitializer.GetProjectController(); projectController.ProjectsChanged += ProjectController_ProjectsChanged; }
/// <summary> /// Checks whether the given translation provider has a working connection to the translation API. /// If not then display the password form and re-initialized the translation provider. /// </summary> /// <param name="editProvider">The translation provider to be checked.</param> /// <param name="credentialStore">The credential store that should contain</param> /// <returns>Returns true if the credential store already has the respective credentials or if the translation provider is successfully re-initialized. Returns false otherwise.</returns> private bool CheckTranslationProviderCredentials(LetsMTTranslationProvider editProvider, ITranslationProviderCredentialStore credentialStore) { if (credentialStore.GetCredential(editProvider.Uri) != null) { return(true); } PasswordForm pf = new PasswordForm(); while (pf.ShowDialog(this) == DialogResult.OK) { //TODO: check how to minimize the amount odfsystem list calls string credentials = string.Format("{0}\t{1}", pf.strToken, pf.strAppId); TranslationProviderCredential tc = new TranslationProviderCredential(credentials, pf.bRemember); credentialStore.AddCredential(editProvider.Uri, tc); // Create a new connection to the translation API editProvider.InitService(pf.strToken); if (!LetsMTTranslationProviderWinFormsUI.ValidateTranslationProviderLocaly(editProvider)) { //IF USERNAME INFOREC REMOVE DATA FROM STORE credentialStore.RemoveCredential(editProvider.Uri); } else { editProvider.DownloadProfileList(true); return(true); } } return(false); }
/// <summary> /// Constructor taht get cridentals /// </summary> /// <param name="credentialStore"></param> /// <param name="translationProviderUri"></param> /// <param name="resultScore"></param> public LetsMTTranslationProvider(ITranslationProviderCredentialStore credentialStore, Uri translationProviderUri, int resultScore) { m_resultScore = resultScore; m_uri = translationProviderUri; m_store = credentialStore; m_userRetryWarning = true; TranslationProviderCredential credentialData = credentialStore.GetCredential(translationProviderUri); //Make sure we have credentials, if not, throw exception to ask user if (credentialData == null) { throw new TranslationProviderAuthenticationException(); } string credential = credentialData.Credential; //Get the credentials in form "{0}\t{1}\t{3}", where 0 - username, 1 - password and 3 - appId m_strCredential = credential; ApiCredential apiCredential = ApiCredential.ParseCredential(m_strCredential); m_strAppID = string.IsNullOrEmpty(apiCredential.AppId) ? "sdl-studio" : apiCredential.AppId; InitService(apiCredential.Token == null ? "" : apiCredential.Token); }
public void Initialize(TP2007ServerBasedDialogSerializationHelper helper) { if (helper.Servers == null) { return; } List <Trados2007ServerAccount> accounts = new List <Trados2007ServerAccount>(helper.Servers.Length); foreach (var serverString in helper.Servers) { Uri serverUri; try { serverUri = new Uri(string.Format("{0}://{1}", "http", serverString)); } catch (UriFormatException) { continue; } TranslationProviderCredential credential = this.CredentialStore.GetCredential(serverUri); string username; string password; if (CredentialsUtility.TryParse(credential, out username, out password)) { Trados2007ServerAccount account = new Trados2007ServerAccount(serverString, username, password); accounts.Add(account); } } this.Servers = accounts; }
public BeGlobalWindowViewModel(BeGlobalWindow mainWindow, BeGlobalTranslationOptions options, TranslationProviderCredential credentialStore, LanguagePair[] languagePairs) { LoginViewModel = new LoginViewModel(options); SettingsViewModel = new SettingsViewModel(options); Options = options; _mainWindow = mainWindow; _languagePairs = languagePairs; _normalizeSourceTextHelper = new NormalizeSourceTextHelper(); if (credentialStore == null) { return; } if (options.UseClientAuthentication) { _mainWindow.LoginTab.ClientKeyBox.Password = options.ClientId; _mainWindow.LoginTab.ClientSecretBox.Password = options.ClientSecret; } else { LoginViewModel.Email = options.ClientId; _mainWindow.LoginTab.PasswordBox.Password = options.ClientSecret; } }
/// <summary> /// If the plug-in settings can be changed by the user, /// SDL Trados Studio will display a Settings button. /// By clicking this button, users raise the plug-in user interface, /// in which they can modify any applicable settings, in our implementation /// the delimiter character and the list file name. /// </summary> /// <param name="owner"></param> /// <param name="translationProvider"></param> /// <param name="languagePairs"></param> /// <param name="credentialStore"></param> /// <returns></returns> #region "Edit" public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore) { MtTranslationProvider editProvider = translationProvider as MtTranslationProvider; if (editProvider == null) { return(false); } //get saved key if there is one and put it into options //get google credentials TranslationProviderCredential getCredGt = GetMyCredentials(credentialStore, "mtenhancedprovidergt:///"); if (getCredGt != null) { editProvider.Options.apiKey = getCredGt.Credential; editProvider.Options.persistGoogleKey = getCredGt.Persist; } //get microsoft credentials TranslationProviderCredential getCredMt = GetMyCredentials(credentialStore, "mtenhancedprovidermst:///"); if (getCredMt != null) { try { GenericCredentials creds = new GenericCredentials(getCredMt.Credential); //parse credential into username and password editProvider.Options.ClientID = creds.UserName; editProvider.Options.ClientSecret = creds.Password; editProvider.Options.persistMicrosoftCreds = getCredMt.Persist; } catch { }//swallow b/c it will just fail to fill in instead of crashing the whole program } MtProviderConfDialog dialog = new MtProviderConfDialog(editProvider.Options, credentialStore); //we are letting user delete creds but after testing it seems that it's ok if the individual credentials are null, b/c our method will re-add them to the credstore based on the uri if (dialog.ShowDialog(owner) == DialogResult.OK) { editProvider.Options = dialog.Options; string apiKey = editProvider.Options.apiKey; //we are setting credentials selectively based on the chosen provider to avoid saving the other if it is blank if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate) { //set google credential SetGoogleCredentials(credentialStore, apiKey, dialog.Options.persistGoogleKey); } else if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator) { //set mst cred GenericCredentials creds2 = new GenericCredentials(dialog.Options.ClientID, dialog.Options.ClientSecret); SetMstCredentials(credentialStore, creds2, dialog.Options.persistMicrosoftCreds); } return(true); } return(false); }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { Log.logger.Info("Attempting to create a new translation provider with URI: {0}", translationProviderUri); if (!SupportsTranslationProviderUri(translationProviderUri)) { Log.logger.Error("Cannot handle URI {0}.", translationProviderUri); throw new Exception("Cannot handle URI."); } TranslationProviderCredential credentials = credentialStore.GetCredential(translationProviderUri); if (credentials == null) { //Throw TranslationProviderAuthenticationException, which will cause Studio to call GetCredentialsFromUser throw new TranslationProviderAuthenticationException(); } TranslationOptions options = JsonConvert.DeserializeObject <TranslationOptions>(translationProviderState); GenericCredentials genericCredentials = new GenericCredentials(credentials.Credential); if (options.UseBasicAuthentication) { options.ApiToken = ETSApi.ETSTranslatorHelper.GetAuthToken(options, genericCredentials); } else { options.ApiToken = genericCredentials["API-Key"]; ETSApi.ETSTranslatorHelper.VerifyBasicAPIToken(options, genericCredentials); } return(new TranslationProvider(options)); }
public DeepLWindow(DeepLTranslationOptions options, TranslationProviderCredential credentialStore = null, LanguagePair[] languagePairs = null, bool isTellMeAction = false) { InitializeComponent(); _isTellMeAction = isTellMeAction; var currentLanguagePairs = isTellMeAction ? options?.LanguagesSupported?.Keys.Select(key => new CultureInfo(key)).ToList() : languagePairs?.Select(lp => new CultureInfo(lp.TargetCultureName)).ToList(); NotCompatibleBlock.Visibility = Helpers.AreLanguagesCompatibleWithFormalityParameter(currentLanguagePairs) ? Visibility.Collapsed : Visibility.Visible; Formality.SelectedIndex = (int)options.Formality; PlainText.IsChecked = options.SendPlainText; Options = options; if (isTellMeAction) { ApiKeyBox.IsEnabled = false; } else { if (credentialStore != null) { ApiKeyBox.Password = credentialStore.Credential; } } }
public void ToCredentialStore(ITranslationProviderCredentialStore credentialStore) { bool flag = credentialStore.GetCredential(TmxMallOptions._uri) != null; if (flag) { credentialStore.RemoveCredential(TmxMallOptions._uri); } string text = string.Concat(new string[] { this.TmxMallUserName, ":", this.TmxMallClientID, ":", this.Num, ":", this.Fuzzy, ":", this.GlsNum, ":", this.LastError, ":", this.ProxyIP, ":", this.ProxyPort }); TranslationProviderCredential translationProviderCredential = new TranslationProviderCredential(text, true); credentialStore.AddCredential(TmxMallOptions._uri, translationProviderCredential); }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { #region "CheckHandlesUri" if (!SupportsTranslationProviderUri(translationProviderUri)) { throw new Exception(PluginResources.UriNotSupportedMessage); } #endregion //create options class based on URI passed to the method var loadOptions = new MtTranslationOptions(translationProviderUri); //start with MT...check if we are using MT if (loadOptions.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator) { var myUri = new Uri("mtenhancedprovidermst:///"); if (credentialStore.GetCredential(myUri) != null) { var credPersists = credentialStore.GetCredential(myUri).Persist; var cred = new TranslationProviderCredential("", credPersists); //will this work?? cred = credentialStore.GetCredential(myUri); //if credential is there then just get it var cred2 = new GenericCredentials(cred.Credential);//convert to generic credentials //add creds to options loadOptions.ClientId = cred2.UserName; loadOptions.ClientSecret = cred2.Password; } else { throw new TranslationProviderAuthenticationException(); } } else //if we are using Google as the provider need to get API key { var myUri = new Uri("mtenhancedprovidergt:///"); if (credentialStore.GetCredential(myUri) != null) { var credPersists = credentialStore.GetCredential(myUri).Persist; var cred = new TranslationProviderCredential("", credPersists); //will this work?? cred = credentialStore.GetCredential(myUri); //if credential is there then just get it //add gt key to options loadOptions.ApiKey = cred.Credential; } else { throw new TranslationProviderAuthenticationException(); //throwing this exception ends up causing Studio to call MtTranslationProviderWinFormsUI.GetCredentialsFromUser(); //which we use to prompt the user to enter credentials } } //construct new provider with options..these options are going to include the cred.credential and the cred.persists var tp = new MtTranslationProvider(loadOptions); return tp; }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { #region "CheckHandlesUri" if (!SupportsTranslationProviderUri(translationProviderUri)) { throw new Exception(PluginResources.UriNotSupportedMessage); } #endregion //create options class based on URI passed to the method MtTranslationOptions loadOptions = new MtTranslationOptions(translationProviderUri); //start with MT...check if we are using MT if (loadOptions.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator) { Uri myUri = new Uri("mtenhancedprovidermst:///"); if (credentialStore.GetCredential(myUri) != null) { bool credPersists = credentialStore.GetCredential(myUri).Persist; TranslationProviderCredential cred = new TranslationProviderCredential("", credPersists); //will this work?? cred = credentialStore.GetCredential(myUri); //if credential is there then just get it GenericCredentials cred2 = new GenericCredentials(cred.Credential);//convert to generic credentials //add creds to options loadOptions.ClientID = cred2.UserName; loadOptions.ClientSecret = cred2.Password; } else { throw new TranslationProviderAuthenticationException(); } } else //if we are using Google as the provider need to get API key { Uri myUri = new Uri("mtenhancedprovidergt:///"); if (credentialStore.GetCredential(myUri) != null) { bool credPersists = credentialStore.GetCredential(myUri).Persist; TranslationProviderCredential cred = new TranslationProviderCredential("", credPersists); //will this work?? cred = credentialStore.GetCredential(myUri); //if credential is there then just get it //add gt key to options loadOptions.apiKey = cred.Credential; } else { throw new TranslationProviderAuthenticationException(); //throwing this exception ends up causing Studio to call MtTranslationProviderWinFormsUI.GetCredentialsFromUser(); //which we use to prompt the user to enter credentials } } //construct new provider with options..these options are going to include the cred.credential and the cred.persists MtTranslationProvider tp = new MtTranslationProvider(loadOptions); return tp; }
public void SaveCredential(ITranslationProviderCredentialStore credentialStore, bool persist = true) { var uri = new Uri($"{Constants.MTCloudUriScheme}://"); var credentials = new TranslationProviderCredential(CredentialToString(), persist); credentialStore.RemoveCredential(uri); credentialStore.AddCredential(uri, credentials); }
private void SetGoogleCredentials(ITranslationProviderCredentialStore credentialStore, string apiKey, bool persistKey) { //used to set credentials // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential var myUri = new Uri("mtenhancedprovidergt:///"); var cred = new TranslationProviderCredential(apiKey, persistKey); credentialStore.RemoveCredential(myUri); credentialStore.AddCredential(myUri, cred); }
private void SetCredentials(ITranslationProviderCredentialStore credentialStore, string clientId, string clientSecret, bool persistKey) { var uri = new Uri("sdlmachinetranslationcloudprovider:///"); var credential = $"{clientId}#{clientSecret}"; var credentials = new TranslationProviderCredential(credential, persistKey); credentialStore.RemoveCredential(uri); credentialStore.AddCredential(uri, credentials); }
private void SetCredentials(ITranslationProviderCredentialStore credentialStore, string creds, bool persistCred) { //used to set credentials // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential var myUri = new Uri("argostranslateprovider:///"); var cred = new TranslationProviderCredential(creds, persistCred); credentialStore.RemoveCredential(myUri); credentialStore.AddCredential(myUri, cred); }
private void SetMstCredentials(ITranslationProviderCredentialStore credentialStore, GenericCredentials creds, bool persistCred) { //used to set credentials // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential var myUri = new Uri("mtenhancedprovidermst:///"); var cred = new TranslationProviderCredential(creds.ToCredentialString(), persistCred); credentialStore.RemoveCredential(myUri); credentialStore.AddCredential(myUri, cred); }
private void SetCredentialsOnCredentialStore(ITranslationProviderCredentialStore credentialStore, string providerUri, string apiKey, bool persistKey) { var myUri = new Uri(providerUri); var cred = new TranslationProviderCredential(apiKey, persistKey); credentialStore.RemoveCredential(myUri); credentialStore.AddCredential(myUri, cred); }
private void SetDeeplCredentials(ITranslationProviderCredentialStore credentialStore, string apiKey, bool persistKey) { //used to set credentials // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential var uri = new Uri("deeplprovider:///"); var credentials = new TranslationProviderCredential(apiKey, persistKey); credentialStore.RemoveCredential(uri); credentialStore.AddCredential(uri, credentials); }
/// <summary> /// Gets the API key from the credentials store and adds it to the settings. /// As Google settings generate a valid credentialsUri for the case when no User Key is set (to accomodate V1 google providers) /// then the API Key will always be overwritten with the key in the credentials store if one is present /// Also copies the API Key to the Text bo on the UI /// </summary> /// <param name="settings">Initial settings</param> /// <returns>Settings with apikey filled in</returns> private void UpdateAPIKeyFromCredentials(Settings settings) { if (settings != null) { TranslationProviderCredential credential = _credentialStore.GetCredential(settings.CredentialsUri); if (credential != null) { settings.ApiKey = this.txtApiKey.Text = credential.Credential; } } }
private TranslationProviderCredential GetCredentials(ITranslationProviderCredentialStore credentialStore, string uri) { var providerUri = new Uri(uri); TranslationProviderCredential cred = null; if (credentialStore.GetCredential(providerUri) != null) { //get the credential to return cred = new TranslationProviderCredential(credentialStore.GetCredential(providerUri)?.Credential, credentialStore.GetCredential(providerUri).Persist); } return(cred); }
public string GetStoreCridential() { TranslationProviderCredential credentialData = m_store.GetCredential(m_uri); //Make sure we have credentials, if not, throw exception to ask user if (credentialData == null) { throw new TranslationProviderAuthenticationException(); } //string credential = return(credentialData.Credential); //Get the credentials in form "{0}\t{1}\t{3}", where 0 - username, 1 - password and 3 - appId }
public DeepLWindow(DeepLTranslationOptions options, TranslationProviderCredential credentialStore, LanguagePair[] languagePairs) { _languagePairs = languagePairs; InitializeComponent(); Options = options; if (credentialStore != null) { ApiKeyBox.Password = credentialStore.Credential; } PlainText.IsChecked = Options.SendPlainText; GetSupportedTargetLanguages(); }
public DeepLWindow(DeepLTranslationOptions options, TranslationProviderCredential credentialStore) { InitializeComponent(); Options = options; if (credentialStore != null) { LoginTab.ApiKeyBox.Password = credentialStore.Credential; } if (options != null) { SettingsTab.Resend.IsChecked = options.ResendDrafts; } }
private void btnDeleteSavedGoogleKey_Click(object sender, EventArgs e) { this.gtCred = credstore.GetCredential(uriGt); if (gtCred != null && gtCred.Persist) { credstore.RemoveCredential(uriGt); chkSaveKey.Checked = false; MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedKeyDeleted); } else { MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedKeyEmpty); } }
private void btnDeleteSavedAWSKeys_Click(object sender, EventArgs e) { this.amzCred = credstore.GetCredential(uriAmz); if (amzCred != null && amzCred.Persist) { credstore.RemoveCredential(uriAmz); chkSaveCred.Checked = false; MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedCredsDeleted); } else { MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedCredsEmpty); } }
private void btnDeleteSavedMicrosoftCreds_Click(object sender, EventArgs e) { this._msCred = _credstore.GetCredential(uriMs); if (_msCred != null && _msCred.Persist) { _credstore.RemoveCredential(uriMs); chkSaveCred.Checked = false; MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedCredsDeleted); } else { MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedCredsEmpty); } }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { TranslationProviderCredential authCredential = credentialStore.GetCredential(translationProviderUri); string authToken = authCredential?.Credential; if (string.IsNullOrEmpty(authToken)) { throw new TranslationProviderAuthenticationException(); } var client = new API.Client(PluginResources.iADAATPA_API, authToken); //var client = new API.MockClient(); return(new TranslationProvider(translationProviderUri, client)); }
public DeepLWindow(DeepLTranslationOptions options, TranslationProviderCredential credentialStore = null, LanguagePair[] languagePairs = null, bool isTellMeAction = false) { InitializeComponent(); _languagePairs = languagePairs; _isTellMeAction = isTellMeAction; Formality.SelectedIndex = (int)options.Formality; PlainText.IsChecked = options.SendPlainText; Options = options; PasswordChangedTimer.Elapsed += OnPasswordChanged; SetSettingsOnWindow(credentialStore, isTellMeAction); }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { if (!SupportsTranslationProviderUri(translationProviderUri)) { throw new Exception(PluginResources.UriNotSupportedMessage); } //create options class based on URI passed to the method var loadOptions = new MtTranslationOptions(translationProviderUri); var regionsProvider = new RegionsProvider(); //start with MT...check if we are using MT if (loadOptions.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator) { var myUri = new Uri(PluginResources.UriMs); if (credentialStore.GetCredential(myUri) != null) { var cred = new TranslationProviderCredential(credentialStore.GetCredential(myUri).Credential, credentialStore.GetCredential(myUri).Persist); loadOptions.ClientId = cred.Credential; loadOptions.PersistMicrosoftCreds = cred.Persist; } else { throw new TranslationProviderAuthenticationException(); } } else //if we are using Google as the provider need to get API key { var myUri = new Uri(PluginResources.UriGt); if (credentialStore.GetCredential(myUri) != null) { var cred = new TranslationProviderCredential(credentialStore.GetCredential(myUri).Credential, credentialStore.GetCredential(myUri).Persist); loadOptions.ApiKey = cred.Credential; loadOptions.PersistGoogleKey = cred.Persist; } else { throw new TranslationProviderAuthenticationException(); //throwing this exception ends up causing Studio to call MtTranslationProviderWinFormsUI.GetCredentialsFromUser(); //which we use to prompt the user to enter credentials } } //construct new provider with options..these options are going to include the cred.credential and the cred.persists var tp = new MtTranslationProvider(loadOptions, regionsProvider); return(tp); }
private void btnDeleteSavedGoogleKey_Click(object sender, EventArgs e) { this.gtCred = credstore.GetCredential(uriGt); if (gtCred != null && gtCred.Persist) { credstore.RemoveCredential(uriGt); chkSaveKey.Checked = false; MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedKeyDeleted); } else { MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedKeyEmpty); } }
private void SetMstCredentials(ITranslationProviderCredentialStore credentialStore, GenericCredentials creds, bool persistCred) { //used to set credentials // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential Uri myUri = new Uri("mtenhancedprovidermst:///"); TranslationProviderCredential cred = new TranslationProviderCredential(creds.ToCredentialString(), persistCred); credentialStore.RemoveCredential(myUri); credentialStore.AddCredential(myUri, cred); }
private void SetGoogleCredentials(ITranslationProviderCredentialStore credentialStore, string apiKey, bool persistKey) { //used to set credentials // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential Uri myUri = new Uri("mtenhancedprovidergt:///"); TranslationProviderCredential cred = new TranslationProviderCredential(apiKey, persistKey); credentialStore.RemoveCredential(myUri); credentialStore.AddCredential(myUri, cred); }
/// <summary> /// Show the plug-in settings form when the user is adding the translation provider plug-in /// through the GUI of SDL Trados Studio /// </summary> /// <param name="owner"></param> /// <param name="languagePairs"></param> /// <param name="credentialStore"></param> /// <returns></returns> private TranslationProviderCredential GetMyCredentials(ITranslationProviderCredentialStore credentialStore, string uri) { Uri myUri = new Uri(uri); TranslationProviderCredential cred = null; if (credentialStore.GetCredential(myUri) != null) { //get the credential to return cred = new TranslationProviderCredential(credentialStore.GetCredential(myUri).Credential, credentialStore.GetCredential(myUri).Persist); } return cred; }
private void btnDeleteSavedMicrosoftCreds_Click(object sender, EventArgs e) { this.msCred = credstore.GetCredential(uriMs); if (msCred != null && msCred.Persist) { credstore.RemoveCredential(uriMs); chkSaveCred.Checked = false; MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedCredsDeleted); } else { MessageBox.Show(MtProviderConfDialogResources.deleteCredentialsMessageSavedCredsEmpty); } }