public void MergeKeysTest()
        {
            var properties = new YamlConfigAdapter().GetProperties(@"merge:
  - &CENTER { x: 1, y: 2 }
  - &LEFT { x: 0, y: 2 }
  - &BIG { r: 10 }
  - &SMALL { r: 1 }

sample1:
    <<: *CENTER
    r: 10

sample2:
    << : [ *CENTER, *BIG ]
    other: haha

sample3:
    << : [ *CENTER, *BIG ]
    r: 100");

            Assert.NotNull(properties);

            Assert.Equal("1", properties.GetProperty("sample1:x"));
            Assert.Equal("10", properties.GetProperty("sample2:r"));
            Assert.Equal("100", properties.GetProperty("sample3:r"));
        }
Exemplo n.º 2
0
        private static void Main()
        {
            LogManager.UseConsoleLogging(LogLevel.Trace);

            YamlConfigAdapter.Register();

            var demo = new ConfigurationManagerDemo();

            Console.WriteLine("Apollo Config Demo. Please input key to get the value. Input quit to exit.");
            while (true)
            {
                Console.Write("> ");
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    continue;
                }
                input = input.Trim();
                if (input.Equals("quit", StringComparison.CurrentCultureIgnoreCase))
                {
                    Environment.Exit(0);
                }
                demo.GetConfig(input);
            }
        }
Exemplo n.º 3
0
        void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            #region apollo
            YamlConfigAdapter.Register();

            var apolloAppId = ConfigurationManager.AppSettings["Apollo.AppId"];
            var apolloEnv   = ConfigurationManager.AppSettings["Apollo.Env"];
            if (!string.IsNullOrEmpty(apolloEnv))
            {
                apolloEnv = apolloEnv.ToUpper();
            }
            else
            {
                apolloEnv = "DEV";
            }
            var apolloMetaServer = ConfigurationManager.AppSettings[$"Apollo.{apolloEnv}.Meta"];
            Configuration = new ConfigurationBuilder()
                            .AddApollo(apolloAppId, apolloMetaServer)
                            .AddDefault(ConfigFileFormat.Xml)
                            .AddDefault(ConfigFileFormat.Json)
                            .AddDefault(ConfigFileFormat.Yml)
                            .AddDefault(ConfigFileFormat.Yaml)
                            .AddDefault()
                            .Build();
            #endregion
        }
Exemplo n.º 4
0
    public static void Register()
    {
        var adapter = new YamlConfigAdapter();

        ConfigAdapterRegister.AddAdapter(ConfigFileFormat.Yml, adapter);
        ConfigAdapterRegister.AddAdapter(ConfigFileFormat.Yaml, adapter);
    }
        public void RegisterTest()
        {
            YamlConfigAdapter.Register();

            Assert.True(ConfigAdapterRegister.TryGetAdapter(ConfigFileFormat.Yml, out var a));
            Assert.True(ConfigAdapterRegister.TryGetAdapter(ConfigFileFormat.Yaml, out var b));

            Assert.Equal(a, b);

            Assert.NotNull(a);
        }
Exemplo n.º 6
0
        protected void Application_Start(object sender, EventArgs e)
        {
            YamlConfigAdapter.Register();

            Configuration = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                            .AddApollo(ConfigurationManager.AppSettings["Apollo.AppId"], ConfigurationManager.AppSettings["Apollo.MetaServer"])
                            .AddDefault(ConfigFileFormat.Xml)
                            .AddDefault(ConfigFileFormat.Json)
                            .AddDefault(ConfigFileFormat.Yml)
                            .AddDefault(ConfigFileFormat.Yaml)
                            .AddDefault()
                            .Build();
        }
        public void ParseTest()
        {
            var properties = new YamlConfigAdapter().GetProperties(@"environments:
    dev:
        url: http://dev.bar.com
        name: Developer Setup
    prod:
        url: http://foo.bar.com
        name: My Cool App
my:
    servers:
        - dev.bar.com
        - foo.bar.com");

            Assert.NotNull(properties);

            Assert.Equal(6, properties.GetPropertyNames().Count);

            Assert.Equal("foo.bar.com", properties.GetProperty("my:servers:1"));
        }
        public void NullTest()
        {
            var properties = new YamlConfigAdapter().GetProperties(@"environments:
    dev:
        url: ~
        url2: null
        url3: Null
        url4: NULL
        url5: '`'
        name: ''");

            Assert.NotNull(properties);

            Assert.Equal(6, properties.GetPropertyNames().Count);

            Assert.Empty(properties.GetProperty("environments:dev:url"));
            Assert.Empty(properties.GetProperty("environments:dev:url2"));
            Assert.Empty(properties.GetProperty("environments:dev:url3"));
            Assert.Empty(properties.GetProperty("environments:dev:url4"));
            Assert.Equal("`", properties.GetProperty("environments:dev:url5"));
            Assert.Empty(properties.GetProperty("environments:dev:name"));
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            YamlConfigAdapter.Register();

            CreateHostBuilder(args).Build().Run();
        }
Exemplo n.º 10
0
    public static Task Main(string[] args)
    {
        YamlConfigAdapter.Register();

        return(CreateHostBuilder(args).Build().RunAsync());
    }