Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Can be used in implementations in which a user login is required, e.g. for connecting to an online translation provider.
        /// In our implementation, however, this is not required, so we 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)
        {
            PasswordForm pf = new PasswordForm();

            if (pf.ShowDialog(owner) == DialogResult.OK)
            {
                //TranslationProviderCredential tc = new TranslationProviderCredential(string.Format("{0}\t{1}\t{2}", pf.strUsername, pf.strPassword,pf.strAppId), pf.bRemember);
                TranslationProviderCredential tc = new TranslationProviderCredential(string.Format("{0}\t{1}", pf.strToken, pf.strAppId), pf.bRemember);

                credentialStore.AddCredential(translationProviderUri, tc);

                return(true);
            }

            return(false);
        }
Beispiel #3
0
        /// <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>
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            LetsMTTranslationProviderOptions opts = new LetsMTTranslationProviderOptions();

            int letsmtNum = 0;
            Uri letsmtUri = null;

            TranslationProviderCredential credentialData = null;

            do
            {
                letsmtNum++;
                letsmtUri      = new Uri(opts.Uri.ToString() + letsmtNum.ToString());
                credentialData = credentialStore.GetCredential(letsmtUri);
            } while (credentialData != null);

            int    lastUsedLetsmtNum = letsmtNum - 1;
            Uri    lastUsedLetsmtUri = new Uri(opts.Uri.ToString() + lastUsedLetsmtNum.ToString());
            string lastUsedToken     = null;

            if (lastUsedLetsmtNum > 0)
            {
                credentialData = credentialStore.GetCredential(lastUsedLetsmtUri);
                ApiCredential apiCredentaial = ApiCredential.ParseCredential(credentialData.Credential);
                lastUsedToken = apiCredentaial.Token;
            }

            PasswordForm pf = new PasswordForm(lastUsedToken);

            while (pf.ShowDialog(owner) == DialogResult.OK)
            {
                if (lastUsedToken != pf.strToken)
                {
                    //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);
                    //ad a new uri to handle multiple plugins and users

                    credentialStore.AddCredential(letsmtUri, tc);
                }
                else
                {
                    letsmtUri = lastUsedLetsmtUri;
                }

                LetsMTTranslationProvider testProvider = new LetsMTTranslationProvider(credentialStore, letsmtUri, 85);// (dialog.Options);

                //credentialStore.AddCredential(opts.Uri, tc);
                ////TODO: Check if we need a "testProvider"
                //LetsMTTranslationProvider testProvider = new LetsMTTranslationProvider(credentialStore, opts.Uri);// (dialog.Options);

                if (ValidateTranslationProviderLocaly(testProvider))
                {
                    Sdl.LanguagePlatform.TranslationMemoryApi.ITranslationProvider[] ResultProv = new ITranslationProvider[] { testProvider };
                    //Open system select screen emidetly for user frendlier setup
                    if (Edit(owner, ResultProv[ResultProv.Length - 1], languagePairs, credentialStore))
                    {
                        return(ResultProv);
                    }
                }
                else
                {
                    //IF USERNAME INFOREC REMOVE DATA FROM STORE
                    credentialStore.RemoveCredential(letsmtUri);
                }
            }
            return(null);
        }