예제 #1
0
        public ProviderConfDialog(TranslationOptions options, ITranslationProviderCredentialStore store, LanguagePair[] languagePairs)
        {
            credentialStore = store;
            Options         = options;
            LanguagePairs   = languagePairs;
            InitializeComponent();

            if (PluginConfiguration.CurrentInstance.DefaultConnection.HasValue &&
                Options.Host == null)
            {
                Options.Host = PluginConfiguration.CurrentInstance.DefaultConnection.Value.Host;
                Options.Port = PluginConfiguration.CurrentInstance.DefaultConnection.Value.Port;
            }
            // Set this outside the if statement in case Options Host & Port were already set to the default connection
            setDefaultTM.Checked = PluginConfiguration.CurrentInstance.DefaultConnection.HasValue &&
                                   PluginConfiguration.CurrentInstance.DefaultConnection.Value.Host == Options.Host &&
                                   PluginConfiguration.CurrentInstance.DefaultConnection.Value.Port == Options.Port;

            UpdateDialog();
            Text = @"SDL ETS Translation";

            // .5 seconds after certain events, run the populate command. This prevents us from authenticating each
            // keypress (as that was causing massive lag).
            lpPopulationTimer.AutoReset = false;
            lpPopulationTimer.Elapsed  += lpPopulationTimer_Elapsed;
        }
예제 #2
0
        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));
        }
예제 #3
0
        /// <summary>
        /// Can be used in implementations in which a user login is required, e.g.
        /// for connecting to an online translation provider.
        /// Trados Studio fires calls method when a TranslationProviderAuthenticationException is thrown (e.g. in the TranslationProviderFactory class)
        /// If credentials are not required simply set
        /// this member to return always True.
        /// </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)
        {
            Log.logger.Trace("");
            var options = new TranslationOptions(translationProviderUri);

            var dialog = new ProviderConfDialog(options, credentialStore, null);

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

            return(dialog.ShowDialog(owner) == DialogResult.OK);
        }
예제 #4
0
 public TranslationProvider(TranslationOptions options)
 {
     Log.Logger.Trace("");
     Options = options;
 }
예제 #5
0
 public void LoadState(string translationProviderState)
 {
     Log.Logger.Trace("");
     Options = JsonConvert.DeserializeObject <TranslationOptions>(translationProviderState);
 }