示例#1
0
        public static void LoadStringCultureInfo()
        {
            try
            {
                string locale = Environment.GetEnvironmentVariable(ENVIRONMENT_VARIABLE_LANG);

                if (!string.IsNullOrEmpty(locale))
                {
                    // The environment variable also has the text encoding (i.e. en_US.UTF-8). .NET 6
                    // Does not accept culture names with text encoding and throw an exception.
                    // To avoid that strip off the text encoding.
                    if (locale.Contains("."))
                    {
                        locale = locale.Substring(0, locale.IndexOf("."));
                    }
                    /*A dummy operation on string*/
                    "Lambdalanguages".ToUpper(new CultureInfo(locale));
                }
                else
                {
                    /*A dummy operation on string*/
                    "Lambdalanguages".ToUpper();
                }
            }
            catch (Exception e)
            {
                InternalLogger.GetDefaultLogger().LogError(e, "PreJit: Error with LoadStringCultureInfo");
            }
        }
示例#2
0
        /// <summary>
        /// Class constructor that takes a Function Handler and initializes the class.
        /// </summary>
        public RuntimeSupportInitializer(string handler)
        {
            if (string.IsNullOrWhiteSpace(handler))
            {
                throw new ArgumentException("Cannot initialize RuntimeSupportInitializer with a null of empty Function Handler", nameof(handler));
            }

            _logger = InternalLogger.GetDefaultLogger();

            _handler       = handler;
            _debugAttacher = new RuntimeSupportDebugAttacher();
        }
 public InternalRuntimeApiClient(System.Net.Http.HttpClient httpClient)
 {
     _httpClient = httpClient;
     _logger     = InternalLogger.GetDefaultLogger();
 }
示例#4
0
        public static void PreJitAssembly(Assembly a)
        {
            // Storage to ensure not loading the same assembly twice and optimize calls to GetAssemblies()
            var loaded = new HashSet <string>();

            PrepareAssembly(a);
            LoadReferencedAssemblies(a);

            // Filter to avoid loading all the .net framework
            bool ShouldLoad(string assemblyName)
            {
                return(!loaded.Contains(assemblyName) && NotNetFramework(assemblyName));
            }

            bool NotNetFramework(string assemblyName)
            {
                return(!assemblyName.StartsWith("Microsoft.") &&
                       !assemblyName.StartsWith("System.") &&
                       !assemblyName.StartsWith("Newtonsoft.") &&
                       !assemblyName.StartsWith("netstandard"));
            }

            void PrepareAssembly(Assembly assembly)
            {
                foreach (var type in assembly.GetTypes())
                {
                    foreach (var method in type.GetMethods(BindingFlags.DeclaredOnly |
                                                           BindingFlags.NonPublic |
                                                           BindingFlags.Public | BindingFlags.Instance |
                                                           BindingFlags.Static))
                    {
                        try
                        {
                            if (method.IsAbstract)
                            {
                                continue;
                            }

                            RuntimeHelpers.PrepareMethod(
                                method.MethodHandle);
                        }
                        catch (Exception e)
                        {
                            InternalLogger.GetDefaultLogger().LogError(e, "PreJit: Error with PrepareAssembly");
                        }
                    }
                }
            }

            void LoadReferencedAssemblies(Assembly assembly)
            {
                foreach (AssemblyName an in assembly.GetReferencedAssemblies().Where(x => ShouldLoad(x.FullName)))
                {
                    // Load the assembly and load its dependencies
                    Assembly loadedAssembly = Assembly.Load(an);
                    loaded.Add(an.FullName);
                    PrepareAssembly(loadedAssembly);
                    LoadReferencedAssemblies(loadedAssembly); // Load the referenced assemblies
                }
            }
        }