public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
 {
     var fileBasedUri = translationProviderUri.GetInnerProviderUri();
     var tProviderFactory = TranslationProviderManager.GetTranslationProviderFactory(fileBasedUri);
     var tProvider = tProviderFactory.CreateTranslationProvider(fileBasedUri, translationProviderState, credentialStore);
     return new RecordSourceTuTmTranslationProvider(tProvider);
 }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var controlledMTProvider = (ControlledMtProvidersProvider)translationProvider;

            List<ITranslationProvider> mtProviders = new List<ITranslationProvider>();

            //move this to mmtProvider
          
            using (MTProvidersDialog pd = new MTProvidersDialog(controlledMTProvider))
            {
                DialogResult result = pd.ShowDialog(owner);

                if (result != DialogResult.OK)
                {
                    return false;
                }

                var mtProvidersUi = pd.SelectedTranslationProvidersWinformsUI;
                if (mtProvidersUi.Count == 0) return false;

                foreach (var mtProviderUi in mtProvidersUi)
                {
                    var innerProviders = mtProviderUi.Browse(owner, languagePairs, credentialStore);
                    if (innerProviders != null && innerProviders.All(x => x.TranslationMethod == TranslationMethod.MachineTranslation))
                    {
                        mtProviders.AddRange(innerProviders);
                    }
                }
            }
            controlledMTProvider.MtProviders = mtProviders;
            return true;
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            List<ITranslationProvider> mtProviders = new List<ITranslationProvider>();
            ControlledMtProvidersProvider controlledMTProvider = new ControlledMtProvidersProvider();

            using (MTProvidersDialog pd = new MTProvidersDialog(controlledMTProvider))
            {
                DialogResult result = pd.ShowDialog(owner);

                if(result != DialogResult.OK)
                {
                    return null;
                }

                var mtProvidersUi = pd.SelectedTranslationProvidersWinformsUI;

                if (mtProvidersUi.Count == 0) return null;
                foreach (var mtProviderUi in mtProvidersUi)
                {
                    var innerProviders = mtProviderUi.Browse(owner, languagePairs, credentialStore);
                    if (innerProviders != null && innerProviders.All(x => x.TranslationMethod == TranslationMethod.MachineTranslation))
                    {
                        mtProviders.AddRange(innerProviders);
                    }
                }
            }

            return new ITranslationProvider[] { new ControlledMtProvidersProvider(mtProviders) };
        }
        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
            MtTranslationOptions loadOptions = new MtTranslationOptions(translationProviderUri);

            //start with MT...check if we are using MT
            if (loadOptions.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
            {
                Uri myUri = new Uri("mtenhancedprovidermst:///");
                if (credentialStore.GetCredential(myUri) != null)
                {
                    bool credPersists = credentialStore.GetCredential(myUri).Persist;
                    TranslationProviderCredential cred = new TranslationProviderCredential("", credPersists); //will this work??

                    cred = credentialStore.GetCredential(myUri); //if credential is there then just get it

                    GenericCredentials cred2 = new GenericCredentials(cred.Credential);//convert to generic credentials
                    //add creds to options
                    loadOptions.ClientID = cred2.UserName;
                    loadOptions.ClientSecret = cred2.Password;
                }
                else
                {
                    throw new TranslationProviderAuthenticationException();
                }
            }
            else //if we are using Google as the provider need to get API key
            {
                Uri myUri = new Uri("mtenhancedprovidergt:///");
                if (credentialStore.GetCredential(myUri) != null)
                {
                    bool credPersists = credentialStore.GetCredential(myUri).Persist;
                    TranslationProviderCredential cred = new TranslationProviderCredential("", credPersists); //will this work??

                    cred = credentialStore.GetCredential(myUri); //if credential is there then just get it
                    //add gt key to options
                    loadOptions.apiKey = cred.Credential;
                }
                else
                {
                    throw new TranslationProviderAuthenticationException();
                    //throwing this exception ends up causing Studio to call MtTranslationProviderWinFormsUI.GetCredentialsFromUser();
                    //which we use to prompt the user to enter credentials
                }
            }

            //construct new provider with options..these options are going to include the cred.credential and the cred.persists
            MtTranslationProvider tp = new MtTranslationProvider(loadOptions);

            return tp;
        }
 public MtProviderConfDialog(MtTranslationOptions options, ITranslationProviderCredentialStore credentialStore)
 {
     this.credstore = credentialStore;
     uriMs = new Uri("mtenhancedprovidermst:///");
     uriGt = new Uri("mtenhancedprovidergt:///");
     Options = options;
     InitializeComponent();
     UpdateDialog();
 }
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            var puis = JsonConvert.DeserializeObject<List<ProviderUriInfo>>(translationProviderState);
            var managedTranslationProviders = (from pui in puis
                let providerFactory = TranslationProviderManager.GetTranslationProviderFactory(pui.Uri)
                select providerFactory.CreateTranslationProvider(pui.Uri, pui.SerializedState, credentialStore))
                .ToList();

            return new ControlledMtProvidersProvider(managedTranslationProviders);
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var translationProviders = FileBasedTranslationProviderUi.Browse(owner, languagePairs, credentialStore);
            var translationProvider = translationProviders[0];
            using (var sourceConfigurationForm = new SourceTmConfiguration(translationProvider.Uri))
            {
                sourceConfigurationForm.ShowDialog();
            }

            return new ITranslationProvider[] {new AddSourceTmTranslationProvider(translationProvider)};
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            //construct options to send to form
            MtTranslationOptions loadOptions = new MtTranslationOptions();
            //get saved key if there is one and put it into options
            //get google credentials
            TranslationProviderCredential getCredGt = GetMyCredentials(credentialStore, "mtenhancedprovidergt:///");
            if (getCredGt != null)
            {
                loadOptions.apiKey = getCredGt.Credential;
                loadOptions.persistGoogleKey = getCredGt.Persist;
            }

            //get microsoft credentials
            TranslationProviderCredential getCredMt = GetMyCredentials(credentialStore, "mtenhancedprovidermst:///");
            if (getCredMt != null)
            {
                try
                {
                    GenericCredentials creds = new GenericCredentials(getCredMt.Credential); //parse credential into username and password
                    loadOptions.ClientID = creds.UserName;
                    loadOptions.ClientSecret = creds.Password;
                    loadOptions.persistMicrosoftCreds = getCredMt.Persist;
                }
                catch { } //swallow b/c it will just fail to fill in instead of crashing the whole program
            }

            //construct form
            MtProviderConfDialog 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)
            {
                MtTranslationProvider testProvider = new MtTranslationProvider(dialog.Options);
                string apiKey = dialog.Options.apiKey;

                //we are setting credentials selectively based on the chosen provider to avoid saving the other if it is blank
                if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.persistGoogleKey);
                }
                else if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    GenericCredentials creds2 = new GenericCredentials(dialog.Options.ClientID, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.persistMicrosoftCreds);
                }

                return new ITranslationProvider[] { testProvider };
            }
            return null;
        }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var tProvider = translationProvider as AddSourceTmTranslationProvider;
            bool result = false;
            if (tProvider != null)
            {
                result = FileBasedTranslationProviderUi.Edit(owner, tProvider.FileBasedTranslationProvider, languagePairs, credentialStore);
            }

            using (var sourceConfigurationForm = new SourceTmConfiguration(translationProvider.Uri))
            {
                sourceConfigurationForm.ShowDialog();
            }

            return result;
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var translationProviders = FileBasedTranslationProviderUi.Browse(owner, languagePairs, credentialStore);

            return new ITranslationProvider[] {new AddSourceTmTranslationProvider(translationProviders[0])};
        }
