Exemple #1
0
 public void RegisterEndpoint(TranslationEndpointManager translationEndpointManager)
 {
     translationEndpointManager.Manager = this;
     AllEndpoints.Add(translationEndpointManager);
     if (translationEndpointManager.Error == null)
     {
         ConfiguredEndpoints.Add(translationEndpointManager);
     }
 }
        public void RegisterEndpoint(TranslationEndpointManager translationEndpointManager)
        {
            translationEndpointManager.Manager = this;
            AllEndpoints.Add(translationEndpointManager);
            if (translationEndpointManager.Error == null)
            {
                ConfiguredEndpoints.Add(translationEndpointManager);
            }

            if (translationEndpointManager.Endpoint is IMonoBehaviour_Update updatable)
            {
                _updateCallbacks.Add(updatable);
            }
        }
        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;
            }
        }