Exemple #1
0
        /// <summary>
        /// Adds a remote configuration source to <paramref name="builder" />.
        /// </summary>
        /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
        /// <param name="configurationUri">The remote uri to</param>
        /// <param name="optional">Whether the remote configuration source is optional.</param>
        /// <param name="events">Events that get add</param>
        /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
        /// <exception cref="ArgumentNullException">builder</exception>
        /// <exception cref="ArgumentNullException">configurationUri</exception>
        /// <exception cref="ArgumentNullException">events</exception>
        /// <exception cref="ArgumentNullException">builder</exception>
        /// <exception cref="ArgumentNullException">configurationUri</exception>
        /// <exception cref="ArgumentNullException">events</exception>
        /// <exception cref="ArgumentNullException">builder</exception>
        public static IConfigurationBuilder AddRemoteSource(this IConfigurationBuilder builder, Uri configurationUri,
                                                            bool optional, RemoteConfigurationEvents events)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configurationUri == null)
            {
                throw new ArgumentNullException(nameof(configurationUri));
            }

            if (events == null)
            {
                throw new ArgumentNullException(nameof(events));
            }

            var source = new RemoteConfigurationSource
            {
                ConfigurationUri = configurationUri,
                Events           = events,
                Optional         = optional
            };

            return(builder.AddRemoteSource(source));
        }
Exemple #2
0
        /// <summary>
        /// Adds the remote source.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="source">The source.</param>
        /// <returns>IConfigurationBuilder.</returns>
        /// <exception cref="ArgumentNullException">builder</exception>
        /// <exception cref="ArgumentNullException">source</exception>
        /// <exception cref="ArgumentNullException">builder</exception>
        /// <exception cref="ArgumentNullException">source</exception>
        public static IConfigurationBuilder AddRemoteSource(this IConfigurationBuilder builder,
                                                            RemoteConfigurationSource source)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            builder.Add(source);
            return(builder);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RemoteConfigurationProvider" /> class.
        /// </summary>
        /// <param name="source">The source.</param>
        public RemoteConfigurationProvider(RemoteConfigurationSource source)
        {
            Check.NotNull(source, "source");
            if (!string.IsNullOrEmpty(source.ConfigurationKeyPrefix))
            {
                Check.CheckCondition(() => source.ConfigurationKeyPrefix.Trim().StartsWith(":"),
                                     CPlatformResource.InvalidStartCharacter, "source.ConfigurationKeyPrefix", ":");
                Check.CheckCondition(() => source.ConfigurationKeyPrefix.Trim().EndsWith(":"),
                                     CPlatformResource.InvalidEndCharacter, "source.ConfigurationKeyPrefix", ":");
            }

            Source      = source;
            Backchannel = new HttpClient(source.BackchannelHttpHandler ?? new HttpClientHandler());
            Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("获取CacheConfiugration信息");
            Backchannel.Timeout = source.BackchannelTimeout;
            Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10;
            Parser = source.Parser ?? new JsonConfigurationParser();
        }