public static IBuilder Register(
            this IBuilder builder,
            Type configurationType,
            string fullPathToFolder,
            Environment environment,
            FileType fileType,
            bool isOptional
            )
        {
            var isDefault = environment == Environment.Default;
            var filename  = new StringBuilder()
                            .Append(configurationType.Name)
                            .Append(isDefault ? "" : $".{environment.ToString()}")
                            .Append(".json")
                            .ToString();
            var path = string.IsNullOrEmpty(fullPathToFolder) ?
                       filename :
                       Path.Combine(fullPathToFolder, filename);

            switch (fileType)
            {
            case FileType.Json:
                return(builder.AddJsonFile(path, isOptional, true));

            case FileType.Xml:
                return(builder.AddXmlFile(path, isOptional, true));

            case FileType.Ini:
                return(builder.AddIniFile(path, isOptional, true));
            }

            throw new NotSupportedException(fileType.ToString());
        }
        /// <summary>
        /// Replaces the arguments.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        public void ReplaceArguments(IConfigurationBuilder configurationBuilder)
        {
            var commandLineSource = configurationBuilder.Sources.OfType <CommandLineConfigurationSource>()
                                    .FirstOrDefault();

            if (commandLineSource != null)
            {
                commandLineSource.Args = _args;
            }
        }
        /// <summary>
        /// Captures the arguments.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        public void CaptureArguments(IConfigurationBuilder configurationBuilder)
        {
            var commandLineSource = configurationBuilder.Sources.OfType <CommandLineConfigurationSource>()
                                    .FirstOrDefault();

            if (commandLineSource != null)
            {
                _args = commandLineSource.Args.ToArray();
            }
        }
 public static IBuilder Register(
     this IBuilder builder,
     params IConfigurationSource[] sources
     )
 {
     foreach (var source in sources)
     {
         builder.Register(source);
     }
     return(builder);
 }
        public static IBuilder SetRelativePath(
            this IBuilder builder,
            string relativePath
            )
        {
            var path = Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory,
                relativePath
                );

            return(builder.SetBasePath(path));
        }
 public static IBuilder Register(
     this IBuilder builder,
     IConfigurationSource source
     )
 {
     return(builder.Register(
                source.ConfigurationType,
                source.ConfigurationsDirectory?.FullName,
                source.Environment,
                source.FileType,
                source.IsOptional
                ));
 }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationBuilder" /> class.
 /// </summary>
 /// <param name="scanner">The scanner.</param>
 /// <param name="environment">The environment.</param>
 /// <param name="configuration">The configuration.</param>
 /// <param name="builder">The builder.</param>
 /// <param name="diagnosticSource">The diagnostic source.</param>
 /// <param name="properties">The properties.</param>
 /// <exception cref="ArgumentNullException">
 /// scanner
 /// or
 /// builder
 /// or
 /// configuration
 /// or
 /// diagnosticSource
 /// </exception>
 public ConfigurationBuilder(
     IConventionScanner scanner,
     IRocketEnvironment environment,
     IConfiguration configuration,
     IMsftConfigurationBuilder builder,
     ILogger diagnosticSource,
     IDictionary <object, object?> properties
     ) : base(scanner, properties)
 {
     ApplicationConfigurationBuilder = builder ?? throw new ArgumentNullException(nameof(builder));
     Environment   = environment;
     Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     Logger        = diagnosticSource ?? throw new ArgumentNullException(nameof(diagnosticSource));
 }
        /// <summary>
        /// Configures the application configuration.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="configurationBuilder">The configuration builder.</param>
        public void ConfigureAppConfiguration(HostBuilderContext context, IConfigurationBuilder configurationBuilder)
        {
            var rocketHostBuilder = RocketHostExtensions.GetConventionalHostBuilder(_hostBuilder);

            InsertConfigurationSourceAfter(
                configurationBuilder.Sources,
                sources => sources.OfType <JsonConfigurationSource>().FirstOrDefault(x => x.Path == "appsettings.json"),
                (source) => new YamlConfigurationSource()
            {
                Path           = "appsettings.yml",
                FileProvider   = source.FileProvider,
                Optional       = true,
                ReloadOnChange = true,
            });

            InsertConfigurationSourceAfter(
                configurationBuilder.Sources,
                sources => sources.OfType <JsonConfigurationSource>().FirstOrDefault(x =>
                                                                                     string.Equals(x.Path, $"appsettings.{context.HostingEnvironment.EnvironmentName}.json",
                                                                                                   StringComparison.OrdinalIgnoreCase)),
                (source) => new YamlConfigurationSource()
            {
                Path           = $"appsettings.{context.HostingEnvironment.EnvironmentName}.yml",
                FileProvider   = source.FileProvider,
                Optional       = true,
                ReloadOnChange = true,
            });

            var cb = new ConfigurationBuilder(
                rocketHostBuilder.Scanner,
                context.HostingEnvironment.Convert(),
                context.Configuration,
                configurationBuilder,
                rocketHostBuilder.Logger,
                rocketHostBuilder.Properties);

            cb.Build();

            MoveConfigurationSourceToEnd(configurationBuilder.Sources,
                                         sources => sources.OfType <JsonConfigurationSource>().Where(x =>
                                                                                                     string.Equals(x.Path, "secrets.json", StringComparison.OrdinalIgnoreCase)));

            MoveConfigurationSourceToEnd(configurationBuilder.Sources,
                                         sources => sources.OfType <EnvironmentVariablesConfigurationSource>());

            MoveConfigurationSourceToEnd(configurationBuilder.Sources,
                                         sources => sources.OfType <CommandLineConfigurationSource>());
        }
 public static IBuilder Register(
     this IBuilder builder,
     Type configurationType,
     Environment environment,
     FileType fileType,
     bool isOptional
     )
 {
     return(builder.Register(
                configurationType,
                null,
                environment,
                fileType,
                isOptional
                ));
 }
        /// <summary>
        /// Configures the cli.
        /// </summary>
        /// <param name="configurationBuilder">The configuration builder.</param>
        public void ConfigureCli(IConfigurationBuilder configurationBuilder)
        {
            var rocketHostBuilder = RocketHostExtensions.GetConventionalHostBuilder(_hostBuilder);
            var clb = new CommandLineBuilder(
                rocketHostBuilder.Scanner,
                rocketHostBuilder.AssemblyProvider,
                rocketHostBuilder.AssemblyCandidateFinder,
                rocketHostBuilder.Logger,
                rocketHostBuilder.Properties
                );

            _exec = clb.Build().Parse(_args ?? Array.Empty <string>());
            _args = _exec.ApplicationState.RemainingArguments ?? Array.Empty <string>();
            configurationBuilder.AddApplicationState(_exec.ApplicationState);
            rocketHostBuilder.Properties.Add(typeof(ICommandLineExecutor), _exec);
        }
 public static IBuilder Auto(
     this IBuilder builder,
     Type configurationType,
     string fullPathToFolder,
     FileType fileType
     )
 {
     foreach (Environment environment in Enum.GetValues(
                  typeof(Environment)
                  ))
     {
         builder.Register(
             configurationType,
             fullPathToFolder,
             environment,
             fileType,
             environment != Environment.Default
             );
     }
     return(builder);
 }
 public static IBuilder Auto <T>(
     this IBuilder builder,
     FileType fileType
     ) => builder.Auto(typeof(T), null, fileType);
 public static IBuilder Auto <T>(
     this IBuilder builder,
     string fullPathToFolder,
     FileType fileType
     ) => builder.Auto(typeof(T), fullPathToFolder, fileType);
 public static IBuilder Auto(
     this IBuilder builder,
     Type configurationType,
     FileType fileType
     ) => builder.Auto(configurationType, null, fileType);
 public void Init()
 {
     this.Builder = new ConfigurationBuilder()
                    .SetRelativePath("App_Data/Configurations");
 }
 public ProxyConfigurationBuilder(IMsftConfigurationBuilder builder) => _builder = builder;