public ConfigurationBuilder AddCondition(ConditionConfig condition)
        {
            var lastResponder = this.responderConfigs[this.responderConfigs.Count - 1];

            lastResponder.AddCondtion(condition);
            return(this);
        }
示例#2
0
        private void extractResponders(ConfigurationBuilder builder, JsonAccessor json)
        {
            foreach (var responderName in json["responders"])
            {
                var targetName       = responderName.Get <string>();
                var targetResponders = json["responders"][targetName];
                foreach (var responder in targetResponders)
                {
                    var values = new List <string>();
                    foreach (var respond in responder["responds"])
                    {
                        values.Add(respond.Get <string>());
                    }

                    if (responder.Contains <string>("condition"))
                    {
                        ConditionConfig condition = this.extractCondtion(responder["condition"]);
                        builder.AddResponds(targetName, values, new List <ConditionConfig>()
                        {
                            condition
                        });
                    }
                    else
                    {
                        builder.AddResponds(targetName, values, new List <ConditionConfig>());
                    }
                }
            }
        }
示例#3
0
        private static List <Func <State, bool> > generate_factor_methods(ConditionConfig factor_config)
        {
            var factor_methods = new List <Func <State, bool> >();

            foreach (var config in factor_config.ChildConfigs)
            {
                Func <State, bool> factor_method = generate_factor_method(config);
                factor_methods.Add(factor_method);
            }
            return(factor_methods);
        }
示例#4
0
        public static Func <State, bool> Load(ConditionConfig config)
        {
            if (config == null)
            {
                return((State state) =>
                {
                    return true;
                });
            }

            return(term(config.CondtionType, config));
        }
示例#5
0
        private static Func <State, bool> term_method(ConditionConfig config)
        {
            var targetField = config.TargetField;
            var targetValue = (string)config.Arguments[0].First;

            return((State state) => {
                if (state.HasKey(targetField) && state.GetString(targetField) == targetValue)
                {
                    return true;
                }
                return false;
            });
        }
示例#6
0
        private static Func <State, bool> should_method(ConditionConfig factor_config)
        {
            var factor_methods = generate_factor_methods(factor_config);

            return((State state) => {
                foreach (var factor in factor_methods)
                {
                    if (factor(state))
                    {
                        return true;
                    }
                }
                return false;
            });
        }
示例#7
0
 private static Func <State, bool> term(string condtion_type, ConditionConfig factor_config)
 {
     if (condtion_type == "must")
     {
         return(must_method(factor_config));
     }
     else if (condtion_type == "should")
     {
         return(should_method(factor_config));
     }
     else
     {
         return(generate_factor_method(factor_config));
     }
 }
示例#8
0
        private static Func <State, bool> generate_factor_method(ConditionConfig config)
        {
            var factor_name = config.CondtionType;

            if (factor_name == "term")
            {
                return(term_method(config));
            }
            else if (factor_name == "range")
            {
                return(ranges_method(config));
            }
            else
            {
                throw new ArgumentException(factor_name + " is not supported in factor method.");
            }
        }
示例#9
0
        private static Func <State, bool> ranges_method(ConditionConfig config)
        {
            var targetField = config.TargetField;
            var ranges      = config.Arguments;
            List <Func <State, bool> > methods = new List <Func <State, bool> >();

            foreach (var range in ranges)
            {
                methods.Add(range_method(targetField, range));
            }
            return((State state) => {
                foreach (var method in methods)
                {
                    if (!method(state))
                    {
                        return false;
                    }
                }
                return true;
            });
        }
示例#10
0
 public ConditionConfigBuilder AddChild(ConditionConfig config)
 {
     this.childConfigs.Add(config);
     return(this);
 }
 public ConditionConfigListBuilder AddCondition(ConditionConfig condition)
 {
     this.configs.Add(condition);
     return(this);
 }