Esempio n. 11
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var controlledMTProvider = (ControlledMtProvidersProvider)translationProvider;

            List <ITranslationProvider> mtProviders = new List <ITranslationProvider>();

            //move this to mmtProvider

            using (MTProvidersDialog pd = new MTProvidersDialog(controlledMTProvider))
            {
                DialogResult result = pd.ShowDialog(owner);

                if (result != DialogResult.OK)
                {
                    return(false);
                }

                var mtProvidersUi = pd.SelectedTranslationProvidersWinformsUI;
                if (mtProvidersUi.Count == 0)
                {
                    return(false);
                }

                foreach (var mtProviderUi in mtProvidersUi)
                {
                    var innerProviders = mtProviderUi.Browse(owner, languagePairs, credentialStore);
                    if (innerProviders != null && innerProviders.All(x => x.TranslationMethod == TranslationMethod.MachineTranslation))
                    {
                        mtProviders.AddRange(innerProviders);
                    }
                }
            }
            controlledMTProvider.MtProviders = mtProviders;
            return(true);
        }
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            if (!SupportsTranslationProviderUri(translationProviderUri))
            {
                throw new Exception(PluginResources.UriNotSupportedMessage);
            }

            //create options class based on URI passed to the method
            var loadOptions = new MtTranslationOptions(translationProviderUri);

            //start with MT...check if we are using MT
            if (loadOptions.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
            {
                var myUri = new Uri("mtenhancedprovidermst:///");
                if (credentialStore.GetCredential(myUri) != null)
                {
                    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.ClientId     = cred2.UserName;
                    loadOptions.ClientSecret = cred2.Password;
                }
                else
                {
                    throw new TranslationProviderAuthenticationException();
                }
            }
            else //if we are using Google as the provider need to get API key
            {
                var myUri = new Uri("mtenhancedprovidergt:///");
                if (credentialStore.GetCredential(myUri) != null)
                {
                    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
                    //add gt key to options
                    loadOptions.ApiKey = cred.Credential;
                }
                else
                {
                    throw new TranslationProviderAuthenticationException();
                    //throwing this exception ends up causing Studio to call MtTranslationProviderWinFormsUI.GetCredentialsFromUser();
                    //which we use to prompt the user to enter credentials
                }
            }

            //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);
        }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            TmxMallTranslationProvider tmxMallTranslationProvider = translationProvider as TmxMallTranslationProvider;
            bool flag = tmxMallTranslationProvider != null;
            bool result;

            if (flag)
            {
                TmxMallOptions    tmxMallOptions    = TmxMallOptions.FromCredentialStore(credentialStore);
                TmxMallConfDialog tmxMallConfDialog = new TmxMallConfDialog(tmxMallOptions);
                bool flag2 = tmxMallConfDialog.ShowDialog() == DialogResult.OK;
                if (flag2)
                {
                    tmxMallTranslationProvider.UpdateOptions(tmxMallOptions);
                    tmxMallOptions.ToCredentialStore(credentialStore);
                    result = true;
                    return(result);
                }
            }
            result = false;
            return(result);
        }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            TartuNLPProvider editProvider = translationProvider as TartuNLPProvider;

            if (editProvider == null)
            {
                return(false);
            }

            TartuNLPConfigForm dialog = new TartuNLPConfigForm(editProvider.Options, languagePairs);

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                editProvider.Options = dialog.Options;
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// If the plug-in settings can be changed by the user,
        /// SDL Trados Studio will display a Settings button.
        /// By clicking this button, users raise the plug-in user interface,
        /// in which they can modify any applicable settings.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProvider"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>
        #region "Edit"
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            OpenNmtProvider editProvider = translationProvider as OpenNmtProvider;

            if (editProvider == null)
            {
                return(false);
            }

            OpenNMTConfDialog dialog = new OpenNMTConfDialog(editProvider.Options, languagePairs);

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                editProvider.Options = dialog.Options;
                return(true);
            }

            return(false);
        }
        private void SetMstCredentials(ITranslationProviderCredentialStore credentialStore, GenericCredentials creds, bool persistCred)
        {
            //used to set credentials
            // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential
            Uri myUri = new Uri("mtenhancedprovidermst:///");

            TranslationProviderCredential cred = new TranslationProviderCredential(creds.ToCredentialString(), persistCred);
            credentialStore.RemoveCredential(myUri);
            credentialStore.AddCredential(myUri, cred);
        }
        /// <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>
        #region "GetCredentialsFromUser"
        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

            if (options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
            {
                caption = PluginResources.PromptForCredentialsCaption_Google;
            }
            else if (options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
            {
                caption = PluginResources.PromptForCredentialsCaption_Microsoft;
            }

            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)
            {
                var apiKey = dialog.Options.ApiKey;

                if (options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.PersistGoogleKey);
                }
                else if (options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    var creds2 = new GenericCredentials(dialog.Options.ClientId, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.PersistMicrosoftCreds);
                }
                return(true);
            }
            return(false);
        }
