public ConfigurationBuilder AddCondition(ConditionConfig condition) { var lastResponder = this.responderConfigs[this.responderConfigs.Count - 1]; lastResponder.AddCondtion(condition); return(this); }
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>()); } } } }
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); }
public static Func <State, bool> Load(ConditionConfig config) { if (config == null) { return((State state) => { return true; }); } return(term(config.CondtionType, config)); }
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; }); }
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; }); }
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)); } }
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."); } }
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; }); }
public ConditionConfigBuilder AddChild(ConditionConfig config) { this.childConfigs.Add(config); return(this); }
public ConditionConfigListBuilder AddCondition(ConditionConfig condition) { this.configs.Add(condition); return(this); }