Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
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);
        }