Esempio n. 18
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            try
            {
                if (!(translationProvider is SdlMTCloudTranslationProvider provider))
                {
                    return(false);
                }

                provider.TranslationService.ConnectionService.Owner = owner;
                var connectionResult = provider.TranslationService.ConnectionService.EnsureSignedIn(provider.TranslationService.ConnectionService.Credential);

                if (!connectionResult.Item1)
                {
                    throw new TranslationProviderAuthenticationException(PluginResources.Message_Invalid_credentials);
                }

                provider.TranslationService.ConnectionService.SaveCredential(credentialStore);

                var optionsWindow    = GetOptionsWindow(owner);
                var optionsViewModel = new OptionsViewModel(optionsWindow, provider, languagePairs.ToList());
                optionsWindow.DataContext = optionsViewModel;

                optionsWindow.ShowDialog();
                if (optionsWindow.DialogResult.HasValue && optionsWindow.DialogResult.Value)
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                _logger.Error($"{Constants.EditWindow} {e.Message}\n {e.StackTrace}");
            }

            return(false);
        }
Esempio n. 19
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            //TODO: Instantiate the new Rate it View part
            try
            {
                var uri = new Uri($"{Constants.MTCloudUriScheme}://");
                var connectionService = new ConnectionService(owner, new VersionService(), StudioInstance.GetLanguageCloudIdentityApi());

                var credential       = connectionService.GetCredential(credentialStore);
                var connectionResult = connectionService.EnsureSignedIn(credential, true);

                if (!connectionResult.Item1)
                {
                    throw new TranslationProviderAuthenticationException(PluginResources.Message_Invalid_credentials);
                }

                connectionService.SaveCredential(credentialStore);


                var translationService = new TranslationService(connectionService);
                var langaugeProvider   = new LanguageProvider();
                var editorController   = SdlTradosStudio.Application?.GetController <EditorController>();

                var provider = new SdlMTCloudTranslationProvider(uri, string.Empty, translationService, langaugeProvider, editorController);

                return(new ITranslationProvider[] { provider });
            }
            catch (Exception e)
            {
                _logger.Error($"{Constants.Browse} {e.Message}\n {e.StackTrace}");
            }

            return(null);
        }
