Exemplo n.º 1
0
        /// <summary>
        /// Setup the provided <see cref="IConfigurationBuilder"/> with the required Runtime configuration.
        /// </summary>
        /// <param name="builder">
        /// The <see cref="IConfigurationBuilder"/> to supply with additional in-memory configuration settings.
        /// </param>
        /// <param name="applicationRoot">
        /// The application root directory. When running in local development mode from Composer, this is determined
        /// to be three directory levels above where the runtime application project is ejected, i.e. '../../..'.
        /// </param>
        /// <param name="settingsDirectory">
        /// The relative path to the directory containing the appsettings.json file to add as a configuration source.
        /// If null is specified, appsettings.json will be located within the application root directory.
        /// </param>
        /// <returns>
        /// Supplied <see cref="IConfigurationBuilder"/> instance with additional in-memory configuration provider.
        /// </returns>
        public static IConfigurationBuilder AddBotRuntimeConfiguration(
            this IConfigurationBuilder builder,
            string applicationRoot,
            string settingsDirectory)
        {
            // Add in-memory properties for the bot runtime that depend on the environment and application root
            AddBotRuntimeProperties(builder, applicationRoot);

            IConfiguration configuration = builder.Build();

            var applicationRootPath = configuration.GetValue <string>(ConfigurationConstants.ApplicationRootKey);

            var appSettingsConfigFilePath       = Path.GetFullPath(Path.Combine(applicationRootPath, settingsDirectory, AppSettingsFileName));
            var developerSettingsConfigFilePath = Path.GetFullPath(Path.Combine(applicationRootPath, AppSettingsDevelopmentFileName));

            builder.AddJsonFile(appSettingsConfigFilePath, optional: true, reloadOnChange: true);
            builder.AddJsonFile(developerSettingsConfigFilePath, optional: true, reloadOnChange: true);

            // Use Composer luis and qna settings extensions
            builder.AddComposerConfiguration();

            builder.AddEnvironmentVariables();

            return(builder);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Setup the provided <see cref="IConfigurationBuilder"/> with the required Runtime configuration.
        /// </summary>
        /// <param name="builder">
        /// The <see cref="IConfigurationBuilder"/> to supply with additional in-memory configuration settings.
        /// </param>
        /// <param name="applicationRoot">
        /// The application root directory. When running in local development mode from Composer, this is determined
        /// to be three directory levels above where the runtime application project is ejected, i.e. '../../..'.
        /// </param>
        /// <param name="settingsDirectory">
        /// The relative path to the directory containing the appsettings.json file to add as a configuration source.
        /// If null is specified, appsettings.json will be located within the application root directory.
        /// </param>
        /// <param name="environmentName">The name for the environment used to load appsettings.[EnvironmentName].json.</param>
        /// <returns>
        /// Supplied <see cref="IConfigurationBuilder"/> instance with additional in-memory configuration provider.
        /// </returns>
        public static IConfigurationBuilder AddBotRuntimeConfiguration(
            this IConfigurationBuilder builder,
            string applicationRoot,
            string settingsDirectory = null,
            string environmentName   = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (string.IsNullOrWhiteSpace(applicationRoot))
            {
                throw new ArgumentNullException(nameof(applicationRoot));
            }

            // Add in-memory properties for the bot runtime that depend on the environment and application root
            AddBotRuntimeProperties(builder, applicationRoot);

            // Load appsettings.
            var appSettingsConfigFilePath = Path.Combine(applicationRoot, settingsDirectory ?? string.Empty, "appsettings.json");

            builder.AddJsonFile(appSettingsConfigFilePath, optional: true, reloadOnChange: true);

            if (!string.IsNullOrWhiteSpace(environmentName))
            {
                var developerSettingsConfigFilePath = Path.Combine(applicationRoot, settingsDirectory ?? string.Empty, $"appsettings.{environmentName}.json");
                builder.AddJsonFile(developerSettingsConfigFilePath, optional: true, reloadOnChange: true);
            }

            // Use Composer luis and qna settings extensions
            builder.AddComposerConfiguration(applicationRoot);

            builder.AddEnvironmentVariables();

            return(builder);
        }