Beispiel #1
0
 public SdlMTCloudLanguageDirection(SdlMTCloudTranslationProvider translationProvider, LanguagePair languageDirection, EditorController editorController)
 {
     _translationProvider = translationProvider;
     _languageDirection   = languageDirection;
     _translationUnits    = new List <TranslationUnit>();
     _editorController    = editorController;
 }
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState,
                                                              ITranslationProviderCredentialStore credentialStore)
        {
            var currentProjProvider = MtCloudApplicationInitializer.GetCurrentProjectProvider();

            if (currentProjProvider != null)
            {
                MtCloudApplicationInitializer.SetTranslationService(null, currentProjProvider.TranslationService);
                return(currentProjProvider);
            }

            var connectionService = new ConnectionService(StudioInstance.GetActiveForm(), new VersionService(),
                                                          StudioInstance.GetLanguageCloudIdentityApi(), MtCloudApplicationInitializer.Client);

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

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

            MtCloudApplicationInitializer.SetTranslationService(connectionService, null);

            var languageProvider = new LanguageProvider();
            var provider         = new SdlMTCloudTranslationProvider(translationProviderUri, translationProviderState,
                                                                     MtCloudApplicationInitializer.TranslationService, languageProvider);

            MtCloudApplicationInitializer.AddCurrentProjectProvider(provider);

            return(provider);
        }
Beispiel #3
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(), MtCloudApplicationInitializer.Client);

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

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

                MtCloudApplicationInitializer.SetTranslationService(connectionService, null);

                var languageProvider = new LanguageProvider();
                var provider         = new SdlMTCloudTranslationProvider(uri, string.Empty, MtCloudApplicationInitializer.TranslationService,
                                                                         languageProvider);

                var optionsWindow = GetOptionsWindow(owner, languagePairs, provider);

                optionsWindow.ShowDialog();
                if (optionsWindow.DialogResult.HasValue && optionsWindow.DialogResult.Value)
                {
                    MtCloudApplicationInitializer.AddCurrentProjectProvider(provider);
                    MtCloudApplicationInitializer.PublishEvent(new TranslationProviderAdded());

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

            return(null);
        }
Beispiel #4
0
        private static OptionsWindow GetOptionsWindow(IWin32Window owner, LanguagePair[] languagePairs, SdlMTCloudTranslationProvider provider)
        {
            var optionsWindow = new OptionsWindow();

            var _ = new WindowInteropHelper(optionsWindow)
            {
                Owner = owner.Handle
            };

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

            optionsWindow.DataContext = optionsViewModel;
            return(optionsWindow);
        }