コード例 #1
0
ファイル: Program.cs プロジェクト: SDVentures/HostBox
        private static void LoadConfiguration(IConfiguration currentConfiguration, IConfigurationBuilder config, string componentPath, CommandLineArgs args)
        {
            Logger.Trace(m => m("Loading hostable component using path [{0}].", componentPath));

            var componentBasePath = Path.GetDirectoryName(componentPath);

            config.SetBasePath(componentBasePath);

            var configName = currentConfiguration[ConfigurationNameEnvVariable];

            Logger.Info(m => m("Application was launched with configuration '{0}'.", configName));

            config.LoadSharedLibraryConfigurationFiles(Logger, componentBasePath, args.SharedLibrariesPath);

            var configProvider = new ConfigFileNamesProvider(configName, componentBasePath, args.SharedLibrariesPath);

            var valuesBuilder = new ConfigurationBuilder();

            foreach (var valuesFile in configProvider.GetTemplateValuesFiles())
            {
                Logger.Trace(m => m($"Loading values file: {valuesFile}"));
                valuesBuilder.AddJsonFile(valuesFile, optional: true, false);
            }

            foreach (var configFile in configProvider.EnumerateConfigFiles())
            {
                config.AddJsonTemplateFile(configFile, false, false, valuesBuilder.Build().Providers, args.PlaceholderPattern);

                Logger.Trace(m => m("Configuration file [{0}] is loaded.", configFile));
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: bamix/HostBox
        private static void LoadConfiguration(IConfiguration currentConfiguration, IConfigurationBuilder config, string componentPath, CommandLineArgs args)
        {
            Logger.Trace(m => m("Loading hostable component using path [{0}].", componentPath));

            var componentBasePath = Path.GetDirectoryName(componentPath);

            config.SetBasePath(componentBasePath);

            var configName = currentConfiguration[ConfigurationNameEnvVariable];

            Logger.Info(m => m("Application was launched with configuration '{0}'.", configName));

            config.LoadSharedLibraryConfigurationFiles(Logger, componentBasePath, args.SharedLibrariesPath);

            var configProvider = new ConfigFileNamesProvider(configName, componentBasePath);

            var templateValuesSource =
                new JsonConfigurationSource
            {
                Path           = configProvider.GetTemplateValuesFile(),
                FileProvider   = null,
                ReloadOnChange = false,
                Optional       = true
            };

            templateValuesSource.ResolveFileProvider();

            var templateValuesProvider = templateValuesSource.Build(config);

            templateValuesProvider.Load();

            foreach (var configFile in configProvider.EnumerateConfigFiles())
            {
                config.AddJsonTemplateFile(configFile, false, false, templateValuesProvider, args.PlaceholderPattern);

                Logger.Trace(m => m("Configuration file [{0}] is loaded.", configFile));
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: kvinnichak-sdv/HostBox
        private static IHostBuilder PrepareHostBuilder(CommandLineArgs args)
        {
            var componentPath = Path.GetFullPath(args.Path, Directory.GetCurrentDirectory());

            var builder = new HostBuilder()
                          .ConfigureHostConfiguration(
                config =>
            {
                config.AddEnvironmentVariables();

                config.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);

                config.AddJsonFile("hostsettings.json", true, false);

                ConfigureLogging(config.Build());

                Logger = LogManager.GetLogger <Program>();

                Logger.Trace(m => m("Starting hostbox."));
            })
                          .ConfigureAppConfiguration(
                (ctx, config) =>
            {
                Logger.Trace(m => m("Loading hostable component using path [{0}].", componentPath));

                var componentBasePath = Path.GetDirectoryName(componentPath);

                config.SetBasePath(componentBasePath);

                var configName = ctx.Configuration[ConfigurationNameEnvVariable];

                Logger.Info(m => m("Application was launched with configuration '{0}'.", configName));

                config.LoadSharedLibraryConfigurationFiles(Logger, componentBasePath,
                                                           args.SharedLibrariesPath);

                var configProvider = new ConfigFileNamesProvider(configName, componentBasePath);

                var templateValuesSource =
                    new JsonConfigurationSource
                {
                    Path           = configProvider.GetTemplateValuesFile(),
                    FileProvider   = null,
                    ReloadOnChange = false,
                    Optional       = true
                };

                templateValuesSource.ResolveFileProvider();

                var templateValuesProvider = templateValuesSource.Build(config);

                templateValuesProvider.Load();

                foreach (var configFile in configProvider.EnumerateConfigFiles())
                {
                    config.AddJsonTemplateFile(configFile, false, false, templateValuesProvider,
                                               args.PlaceholderPattern);

                    Logger.Trace(m => m("Configuration file [{0}] is loaded.", configFile));
                }
            })
                          .ConfigureServices(
                (ctx, services) =>
            {
                services
                .AddSingleton(provider => new ComponentConfig
                {
                    Path = componentPath,
                    SharedLibraryPath = args.SharedLibrariesPath,
                    LoggerFactory     = LogManager.GetLogger
                });

                services.AddSingleton <IHostedService, Application>();
            });

            return(builder);
        }