Beispiel #1
0
        public void TestStardust()
        {
            var provider = new HttpConfigProvider
            {
                Server = "http://star.newlifex.com: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);
        }
Beispiel #2
0
        public void Http_Test()
        {
            {
                var prv = new HttpConfigProvider
                {
                    Server = "http://127.0.0.1:6600",
                    AppId  = "StarWeb"
                };

                var title = prv["Title"];
                Assert.Equal("NewLife开发团队", title);

                var shop = prv["conn_shop"];
                Assert.Equal("server=10.0.0.1;user=maindb;pass=Pass@word", shop);
            }
            {
                var prv = new HttpConfigProvider
                {
                    Server = "http://127.0.0.1:6600",
                    AppId  = "StarWeb",
                    Scope  = "dev",
                };

                var title = prv["Title"];
                Assert.Equal("NewLife开发团队", title);

                var shop = prv["conn_shop"];
                Assert.Equal("server=192.168.0.1;user=dev;pass=dev1234", shop);
            }
        }
Beispiel #3
0
        public void TestApollo()
        {
            var provider = new HttpConfigProvider
            {
                Server = _server,
                AppId  = "testapi"
            };

            provider.SetApollo("application");
            //provider.LoadAll();

            var url = provider["appapiurl"];

            Assert.NotEmpty(url);

            var keys = provider.Keys.ToArray();

            Assert.NotNull(keys);

            var model = provider.Load <Model>();

            Assert.NotNull(model);
            Assert.NotEmpty(model.AppApiUrl);
            Assert.Equal(url, model.AppApiUrl);
            Assert.True(model.Radius > 0);
            Assert.NotEmpty(model.MySqlServer);

            var model2 = new Model();

            provider.Bind(model2);
            Assert.Equal(url, model2.AppApiUrl);
            Assert.True(model2.Radius > 0);
            Assert.NotEmpty(model2.MySqlServer);
        }
Beispiel #4
0
        public void Test1()
        {
            var ini = new InIConfigProvider {
                FileName = "Config/core0.ini"
            };
            var xml = new XmlConfigProvider {
                FileName = "Config/core0.xml"
            };
            var json = new JsonConfigProvider {
                FileName = "Config/core0.json"
            };
            var http = new HttpConfigProvider
            {
                Server     = "http://127.0.0.1:5000/config,http://10.0.0.4/config",
                AppKey     = "Test",
                Secret     = "12345678",
                LocalCache = true,
            };

            var p = http["LogPath"];

            http["LogPath"] = p;

            var cfg = http.Load <Setting>();

            Assert.NotNull(cfg);
            Assert.True(cfg.Debug);
            Assert.NotEmpty(cfg.LogFileFormat);

            ini.Save(cfg);
            xml.Save(cfg);
            json.Save(cfg);
        }
Beispiel #5
0
        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();
        }
Beispiel #6
0
        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);
                }
            }
        }
Beispiel #7
0
        public void ConfigTest2()
        {
            var prv = new HttpConfigProvider
            {
                Server = "http://star.newlifex.com:6600",
                AppId  = "Test"
            };

            var rds = new Redis();

            rds.Init(prv["redis6"]);
            Assert.Equal(6, rds.Db);
        }
Beispiel #8
0
        private static void Test7()
        {
            var config = new HttpConfigProvider
            {
                Server = "http://star.newlifex.com:6600",
                AppId  = "Test",
                Period = 5,
            };

            //config.LoadAll();
            DAL.SetConfig(config);
            //DAL.GetConfig = config.GetConfig;

            XCode.Setting.Current.Migration = Migration.Full;
            //Role.Meta.Session.Dal.Db.Migration = Migration.Full;
            //DAL.AddConnStr("membership", "Server=10.0.0.3;Port=3306;Database=Membership;Uid=root;Pwd=Pass@word;", null, "mysql");

            var dal = Role.Meta.Session.Dal;

            XTrace.WriteLine("dal={0}", dal.DbType);
            XTrace.WriteLine("db={0}", dal.Db.ServerVersion);

            Role.Meta.Session.Dal.Db.ShowSQL = true;
            Role.Meta.Session.Dal.Expire     = 10;
            //Role.Meta.Session.Dal.Db.Readonly = true;

            var list = Role.FindAll();

            Console.WriteLine(list.Count);

            list = Role.FindAll(Role._.Name.NotContains("abc"));
            Console.WriteLine(list.Count);

            Thread.Sleep(1000);

            list = Role.FindAll();
            Console.WriteLine(list.Count);

            Thread.Sleep(1000);

            var r = list.Last();

            r.IsSystem = !r.IsSystem;
            r.Update();

            Thread.Sleep(5000);

            list = Role.FindAll();
            Console.WriteLine(list.Count);
        }
Beispiel #9
0
        public void TestStardustLayers()
        {
            var prv = new HttpConfigProvider
            {
                Server = "http://star.newlifex.com:6600",
                //Server = "http://localhost:6600",
                AppId = "test"
            };

            var cls = prv.Load <MyCls>("cls");

            Assert.NotNull(cls);
            Assert.Equal("http://127.0.0.1", cls.Server);
            Assert.Equal("mytopic", cls.Topic);

            Assert.Equal("http://127.0.0.1", prv["cls:Server"]);
            Assert.Equal("mytopic", prv["cls:Topic"]);
        }
Beispiel #10
0
        public void TestLayers()
        {
            var dic = new Dictionary <String, Object>
            {
                ["name"]       = "stone",
                ["cls:server"] = "http://127.0.0.1",
                ["cls:topic"]  = "mytopic"
            };

            var prv = new HttpConfigProvider();
            var rs  = prv.Build(dic);

            Assert.Equal(2, rs.Childs.Count);
            Assert.Equal("name", rs.Childs[0].Key);
            Assert.Equal("stone", rs.Childs[0].Value);

            var section = rs.Childs[1];

            Assert.Equal("cls", section.Key);
            Assert.Null(section.Value);
            Assert.Equal(2, section.Childs.Count);
            Assert.Equal("server", section.Childs[0].Key);
            Assert.Equal("http://127.0.0.1", section.Childs[0].Value);
            Assert.Equal("topic", section.Childs[1].Key);
            Assert.Equal("mytopic", section.Childs[1].Value);

            prv.Root = rs;

            var cls = prv.Load <MyCls>("cls");

            Assert.NotNull(cls);
            Assert.Equal("http://127.0.0.1", cls.Server);
            Assert.Equal("mytopic", cls.Topic);

            Assert.Equal("http://127.0.0.1", prv["cls:Server"]);
            Assert.Equal("mytopic", prv["cls:Topic"]);
        }