Esempio n. 20
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);
        }
Esempio n. 21
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);
        }
Esempio n. 22
0
        /// <summary>
        /// If the plug-in settings can be changed by the user, SDL Trados Studio will display a Settings button.
        /// By clicking this button, users raise the plug-in user interface, in which they can modify any applicable settings, in our implementation
        /// the delimiter character and the list file name.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProvider"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            LetsMTTranslationProvider editProvider = translationProvider as LetsMTTranslationProvider;

            if (editProvider == null)
            {
                return(false);
            }

            editProvider.DownloadProfileList(true);

            SettingsForm settings = new SettingsForm(ref editProvider, languagePairs, credentialStore);

            if (!settings.TranslationProviderInitialized)
            {
                return(false);
            }

            DialogResult dResult = settings.ShowDialog(owner);

            if (dResult == DialogResult.OK)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 23
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var  tProvider = translationProvider as RecordSourceTuTmTranslationProvider;
            bool result    = false;

            if (tProvider != null)
            {
                result = FileBasedTranslationProviderUi.Edit(owner, tProvider.FileBasedTranslationProvider, languagePairs, credentialStore);
            }

            using (var sourceConfigurationForm = new SourceTmConfiguration(translationProvider.Uri))
            {
                sourceConfigurationForm.ShowDialog();
            }

            return(result);
        }
 public bool GetCredentialsFromUser(IWin32Window owner, Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
 {
     return false;
 }
        /// <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>
        private TranslationProviderCredential GetMyCredentials(ITranslationProviderCredentialStore credentialStore, string uri)
        {
            Uri myUri = new Uri(uri);
            TranslationProviderCredential cred = null;

            if (credentialStore.GetCredential(myUri) != null)
            {

                //get the credential to return
                cred = new TranslationProviderCredential(credentialStore.GetCredential(myUri).Credential, credentialStore.GetCredential(myUri).Persist);
            }

            return cred;
        }
        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 google credentials
            var getCredGt = GetMyCredentials(credentialStore, "mtenhancedprovidergt:///");

            if (getCredGt != null)
            {
                loadOptions.ApiKey           = getCredGt.Credential;
                loadOptions.PersistGoogleKey = getCredGt.Persist;
            }

            //get microsoft credentials
            var getCredMt = GetMyCredentials(credentialStore, "mtenhancedprovidermst:///");

            if (getCredMt != null)
            {
                try
                {
                    var creds = new GenericCredentials(getCredMt.Credential); //parse credential into username and password
                    loadOptions.ClientId              = creds.UserName;
                    loadOptions.ClientSecret          = creds.Password;
                    loadOptions.PersistMicrosoftCreds = getCredMt.Persist;
                }
                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);
                var apiKey       = dialog.Options.ApiKey;

                //we are setting credentials selectively based on the chosen provider to avoid saving the other if it is blank
                if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.PersistGoogleKey);
                }
                else if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    var creds2 = new GenericCredentials(dialog.Options.ClientId, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.PersistMicrosoftCreds);
                }

                return(new ITranslationProvider[] { testProvider });
            }
            return(null);
        }
