Ejemplo n.º 1
0
        public ITranslationProvider[] Browse(IWin32Window owner, LanguagePair[] languagePairs, ITranslationProviderCredentialStore credentialStore)
        {
            try
            {
                var options     = new SdlMTCloudTranslationOptions();
                var credentials = SplitCredentials(credentialStore, options);
                var window      = new OptionsWindow();
                var languages   = new Languages.Provider.Languages();

                var model = new OptionsWindowModel(window, options, credentials, languagePairs, languages);

                window.DataContext = model;

                window.ShowDialog();
                if (window.DialogResult.HasValue && window.DialogResult.Value)
                {
                    var clientId     = model.Options.ClientId;
                    var clientSecret = model.Options.ClientSecret;
                    var resendDraft  = model.Options.ResendDrafts;

                    var provider = new SdlMTCloudTranslationProvider(options)
                    {
                        Options = model.Options
                    };

                    SetCredentials(credentialStore, clientId, clientSecret, resendDraft, true);
                    return(new ITranslationProvider[] { provider });
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error($"{Constants.Browse} {e.Message}\n {e.StackTrace}");
            }
            return(null);
        }
Ejemplo n.º 2
0
 public SdlMTCloudTranslationProvider(SdlMTCloudTranslationOptions options)
 {
     Options = options;
     _languageMappingsService = new LanguageMappingsService();
     _encryptedClientId       = StringExtensions.EncryptData(Options.ClientId);
     _encryptedClientSecret   = StringExtensions.EncryptData(Options.ClientSecret);
 }
Ejemplo n.º 3
0
 public SdlMTCloudLanguageDirection(SdlMTCloudTranslationProvider beGlobalTranslationProvider, LanguagePair languageDirection)
 {
     _beGlobalTranslationProvider = beGlobalTranslationProvider;
     _languageDirection           = languageDirection;
     _options          = beGlobalTranslationProvider.Options;
     _translationUnits = new List <TranslationUnit>();
     _editorController = AppInitializer.GetEditorController();
 }
Ejemplo n.º 4
0
        public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState,
                                                              ITranslationProviderCredentialStore credentialStore)
        {
            var originalUri = new Uri(Constants.MTCloudUriScheme + ":///");
            var options     = new SdlMTCloudTranslationOptions(translationProviderUri);

            var credentials = credentialStore.GetCredential(originalUri);

            if (credentials != null)
            {
                var splitedCredentials = credentials.Credential?.Split('#');

                options.ClientId             = splitedCredentials?.Length > 2 ? StringExtensions.Decrypt(splitedCredentials[0]) : string.Empty;
                options.ClientSecret         = splitedCredentials?.Length > 2 ? StringExtensions.Decrypt(splitedCredentials[1]) : string.Empty;
                options.AuthenticationMethod = splitedCredentials?.Length == 4 ? splitedCredentials[2] : string.Empty;

                var resendDraft = splitedCredentials?.Length == 4 ? splitedCredentials[3] : string.Empty;

                if (!string.IsNullOrEmpty(resendDraft))
                {
                    options.ResendDrafts = resendDraft.Equals("True");
                }

                if (options.BeGlobalService == null)
                {
                    options.BeGlobalService = new SdlMTCloudTranslator(Constants.MTCloudTranslateAPIUri, options);
                }
            }
            else
            {
                credentialStore.AddCredential(originalUri, new TranslationProviderCredential(originalUri.ToString(), true));
            }

            int accountId;

            if (options.AuthenticationMethod.Equals("ClientLogin"))
            {
                accountId = options.BeGlobalService?.GetClientInformation() ?? 0;
            }
            else
            {
                accountId = options.BeGlobalService?.GetUserInformation() ?? 0;
            }

            var subscriptionInfo = options.BeGlobalService?.GetLanguagePairs(accountId.ToString());

            options.SubscriptionInfo = subscriptionInfo;

            return(new SdlMTCloudTranslationProvider(options));
        }
Ejemplo n.º 5
0
        private TranslationProviderCredential SplitCredentials(ITranslationProviderCredentialStore credentialStore, SdlMTCloudTranslationOptions options)
        {
            var savedCredentials = GetCredentials(credentialStore, Constants.MTCloudUriScheme + ":///");

            if (savedCredentials != null)
            {
                var splitedCredentials = savedCredentials.Credential?.Split('#');

                options.ClientId             = splitedCredentials?.Length > 2? StringExtensions.Decrypt(splitedCredentials[0]) : string.Empty;
                options.ClientSecret         = splitedCredentials?.Length > 2 ? StringExtensions.Decrypt(splitedCredentials[1]) : string.Empty;
                options.AuthenticationMethod = splitedCredentials?.Length == 4 ? splitedCredentials[2] : string.Empty;
                var resendDraft = splitedCredentials?.Length == 4 ? splitedCredentials[3] : string.Empty;
                if (!string.IsNullOrEmpty(resendDraft))
                {
                    options.ResendDrafts = resendDraft.Equals("True");
                }
            }
            return(savedCredentials);
        }
Ejemplo n.º 6
0
 public void LoadState(string translationProviderState)
 {
     Options = JsonConvert.DeserializeObject <SdlMTCloudTranslationOptions>(translationProviderState);
 }