Example #1
0
        private static ConfigInfo GetConfigInfo(ConfigInfo config)
        {
            ZookeeperOption option  = null;
            var             section = CPlatform.AppConfig.GetSection("Zookeeper");

            if (section.Exists())
            {
                option = section.Get <ZookeeperOption>();
            }
            else if (AppConfig.Configuration != null)
            {
                option = AppConfig.Configuration.Get <ZookeeperOption>();
            }
            if (option != null)
            {
                var sessionTimeout = config.SessionTimeout.TotalSeconds;
                Double.TryParse(option.SessionTimeout, out sessionTimeout);
                config = new ConfigInfo(
                    option.ConnectionString,
                    TimeSpan.FromSeconds(sessionTimeout),
                    option.RoutePath ?? config.RoutePath,
                    option.SubscriberPath ?? config.SubscriberPath,
                    option.CommandPath ?? config.CommandPath,
                    option.CachePath ?? config.CachePath,
                    option.MqttRoutePath ?? config.MqttRoutePath,
                    option.ChRoot ?? config.ChRoot,
                    option.ReloadOnChange != null ? bool.Parse(option.ReloadOnChange) :
                    config.ReloadOnChange,
                    option.EnableChildrenMonitor != null ? bool.Parse(option.EnableChildrenMonitor) :
                    config.EnableChildrenMonitor
                    );
            }
            return(config);
        }
        public static IServiceCollection AddZookeeperRegistry(this IServiceCollection services, Action <ZookeeperOption> configureOptions)
        {
            services.AddOptions();
            var options = new ZookeeperOption();

            if (configureOptions != null)
            {
                configureOptions(options);
            }
            services.Configure(configureOptions);
            services.AddSingleton <RegistryService, ZookeeperRegistryService>();
            return(services);
        }