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); }
/// <summary> /// Instantiates the variables and fills the list file content into /// a Dictionary collection object. /// </summary> /// <param name="provider"></param> /// <param name="languages"></param> #region "ListTranslationProviderLanguageDirection" public MtTranslationProviderLanguageDirection(MtTranslationProvider provider, LanguagePair languages) { #region "Instantiate" _provider = provider; _languageDirection = languages; _options = _provider.Options; #endregion }
public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore) { //construct options to send to form var loadOptions = new MtTranslationOptions(); //get saved key if there is one and put it into options //get credentials var getCredAmz = GetMyCredentials(credentialStore, "amazontranslateprovider:///"); if (getCredAmz != null) { try { var creds = new GenericCredentials(getCredAmz.Credential); //parse credential into username and password loadOptions.AccessKey = creds.UserName; loadOptions.SecretKey = creds.Password; loadOptions.PersistAWSCreds = getCredAmz.Persist; loadOptions.RegionName = GetRegionName(); } catch { } //swallow b/c it will just fail to fill in instead of crashing the whole program } //construct form var dialog = new MtProviderConfDialog(loadOptions, 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) { var testProvider = new MtTranslationProvider(dialog.Options); //set credentials var creds2 = new GenericCredentials(dialog.Options.AccessKey, dialog.Options.SecretKey); SetCredentials(credentialStore, creds2, dialog.Options.PersistAWSCreds); SetRegionName(dialog.Options.RegionName); SetSupportedLanguages(languagePairs, loadOptions); return(new ITranslationProvider[] { testProvider }); } return(null); }
/// <summary> /// Instantiates the variables and fills the list file content into /// a Dictionary collection object. /// </summary> /// <param name="provider"></param> /// <param name="languages"></param> public MtTranslationProviderLanguageDirection(MtTranslationProvider provider, LanguagePair languages) { _provider = provider; _languageDirection = languages; _options = _provider.Options; }