public OptionsWindowModel(OptionsWindow window, SdlMTCloudTranslationOptions options, TranslationProviderCredential credentialStore, LanguagePair[] languagePairs, Languages.Provider.Languages languages) { _languages = languages; Options = options; LanguageMappingsViewModel = new LanguageMappingsViewModel(options, this, languagePairs, _languages); LoginViewModel = new LoginViewModel(options, languagePairs, LanguageMappingsViewModel, this); _window = window; if (credentialStore == null) { return; } if (options.AuthenticationMethod.Equals("ClientLogin")) { _window.LoginTab.ClientIdBox.Password = options.ClientId; _window.LoginTab.ClientSecretBox.Password = options.ClientSecret; LoginViewModel.SelectedOption = LoginViewModel.AuthenticationOptions[0]; } else { LoginViewModel.Email = options.ClientId; _window.LoginTab.UserPasswordBox.Password = options.ClientSecret; LoginViewModel.SelectedOption = LoginViewModel.AuthenticationOptions[1]; } var projectController = AppInitializer.GetProjectController(); projectController.ProjectsChanged += ProjectController_ProjectsChanged; }
public SdlMTCloudTranslator(string server, SdlMTCloudTranslationOptions options) { try { _messageBoxService = new MessageBoxService(); _languageMappingService = new LanguageMappingsService(); _languageMappings = _languageMappingService.GetLanguageMappingSettings()?.LanguageMappings?.ToList(); _client = new RestClient(string.Format($"{server}/v4")); Utils.LogServerIPAddresses(); IRestRequest request; if (options.AuthenticationMethod.Equals("ClientLogin")) { request = new RestRequest("/token", Method.POST) { RequestFormat = DataFormat.Json }; request.AddBody(new { clientId = options.ClientId, clientSecret = options.ClientSecret }); } else { request = new RestRequest("/token/user", Method.POST) { RequestFormat = DataFormat.Json }; request.AddBody(new { username = options.ClientId, password = options.ClientSecret }); } AddTraceId(request); request.RequestFormat = DataFormat.Json; var response = _client.Execute(request); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception(Constants.TokenFailed + response.Content); } dynamic json = JsonConvert.DeserializeObject(response.Content); _client.AddDefaultHeader("Authorization", $"Bearer {json.accessToken}"); } catch (Exception ex) { Log.Logger.Error($"{Constants.BeGlobalV4Translator} {ex.Message}\n {ex.StackTrace}"); } }
public LanguageMappingsViewModel(SdlMTCloudTranslationOptions options, OptionsWindowModel beGlobalWindowViewModel, LanguagePair[] languagePairs, Languages.Provider.Languages languages) { _mtCloudDictionaries = new List <MTCloudDictionary>(); _languages = languages; _languagePairs = languagePairs; Options = options; _languageMappings = new ObservableCollection <LanguageMappingModel>(); _beGlobalWindowViewModel = beGlobalWindowViewModel; _languageMappingService = new LanguageMappingsService(); if (Options != null) { ReSendChecked = options.ResendDrafts; } BindingOperations.EnableCollectionSynchronization(LanguageMappings, _languageMappings); }
public LoginViewModel( SdlMTCloudTranslationOptions options, LanguagePair[] languagePairs, LanguageMappingsViewModel languageMappingsViewModel, OptionsWindowModel beGlobalWindowViewModel) { _languagePairs = languagePairs; LanguageMappingsViewModel = languageMappingsViewModel; BeGlobalWindowViewModel = beGlobalWindowViewModel; Options = options; AuthenticationOptions = new List <Authentication> { new Authentication { DisplayName = Constants.ClientAuthentication, Type = Constants.Client }, new Authentication { DisplayName = Constants.UserAuthentication, Type = Constants.User } }; if (!string.IsNullOrEmpty(options.AuthenticationMethod)) { SelectedOption = options.AuthenticationMethod.Equals("ClientLogin") ? AuthenticationOptions[0] : AuthenticationOptions[1]; } else { SelectedOption = AuthenticationOptions[1]; } LoginMethod = SelectedOption.Type; }