Beispiel #1
0
        /// <exception cref="System.SqlSyntaxErrorException" />
        public static void InitRouteRule(ISchemaLoader loader)
        {
            var functions       = loader.Functions;
            var functionManager = new MySqlFunctionManager(true);

            BuildFuncManager(functionManager, functions);
            foreach (var conf in loader.RuleConfigList)
            {
                var algorithmString = conf.Algorithm;
                var lexer           = new MySqlLexer(algorithmString);
                var parser          = new MySqlExprParser(lexer, functionManager, false, MySqlParser.DefaultCharset);
                var expression      = parser.Expression();
                if (lexer.Token() != MySqlToken.Eof)
                {
                    throw new ConfigException("route algorithm not end with EOF: " + algorithmString);
                }
                IRuleAlgorithm algorithm;
                if (expression is IRuleAlgorithm)
                {
                    algorithm = (IRuleAlgorithm)expression;
                }
                else
                {
                    algorithm = new ExpressionAdapter(expression);
                }
                conf.RuleAlgorithm = algorithm;
            }
        }
Beispiel #2
0
        public void LoadTest()
        {
            var configuration = new ExpressionAdapter(new DotNetConfigurationStore()
            {
                FileName = "ConfigKramLoadTest.config"
            });
            var test = configuration.Load <TestConfigurationObject>();

            Assert.Equal("default", test.TestString);
            Assert.Equal(10, test.TestInt);
            Assert.Null(test.TestNullableInt);
        }
Beispiel #3
0
        public void SaveTest()
        {
            var configuration = new ExpressionAdapter(new DotNetConfigurationStore()
            {
                FileName = "ConfigKramSaveTest.config"
            });
            var test = new TestConfigurationObject {
                TestString = nameof(SaveTest), TestInt = -1, TestNullableInt = null
            };

            configuration.Save(test);

            test = new TestConfigurationObject();
            configuration.LoadInto(test);

            Assert.Equal(nameof(SaveTest), test.TestString);
            Assert.Equal(-1, test.TestInt);
            Assert.Null(test.TestNullableInt);
        }