Exemplo n.º 1
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);
                }

                MtCloudApplicationInitializer.PublishEvent(new TranslationProviderAdded());

                connectionService.SaveCredential(credentialStore);

                MtCloudApplicationInitializer.SetTranslationService(connectionService);

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

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

            return(null);
        }
Exemplo n.º 2
0
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState,
                                                              ITranslationProviderCredentialStore credentialStore)
        {
            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);

            var editorController = StudioInstance.GetEditorController();

            MtCloudApplicationInitializer.SetTranslationService(connectionService);

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

            return(provider);
        }