Esempio n. 27
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var translationProviders = FileBasedTranslationProviderUi.Browse(owner, languagePairs, credentialStore);

            if (translationProviders.Length == 0)
            {
                return(null);
            }
            var translationProvider = translationProviders[0];

            using (var sourceConfigurationForm = new SourceTmConfiguration(translationProvider.Uri))
            {
                sourceConfigurationForm.ShowDialog();
            }


            return(new ITranslationProvider[] { new RecordSourceTuTmTranslationProvider(translationProvider) });
        }
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            if (!SupportsTranslationProviderUri(translationProviderUri))
            {
                throw new Exception(PluginResources.UriNotSupportedMessage);
            }

            //create options class based on URI passed to the method
            var loadOptions = new MtTranslationOptions(translationProviderUri);

            var myUri = new Uri("argostranslateprovider:///");
            var creds = credentialStore.GetCredential(myUri);

            if (creds != null && creds.Credential != String.Empty)
            {
                loadOptions.ApiKey = creds.Credential;
            }
            var tp = new MtTranslationProvider(loadOptions);

            return(tp);
        }
 public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
 {
     if (languagePairs.Length > 0)
     {
         TartuNLPConfigForm dialog = new TartuNLPConfigForm(new TartuNLPOptions(), languagePairs);
         if (dialog.ShowDialog(owner) == DialogResult.OK)
         {
             TartuNLPProvider testProvider = new TartuNLPProvider(dialog.Options);
             return(new ITranslationProvider[] { testProvider });
         }
     }
     else
     {
         MessageBox.Show("Please configure at least one language pair before setting up the plugin", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     return(null);
 }
Esempio n. 30
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var options = new BeGlobalTranslationOptions();

            var credentials = GetCredentials(credentialStore, "beglobaltranslationprovider:///");

            var beGlobalWindow = new BeGlobalWindow();
            var beGlobalVm     = new BeGlobalWindowViewModel(beGlobalWindow, options, credentials);

            beGlobalWindow.DataContext = beGlobalVm;

            beGlobalWindow.ShowDialog();
            if (beGlobalWindow.DialogResult.HasValue && beGlobalWindow.DialogResult.Value)
            {
                var provider = new BeGlobalTranslationProvider(options)
                {
                    Options = beGlobalVm.Options
                };
                var clientId     = beGlobalVm.Options.ClientId;
                var clientSecret = beGlobalVm.Options.ClientSecret;
                SetBeGlobalCredentials(credentialStore, clientId, clientSecret, true);
                return(new ITranslationProvider[] { provider });
            }
            return(null);
        }
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            DtSearch4StudioProvider dtSearch4StudioProvider;

            try
            {
                var persistenceService = new PersistenceService();
                var providerSettings   = persistenceService.GetProviderSettings();

                // in case we didn't have any settings stored there is no need to load the provider
                if (providerSettings == null)
                {
                    MessageBox.Show(Constants.EmptyProvider, string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }
                //var searchService = new SearchService();
                dtSearch4StudioProvider = new DtSearch4StudioProvider(providerSettings);
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"{Constants.CreateTranslationProvider}: {ex.Message}\n {ex.StackTrace}");
                throw ex;
            }
            return(dtSearch4StudioProvider);
        }
