private void AddEndpoint(HttpSecurity httpSecurity, Type type) { ITranslateEndpoint endpoint; try { endpoint = (ITranslateEndpoint)Activator.CreateInstance(type); } catch (Exception e) { XuaLogger.AutoTranslator.Error(e, "Could not instantiate class: " + type.Name); return; } var context = new InitializationContext(httpSecurity, Settings.FromLanguage, Settings.Language); try { endpoint.Initialize(context); var manager = new TranslationEndpointManager(endpoint, null, context); RegisterEndpoint(manager); } catch (Exception e) { var manager = new TranslationEndpointManager(endpoint, e, context); RegisterEndpoint(manager); } }
internal InitializationContext( HttpSecurity httpSecurity, string sourceLanguage, string destinationLanguage) { _security = httpSecurity; SourceLanguage = sourceLanguage; DestinationLanguage = destinationLanguage; }
internal InitializationContext( HttpSecurity httpSecurity, string sourceLanguage, string destinationLanguage) { _security = httpSecurity; SourceLanguage = sourceLanguage; DestinationLanguage = destinationLanguage; SpamChecksEnabled = true; TranslationDelay = Settings.DefaultTranslationDelay; }
public void CreateEndpoints(HttpSecurity httpSecurity) { if (Settings.FromLanguage != Settings.Language) { var dynamicTypes = AssemblyLoader.GetAllTypesOf <ITranslateEndpoint>(Settings.TranslatorsPath); // add built-in endpoint dynamicTypes.Add(typeof(PassthroughTranslateEndpoint)); foreach (var type in dynamicTypes) { AddEndpoint(httpSecurity, type); } } else { XuaLogger.AutoTranslator.Warn("AutoTranslator has been configured to use same destination language as source language. All translators will be disabled!"); //// add built-in endpoint //AddEndpoint( go, context, typeof( PassthroughTranslateEndpoint ) ); } }
public void InitializeEndpoints(GameObject go) { try { var httpSecurity = new HttpSecurity(); var context = new InitializationContext(httpSecurity, Settings.FromLanguage, Settings.Language); CreateEndpoints(go, context); AllEndpoints = AllEndpoints .OrderBy(x => x.Error != null) .ThenBy(x => x.Endpoint.FriendlyName) .ToList(); var primaryEndpoint = AllEndpoints.FirstOrDefault(x => x.Endpoint.Id == Settings.ServiceEndpoint); if (primaryEndpoint != null) { if (primaryEndpoint.Error != null) { XuaLogger.AutoTranslator.Error(primaryEndpoint.Error, "Error occurred during the initialization of the selected translate endpoint."); } else { CurrentEndpoint = primaryEndpoint; } } else if (!string.IsNullOrEmpty(Settings.ServiceEndpoint)) { XuaLogger.AutoTranslator.Error($"Could not find the configured endpoint '{Settings.ServiceEndpoint}'."); } if (Settings.DisableCertificateValidation) { XuaLogger.AutoTranslator.Debug($"Disabling certificate checks for endpoints because of configuration."); ServicePointManager.ServerCertificateValidationCallback += (a1, a2, a3, a4) => true; } else { var callback = httpSecurity.GetCertificateValidationCheck(); if (callback != null && !Features.SupportsNet4x) { XuaLogger.AutoTranslator.Debug($"Disabling certificate checks for endpoints because a .NET 3.x runtime is used."); ServicePointManager.ServerCertificateValidationCallback += callback; } else { XuaLogger.AutoTranslator.Debug($"Not disabling certificate checks for endpoints because a .NET 4.x runtime is used."); } } // save config because the initialization phase of plugins may have changed the config Settings.Save(); } catch (Exception e) { XuaLogger.AutoTranslator.Error(e, "An error occurred while constructing endpoints. Shutting plugin down."); Settings.IsShutdown = true; } }