/// <summary>
 /// Add remote configuration source
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IHostBuilder ConfigureRemoteSource(this IHostBuilder builder, SAEOptions options)
 {
     return(builder.ConfigureAppConfiguration((ctx, conf) =>
     {
         conf.AddRemoteSource(options);
     }));
 }
        /// <summary>
        /// Add remote configuration source
        /// </summary>
        /// <param name="configurationBuilder"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IConfigurationBuilder AddRemoteSource(this IConfigurationBuilder configurationBuilder, Action <SAEOptions> action)
        {
            var configuration = configurationBuilder.Build();

            var section = configuration.GetSection(Constants.Config.OptionKey);

            SAEOptions option;

            if (section.Exists())
            {
                option = section.Get <SAEOptions>();
            }
            else
            {
                option = new SAEOptions();
            }
            if (option.FileName.IsNullOrWhiteSpace())
            {
                var applicationName = configuration.GetSection(HostDefaults.ApplicationKey).Value;

                var env = configuration.GetSection(HostDefaults.EnvironmentKey).Value;

                var root = configuration.GetSection(Constants.Config.RootDirectoryKey)?.Value;

                root = root.IsNullOrWhiteSpace() ? Constants.Config.DefaultRootDirectory : root;

                option.FileName = Path.Combine(root, $"{applicationName}.{env}{Constants.JsonSuffix}");
            }
            //setting oauth
            if (option.OAuth != null && option.OAuth.Check())
            {
                option.Client = option.Client.UseOAuth(option.OAuth);
            }

            action.Invoke(option);
            option.Check();

            if (!configuration.GetSection(Constants.Config.RootDirectoryKey).Exists())
            {
                configurationBuilder.AddInMemoryCollection(new Dictionary <string, string> {
                    { Constants.Config.RootDirectoryKey, Path.GetDirectoryName(option.FileName) }
                });
            }

            return(configurationBuilder.Add(new SAEConfigurationSource(option)));
        }
Exemplo n.º 3
0
        public async Task Remote(string env)
        {
            var databaseOption = new DBConnectOptions
            {
                ConnectionString = this.GetRandom(),
                Name             = this.GetRandom(),
                Provider         = this.GetRandom(),
            };

            var dic = new Dictionary <string, object>
            {
                { DBConnectOptions.Option, databaseOption }
            };

            await this.SetConfigAsync(ConfigPath, dic);

            var remoteOptions = new SAEOptions
            {
                Url          = ConfigPath,
                Client       = this._client,
                PollInterval = PollInterval
            };

            var root = this.GetConfigurationBuilder(env).AddRemoteSource(remoteOptions).Build();

            var configurationSection = root.GetSection(DBConnectOptions.Option);

            var options = configurationSection.Get <DBConnectOptions>();

            this.Eq(databaseOption, options);


            databaseOption.Provider         = this.GetRandom();
            databaseOption.ConnectionString = this.GetRandom();

            await this.SetConfigAsync(ConfigPath, dic);

            Thread.Sleep((int)(remoteOptions.PollInterval * 1200));

            options = configurationSection.Get <DBConnectOptions>();

            this.Eq(databaseOption, options);
        }
 /// <summary>
 /// Add remote configuration source
 /// </summary>
 /// <param name="configurationBuilder"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 public static IConfigurationBuilder AddRemoteSource(this IConfigurationBuilder configurationBuilder, SAEOptions options)
 {
     return(configurationBuilder.AddRemoteSource(op =>
     {
         op.Extend(options);
     }));
 }