public ParserTranslationContext(object component, TranslationEndpointManager endpoint, InternalTranslationResult translationResult, ParserResult result, ParserTranslationContext parentContext)
        {
            Jobs              = new HashSet <TranslationJob>();
            ChildrenContexts  = new List <ParserTranslationContext>();
            Component         = component;
            Result            = result;
            Endpoint          = endpoint;
            TranslationResult = translationResult;
            ParentContext     = parentContext;

            if (parentContext != null)
            {
                // thought: What would happen if I threw an exception after this massive anti-pattern?
                parentContext.ChildrenContexts.Add(this);
            }

            var ctx = this;

            while (ctx != null)
            {
                ctx = ctx.ParentContext;
                LevelsOfRecursion++;
            }
        }
 public TranslatorViewModel(TranslationEndpointManager endpoint)
 {
     Endpoint  = endpoint;
     IsEnabled = false; // TODO: initialize from configuration...
 }
        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;
            }
        }
 public void UnscheduleUnstartedJobs(TranslationEndpointManager endpoint)
 {
     _endpointsWithUnstartedJobs.Remove(endpoint);
 }
 public void ScheduleUnstartedJobs(TranslationEndpointManager endpoint)
 {
     _endpointsWithUnstartedJobs.Add(endpoint);
 }
 public TranslatorViewModel(TranslationEndpointManager endpoint)
 {
     Endpoint  = endpoint;
     IsEnabled = Settings.EnabledTranslators.Contains(endpoint.Endpoint.Id);
 }
 public bool IsFallbackAvailableFor(TranslationEndpointManager endpoint)
 {
     return(endpoint != null && FallbackEndpoint != null &&
            endpoint == CurrentEndpoint &&
            FallbackEndpoint != endpoint);
 }
Beispiel #8
0
 public void PerformTranslation(TranslationEndpointManager endpoint)
 {
     AutoTranslator.Internal.TranslateAsync(endpoint, OriginalText, Response_Completed);
 }