Ejemplo n.º 1
0
        public override void Initialize()
        {
            var uri    = "config:uri".Config <string>();
            var app    = "config:application".Config <string>();
            var helper = ConfigHelper.Instance;

            if (uri.IsUrl() && !string.IsNullOrWhiteSpace(app))
            {
                var provider = new ConfigServerConfigurationProvider();
                helper.Build(b => b.Add(provider));
                helper.ConfigChanged += obj =>
                {
                    var config = obj as IConfigurationRoot;
                    var mode   = config.GetValue <string>("mode");
                    if (config == null || string.IsNullOrWhiteSpace(mode) || config.GetSection("config") == null)
                    {
                        return;
                    }
                    provider.Reload(helper.Config);
                    if (provider.Settings.RefreshEnable)
                    {
                        RefreshHelper.Start(provider.Settings.RefreshInterval);
                    }
                    else
                    {
                        RefreshHelper.Stop();
                    }
                };
                if (provider.Settings.RefreshEnable)
                {
                    RefreshHelper.Start(provider.Settings.RefreshInterval);
                }
            }
            base.Initialize();
        }
Ejemplo n.º 2
0
 public override void Shutdown()
 {
     RefreshHelper.Stop();
     base.Shutdown();
 }