示例#1
0
        private bool ReferencesHost(ModuleDefinition assembly)
        {
            var hostName = HostAssembly.GetName();

            return(assembly.AssemblyReferences
                   .Any(x => x.Name.Equals(hostName.Name, StringComparison.InvariantCultureIgnoreCase)));
        }
示例#2
0
        private bool ReferencesHost(Assembly assembly)
        {
            var hostName = HostAssembly.GetName();

            return(assembly.GetReferencedAssemblies()
                   .Any(x => x.Name.Equals(hostName.Name, StringComparison.InvariantCultureIgnoreCase)));
        }
示例#3
0
        public async Task InitializeAsync()
        {
            var hostBuilder = new HostBuilder()
                              .ConfigureWebHost(builder =>
            {
                builder.UseTestServer();

                builder.ConfigureAppConfiguration((context, b) =>
                {
                    if (HostAssembly is not null)
                    {
                        context.HostingEnvironment.ApplicationName = HostAssembly.GetName().Name;
                    }
                });

                if (IsDevelopment)
                {
                    builder.UseSetting("Environment", "Development");
                }
                else
                {
                    builder.UseSetting("Environment", "Production");
                }

                builder.ConfigureServices(ConfigureServices);
                builder.Configure(ConfigureApp);
            });

            // Build and start the IHost
            var host = await hostBuilder.StartAsync();

            Server        = host.GetTestServer();
            BrowserClient = new TestBrowserClient(Server.CreateHandler());
            HttpClient    = Server.CreateClient();
        }
示例#4
0
        private void ReadLocalesFromManifest(Assembly hostAssembly)
        {
            Logger?.Invoke("Getting available locales...");

            var localeResources = hostAssembly
                                  .GetManifestResourceNames()
                                  .Where(x => x.Contains($".{ResourceFolder}."));

            var resourcesFilesList = localeResources.ToList();

            string manifestFilePath  = null;
            string resourcesFilePath = null;

            foreach (var file in resourcesFilesList)
            {
                if (file.EndsWith(_languageManifestFile))
                {
                    manifestFilePath = file;
                    continue;
                }

                if (Path.GetFileNameWithoutExtension(file).EndsWith(Path.GetFileNameWithoutExtension(_resourcesFile)))
                {
                    resourcesFilePath = file;
                }
            }

            if (manifestFilePath == null)
            {
                throw new I18NException("Language manifest file have not been found. Make sure you´ve got a " +
                                        $"'{_languageManifestFile}' file in folder " +
                                        $"called '{ResourceFolder}' containing embedded resource files " +
                                        "in the host assembly");
            }

            if (resourcesFilePath == null)
            {
                throw new I18NException("Language resources file have not been found. Make sure you´ve got a " +
                                        $"'{_resourcesFile}' file in folder " +
                                        $"called '{ResourceFolder}' containing embedded resource files " +
                                        "in the host assembly");
            }

            var manifestFileStream = HostAssembly.GetManifestResourceStream(manifestFilePath);
            var streamReader       = new StreamReader(manifestFileStream);

            string locale;

            while ((locale = streamReader.ReadLine()) != null)
            {
                Locales.Add(locale, resourcesFilePath);
            }

            Logger?.Invoke($"Found {Locales.Count} locales: {string.Join(", ", Locales.Keys.ToArray())}");
        }