示例#1
0
        public static void Register()
        {
            var adapter = new YamlConfigAdapter();

            ConfigAdapterRegister.AddAdapter(ConfigFileFormat.Yml, adapter);
            ConfigAdapterRegister.AddAdapter(ConfigFileFormat.Yaml, adapter);
        }
        public override Properties GetConfig()
        {
            var properties = _fileProperties == null ? new Properties() : new Properties(_fileProperties);

            return(Format != ConfigFileFormat.Properties && ConfigAdapterRegister.TryGetAdapter(Format, out var adapter)
                ? adapter.GetProperties(properties)
                : properties);
        }
        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);
        }
示例#4
0
    public void ConfigAdapterRegisterTest()
    {
        Assert.True(ConfigAdapterRegister.TryGetAdapter(ConfigFileFormat.Json, out var json));
        Assert.IsType <JsonConfigAdapter>(json);

        Assert.True(ConfigAdapterRegister.TryGetAdapter(ConfigFileFormat.Xml, out var xml));
        Assert.IsType <XmlConfigAdapter>(xml);

        var moq = new Mock <IConfigAdapter>();

        ConfigAdapterRegister.AddAdapter(ConfigFileFormat.Txt, moq.Object);
        Assert.True(ConfigAdapterRegister.TryGetAdapter(ConfigFileFormat.Txt, out var txt));
        Assert.Equal(moq.Object, txt);
    }
        public override Properties GetConfig()
        {
            var properties = _fileProperties == null ? new Properties() : new Properties(_fileProperties);

            if (Format == ConfigFileFormat.Properties || !ConfigAdapterRegister.TryGetAdapter(Format, out var adapter))
            {
                return(properties);
            }

            try
            {
                return(adapter.GetProperties(properties));
            }
            catch (Exception ex)
            {
                throw new ApolloConfigException($"Config Error! AppId: {_options.AppId}, Namespace: {Namespace}", ex);
            }
        }