public void TestStardust() { var provider = new HttpConfigProvider { Server = "http://star.newlifex.com:6600", //Server = "http://localhost:6600", AppId = "StarWeb" }; var str = provider["test1"]; Assert.NotEmpty(str); var keys = provider.Keys.ToArray(); Assert.NotNull(keys); var model = provider.Load <Model2>(); Assert.NotNull(model); Assert.NotEmpty(model.Test); Assert.Equal(str, model.Test); Assert.NotEmpty(model.Shop); Assert.NotEmpty(model.Title); Assert.Equal("NewLife开发团队", model.Title); var model2 = new Model2(); provider.Bind(model2); Assert.Equal(str, model2.Test); Assert.NotEmpty(model.Shop); Assert.Equal("NewLife开发团队", model.Title); provider.LoadAll(); }
public void TestStardust() { var set = new ConfigModel { Debug = true, LogLevel = LogLevel.Fatal, LogPath = "xxx", NetworkLog = "255.255.255.255:514", TempPath = "yyy", Sys = new SysConfig { Name = "NewLife.Cube", DisplayName = "魔方平台", Company = "新生命开发团队", }, }; var provider = new HttpConfigProvider { Server = "http://star.newlifex.com:6600", //Server = "http://localhost:6600", AppId = "Test" }; provider.Save(set); provider.Save(new Model2 { Test = "测试", Shop = "商店", Title = "NewLife开发团队" }); var str = provider["test1"]; Assert.NotEmpty(str); var keys = provider.Keys.ToArray(); Assert.NotNull(keys); var model = provider.Load <Model2>(); Assert.NotNull(model); Assert.NotEmpty(model.Test); Assert.Equal(str, model.Test); Assert.NotEmpty(model.Shop); Assert.NotEmpty(model.Title); Assert.Equal("NewLife开发团队", model.Title); var model2 = new Model2(); provider.Bind(model2); Assert.Equal(str, model2.Test); Assert.NotEmpty(model.Shop); Assert.Equal("NewLife开发团队", model.Title); provider.LoadAll(); }
private void DoApolloSync(Object state) { foreach (var item in AppConfig.FindAllWithCache()) { if (!item.Enable || !item.EnableApollo || item.ApolloMetaServer.IsNullOrEmpty()) { continue; } var httpConfig = new HttpConfigProvider { Server = item.ApolloMetaServer, AppId = item.ApolloAppId }; var nameSpace = item.ApolloNameSpace; if (nameSpace.IsNullOrEmpty()) { nameSpace = "application"; } httpConfig.SetApollo(nameSpace); try { // 一次性加载所有配置 httpConfig.LoadAll(); if (httpConfig.Keys.Count > 0) { // 配置匹配到本地 var ds = ConfigData.FindAllByApp(item.Id); foreach (var elm in httpConfig.Keys) { var cfg = ds.FirstOrDefault(e => e.Key.EqualIgnoreCase(elm)); if (cfg == null) { cfg = new ConfigData { AppId = item.Id, Key = elm, Enable = true, }; ds.Add(cfg); } cfg.Value = httpConfig[elm]; if (cfg is IEntity entity && entity.HasDirty) { cfg.Version = item.AcquireNewVersion(); } } ds.Save(true); } } catch (Exception ex) { XTrace.WriteException(ex); } } }