public BeGlobalWindowViewModel(BeGlobalWindow mainWindow, BeGlobalTranslationOptions options, LanguagePair[] languagePairs) { Options = options; _mainWindow = mainWindow; _languagePairs = languagePairs; _normalizeSourceTextHelper = new NormalizeSourceTextHelper(); TranslationOptions = new ObservableCollection <TranslationModel>(); var beGlobalTranslator = new BeGlobalV4Translator(Options?.Model); var accountId = beGlobalTranslator.GetUserInformation(); var subscriptionInfo = beGlobalTranslator.GetLanguagePairs(accountId.ToString()); GetEngineModels(subscriptionInfo.LanguagePairs); SetEngineModel(); }
public BeGlobalWindowViewModel(BeGlobalTranslationOptions options, LanguagePair[] languagePairs, TranslationProviderCredential credentials) { SelectedTabIndex = 0; Options = options; LoginViewModel = new LoginViewModel(options); LanguageMappingsViewModel = new LanguageMappingsViewModel(options); _languagePairs = languagePairs; _normalizeSourceTextHelper = new NormalizeSourceTextHelper(); _credentials = credentials; TranslationOptions = new ObservableCollection <TranslationModel>(); _messageBoxService = new MessageBoxService(); if (Options != null) { ReSendChecked = options.ResendDrafts; } if (credentials == null) { return; } var credential = _credentials.Credential.Replace("sdlmachinetranslationcloudprovider:///", string.Empty); if (credential.Contains("#")) { var splitedCredentials = credentials.Credential.Split('#'); if (splitedCredentials.Length == 2 && !string.IsNullOrEmpty(splitedCredentials[0]) && !string.IsNullOrEmpty(splitedCredentials[1])) { var beGlobalTranslator = new BeGlobalV4Translator(Options, _messageBoxService, _credentials); var accountId = beGlobalTranslator.GetUserInformation(); var subscriptionInfo = beGlobalTranslator.GetLanguagePairs(accountId.ToString()); GetEngineModels(subscriptionInfo); SetEngineModel(); SetAuthenticationOptions(); } } }
public ITranslationProvider CreateTranslationProvider(Uri translationProviderUri, string translationProviderState, ITranslationProviderCredentialStore credentialStore) { var originalUri = new Uri("beglobaltranslationprovider:///"); var options = new BeGlobalTranslationOptions(translationProviderUri); if (credentialStore.GetCredential(originalUri) != null) { var credentials = credentialStore.GetCredential(originalUri); var splitedCredentials = credentials.Credential.Split('#'); options.ClientId = splitedCredentials[0]; options.ClientSecret = splitedCredentials[1]; } else { credentialStore.AddCredential(originalUri, new TranslationProviderCredential(originalUri.ToString(), true)); } var beGlobalTranslator = new BeGlobalV4Translator("https://translate-api.sdlbeglobal.com", options.ClientId, options.ClientSecret, string.Empty, string.Empty, options.Model, options.UseClientAuthentication); int accountId; if (options.UseClientAuthentication) { accountId = beGlobalTranslator.GetClientInformation(); } else { accountId = beGlobalTranslator.GetUserInformation(); } var subscriptionInfo = beGlobalTranslator.GetLanguagePairs(accountId.ToString()); options.SubscriptionInfo = subscriptionInfo; return(new BeGlobalTranslationProvider(options)); }