Example #1
0
        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);
        }
Example #2
0
        private void UpdateDialog()
        {
            showcredsloc             = groupBoxAuth.Location; //holds our location of where to place the group box we are showing
            txtRegion.Text           = Options.RegionName;
            txtAccessKey.Text        = Options.AccessKey;
            txtSecretKey.Text        = Options.SecretKey;
            txtAWSProfileName.Text   = Options.ProfileName;
            chkSaveCred.Checked      = Options.PersistAWSCreds;
            chkPlainTextOnly.Checked = Options.SendPlainTextOnly;
            comboAuthType.Text       = MtTranslationOptions.GetAuthTypeDescription(Options.SelectedAuthType);
            chkResendDrafts.Checked  = Options.ResendDrafts;
            chkUsePreEdit.Checked    = Options.UsePreEdit;
            chkUsePostEdit.Checked   = Options.UsePostEdit;
            txtPreEditFileName.Text  = Options.PreLookupFilename;
            txtPostEditFileName.Text = Options.PostLookupFilename;


            //enable/disable controls
            groupBoxPostedit.Enabled = chkUsePostEdit.Checked;
            groupBoxPreedit.Enabled  = chkUsePreEdit.Checked;

            this.Icon = MtProviderConfDialogResources.form_Icon;

            ShowCredBox();
            try
            {
                LoadResources();
            }
            catch { }
        }
Example #3
0
 public MtProviderConfDialog(MtTranslationOptions options, ITranslationProviderCredentialStore credentialStore)
 {
     this.credstore = credentialStore;
     uriAmz         = new Uri("amazontranslateprovider:///");
     Options        = options;
     InitializeComponent();
     UpdateDialog();
 }
Example #4
0
 /// <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
 }
        /// <summary>
        /// Used for displaying the plug-in info such as the plug-in name,
        /// tooltip, and icon.
        /// </summary>
        /// <param name="translationProviderUri"></param>
        /// <param name="translationProviderState"></param>
        /// <returns></returns>

        public TranslationProviderDisplayInfo GetDisplayInfo(Uri translationProviderUri, string translationProviderState)
        {
            var info    = new TranslationProviderDisplayInfo();
            var options = new MtTranslationOptions(translationProviderUri);

            info.TranslationProviderIcon = PluginResources.AmazonTranslate;

            info.Name              = PluginResources.Plugin_NiceName;
            info.TooltipText       = PluginResources.Plugin_Tooltip;
            info.SearchResultImage = PluginResources.amazon_aws_small;
            //TODO: update icon
            return(info);
        }
        private static void SetSupportedLanguages(LanguagePair[] languagePairs, MtTranslationOptions loadOptions)
        {
            var apiConnecter = new ApiConnecter(loadOptions);

            foreach (var languagePair in languagePairs)
            {
                var supportedLanguages = apiConnecter.GetSupportedLanguages();
                var targetLanguage     = languagePair.TargetCultureName.Substring(0, 2).ToLower();
                if (supportedLanguages.Contains(targetLanguage) && !loadOptions.LanguagesSupported.ContainsKey(targetLanguage))
                {
                    loadOptions.LanguagesSupported.Add(languagePair.TargetCultureName, "Amazon Translate");
                }
            }
        }
        /// <summary>
        /// This gets called when a TranslationProviderAuthenticationException is thrown
        /// Since SDL Studio doesn't pass the provider instance here and even if we do a workaround...
        /// any new options set in the form that comes up are never saved to the project XML...
        /// so there is no way to change any options, only to provide the credentials
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProviderUri"></param>
        /// <param name="translationProviderState"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>

        public bool GetCredentialsFromUser(IWin32Window owner, Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            var options = new MtTranslationOptions(translationProviderUri);
            var caption = "Credentials"; //default in case any problem retrieving localized resource below

            caption = PluginResources.PromptForCredentialsCaption;

            var dialog = new MtProviderConfDialog(options, caption, credentialStore);

            dialog.DisableForCredentialsOnly(); //only show controls for setting credentials, as that is the only thing that will end up getting saved

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                //set mst cred
                var creds2 = new GenericCredentials(dialog.Options.AccessKey, dialog.Options.SecretKey);
                SetCredentials(credentialStore, creds2, dialog.Options.PersistAWSCreds);
                return(true);
            }
            return(false);
        }
        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);
        }
Example #9
0
        private string LookupAmz(string sourcetext, MtTranslationOptions options)
        {
            var sourcelang = _languageDirection.SourceCulture.ToString();
            var targetlang = _languageDirection.TargetCulture.ToString();

            //instantiate ApiConnecter if necessary
            if (_amzConnect == null)
            {
                _amzConnect = new ApiConnecter(_options);
            }
            else
            {
                if (options.SelectedAuthType == MtTranslationOptions.AWSAuthType.AccessKeys)
                {
                    _amzConnect.resetCrd(options.AccessKey, options.SecretKey); //reset key in case it has been changed in dialog since ApiConnecter was instantiated
                }
            }

            var translatedText = _amzConnect.Translate(sourcelang, targetlang, sourcetext);

            return(translatedText);
        }
Example #10
0
        /// <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;
        }
Example #11
0
 public MtTranslationProvider(MtTranslationOptions options)
 {
     Options = options;
 }
 public MtTranslationProviderElementVisitor(MtTranslationOptions options)
 {
     _options = options;
 }
Example #13
0
 public void LoadState(string translationProviderState)
 {
     Options = JsonConvert.DeserializeObject <MtTranslationOptions>(translationProviderState);
 }