Esempio n. 32
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var options = new DeepLTranslationOptions();

            //get credentials
            var credentials = GetCredentials(credentialStore, PluginResources.DeeplTranslationProviderScheme);

            var dialog = new DeepLWindow(options, credentials, languagePairs);

            ElementHost.EnableModelessKeyboardInterop(dialog);
            dialog.ShowDialog();

            if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
            {
                var provider = new DeepLMtTranslationProvider(options, new DeepLTranslationProviderConnecter(options.ApiKey, options.Formality), languagePairs)
                {
                    Options = dialog.Options
                };
                var apiKey = dialog.Options.ApiKey;
                SetDeeplCredentials(credentialStore, apiKey, true);
                return(new ITranslationProvider[] { provider });
            }
            return(null);
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            TmxMallOptions    tmxMallOptions    = TmxMallOptions.FromCredentialStore(credentialStore);
            TmxMallConfDialog tmxMallConfDialog = new TmxMallConfDialog(tmxMallOptions);
            bool flag = tmxMallConfDialog.ShowDialog(owner) == DialogResult.OK;

            ITranslationProvider[] result;
            if (flag)
            {
                TmxMallTranslationProvider tmxMallTranslationProvider = new TmxMallTranslationProvider(tmxMallConfDialog.Options);
                tmxMallTranslationProvider.UpdateOptions(tmxMallOptions);
                tmxMallOptions.ToCredentialStore(credentialStore);
                result = new ITranslationProvider[]
                {
                    tmxMallTranslationProvider
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }
Esempio n. 34
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var editProvider = translationProvider as DeepLMtTranslationProvider;

            if (editProvider == null)
            {
                return(false);
            }

            //get saved key if there is one and put it into options
            var savedCredentials = GetCredentials(credentialStore, PluginResources.DeeplTranslationProviderScheme);

            if (savedCredentials != null)
            {
                editProvider.Options.ApiKey = savedCredentials.Credential;
            }

            var dialog = new DeepLWindow(editProvider.Options, savedCredentials, languagePairs);

            ElementHost.EnableModelessKeyboardInterop(dialog);
            dialog.ShowDialog();
            if (dialog.DialogResult.HasValue && dialog.DialogResult.Value)
            {
                var apiKey = editProvider.Options.ApiKey;
                SetDeeplCredentials(credentialStore, apiKey, true);
                return(true);
            }
            return(false);
        }
Esempio n. 35
0
 public bool GetCredentialsFromUser(IWin32Window owner, Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// If the plug-in settings can be changed by the user,
        /// SDL Trados Studio will display a Settings button.
        /// By clicking this button, users raise the plug-in user interface,
        /// in which they can modify any applicable settings, in our implementation
        /// the delimiter character and the list file name.
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="translationProvider"></param>
        /// <param name="languagePairs"></param>
        /// <param name="credentialStore"></param>
        /// <returns></returns>
        #region "Edit"
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            MtTranslationProvider editProvider = translationProvider as MtTranslationProvider;

            if (editProvider == null)
            {
                return(false);
            }

            //get saved key if there is one and put it into options
            //get google credentials
            TranslationProviderCredential getCredGt = GetMyCredentials(credentialStore, "mtenhancedprovidergt:///");

            if (getCredGt != null)
            {
                editProvider.Options.apiKey           = getCredGt.Credential;
                editProvider.Options.persistGoogleKey = getCredGt.Persist;
            }

            //get microsoft credentials
            TranslationProviderCredential getCredMt = GetMyCredentials(credentialStore, "mtenhancedprovidermst:///");

            if (getCredMt != null)
            {
                try
                {
                    GenericCredentials creds = new GenericCredentials(getCredMt.Credential); //parse credential into username and password
                    editProvider.Options.ClientID              = creds.UserName;
                    editProvider.Options.ClientSecret          = creds.Password;
                    editProvider.Options.persistMicrosoftCreds = getCredMt.Persist;
                }
                catch { }//swallow b/c it will just fail to fill in instead of crashing the whole program
            }

            MtProviderConfDialog dialog = new MtProviderConfDialog(editProvider.Options, 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)
            {
                editProvider.Options = dialog.Options;

                string apiKey = editProvider.Options.apiKey;

                //we are setting credentials selectively based on the chosen provider to avoid saving the other if it is blank
                if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.persistGoogleKey);
                }
                else if (dialog.Options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    GenericCredentials creds2 = new GenericCredentials(dialog.Options.ClientID, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.persistMicrosoftCreds);
                }
                return(true);
            }

            return(false);
        }
