Beispiel #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);
        }
Beispiel #2
0
        public bool Edit(IWin32Window owner, ITranslationProvider translationProvider, LanguagePair[] languagePairs,
                         ITranslationProviderCredentialStore credentialStore)
        {
            try
            {
                if (!(translationProvider is SdlMTCloudTranslationProvider editProvider))
                {
                    return(false);
                }

                //get saved key if there is one and put it into options
                var credentials = SplitCredentials(credentialStore, editProvider.Options);
                var window      = new OptionsWindow();
                var languages   = new Languages.Provider.Languages();

                var model = new OptionsWindowModel(window, editProvider.Options, credentials, languagePairs, languages);

                window.DataContext = model;

                window.ShowDialog();
                if (window.DialogResult.HasValue && window.DialogResult.Value)
                {
                    editProvider.Options = model.Options;
                    var clientId     = editProvider.Options.ClientId;
                    var clientSecret = model.Options.ClientSecret;
                    var resendDraft  = model.Options.ResendDrafts;
                    SetCredentials(credentialStore, clientId, clientSecret, resendDraft, true);
                    return(true);
                }
            }
            catch (Exception e)
            {
                Log.Logger.Error($"{Constants.EditWindow} {e.Message}\n {e.StackTrace}");
            }
            return(false);
        }