Esempio n. 37
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            List <ITranslationProvider>   mtProviders          = new List <ITranslationProvider>();
            ControlledMtProvidersProvider controlledMTProvider = new ControlledMtProvidersProvider();

            using (MTProvidersDialog pd = new MTProvidersDialog(controlledMTProvider))
            {
                DialogResult result = pd.ShowDialog(owner);

                if (result != DialogResult.OK)
                {
                    return(null);
                }

                var mtProvidersUi = pd.SelectedTranslationProvidersWinformsUI;

                if (mtProvidersUi.Count == 0)
                {
                    return(null);
                }
                foreach (var mtProviderUi in mtProvidersUi)
                {
                    var innerProviders = mtProviderUi.Browse(owner, languagePairs, credentialStore);
                    mtProviders.AddRange(innerProviders);
                }
            }

            return(new ITranslationProvider[] { new ControlledMtProvidersProvider(mtProviders) });
        }
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var translationProviders = FileBasedTranslationProviderUi.Browse(owner, languagePairs, credentialStore);

            return(new ITranslationProvider[] { new AddSourceTmTranslationProvider(translationProviders[0]) });
        }
 public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
 {
     var tProvider = translationProvider as AddSourceTmTranslationProvider;
     return tProvider != null && FileBasedTranslationProviderUi.Edit(owner, tProvider.FileBasedTranslationProvider, languagePairs, credentialStore);
 }
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            var tProvider = translationProvider as AddSourceTmTranslationProvider;

            return(tProvider != null && FileBasedTranslationProviderUi.Edit(owner, tProvider.FileBasedTranslationProvider, languagePairs, credentialStore));
        }
        public bool GetCredentialsFromUser(IWin32Window owner, Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            MtTranslationOptions options = new MtTranslationOptions(translationProviderUri);
            string caption = "Credentials"; //default in case any problem retrieving localized resource below
            if (options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                caption = PluginResources.PromptForCredentialsCaption_Google;
            else if (options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                caption = PluginResources.PromptForCredentialsCaption_Microsoft;

            MtProviderConfDialog 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)
            {
                string apiKey = dialog.Options.apiKey;

                if (options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    //set google credential
                    SetGoogleCredentials(credentialStore, apiKey, dialog.Options.persistGoogleKey);
                }
                else if (options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    //set mst cred
                    GenericCredentials creds2 = new GenericCredentials(dialog.Options.ClientID, dialog.Options.ClientSecret);
                    SetMstCredentials(credentialStore, creds2, dialog.Options.persistMicrosoftCreds);
                }
                return true;
            }
            return false;
        }
 /// <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>
 #region "GetCredentialsFromUser"
 public bool GetCredentialsFromUser(IWin32Window owner, Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
 {
     //return true;
     return(true);
 }
 private void SetGoogleCredentials(ITranslationProviderCredentialStore credentialStore, string apiKey, bool persistKey)
 {
     //used to set credentials
     // we are only setting and getting credentials for the uri with no parameters...kind of like a master credential
     Uri myUri = new Uri("mtenhancedprovidergt:///");
     TranslationProviderCredential cred = new TranslationProviderCredential(apiKey, persistKey);
     credentialStore.RemoveCredential(myUri);
     credentialStore.AddCredential(myUri, cred);
 }
        /// <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>
        #region "Browse"
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            OpenNMTConfDialog dialog = new OpenNMTConfDialog(new OpenNMTTranslationOptions(), languagePairs);

            if (dialog.ShowDialog(owner) == DialogResult.OK)
            {
                OpenNmtProvider testProvider = new OpenNmtProvider(dialog.Options);
                return(new ITranslationProvider[] { testProvider });
            }
            return(null);
        }
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            if (!SupportsTranslationProviderUri(translationProviderUri))
            {
                throw new Exception("Cannot handle URI.");
            }

            TartuNLPProvider tp = new TartuNLPProvider(new TartuNLPOptions(translationProviderUri));

            return(tp);
        }
Esempio n. 46
0
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore)
        {
            if (translationProviderUri == null || credentialStore == null) //Throw allowed exception if no arguments. TODO: translationProviderState, optional?
            {
                throw new ArgumentNullException("Missing arguments.");
            }

            if (!SupportsTranslationProviderUri(translationProviderUri)) //Wrong Uri, Trados is probably looking for another provider
            {
                throw new Exception("Cannot handle URI.");
            }

            //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


            LetsMTTranslationProvider translationProvider = new LetsMTTranslationProvider(credentialStore, translationProviderUri, 85); //Create the provider passing required parameters

            //if(!translationProvider.ValidateCredentials()) //If credentials are incorrect, ask again
            //  throw new TranslationProviderAuthenticationException();

            translationProvider.LoadState(translationProviderState);

            return(translationProvider); //Provider is good and user is authorized, return
        }