Esempio n. 1
0
 public RuleBookTemplateModel(string name, string baseClassName, RuleEngineRule[] rules, LookupTable[] tables)
 {
     Name = name;
     BaseClassName = baseClassName;
     _rules = rules;
     Tables = tables;
 }
Esempio n. 2
0
        public ActionResult Variables(string id)
        {
            var result = new object[] { };
            if (id != null)
            {
                var root = new RuleEngineRule();
                root.Children.AddRange(Strategy.GetRuleBookRules(CurrentRuleBookId, null));

                var item = root.Find(id);
                if (item != null)
                {
                    result = result.Union(item.AccessibleVars.OrderBy(p => p).Select(p => new
                                                                          {
                                                                              name = p,
                                                                              value = p,
                                                                              type = "variable",
                                                                              description = p
                                                                          })).ToArray();
                }
            }
            // TODO Find out how this fits in if we arn't using the configuration part anymore
            //result = result.Union(ConfigExpressionTree.GetAll().OrderBy(p => p.Name)
            //    .Select(p => new
            //            {
            //                name = p.Display,
            //                value = p.Name,
            //                type = "variable",
            //                description = p.Name + "( " + p.Display + " )"
            //            }).ToArray().Distinct().ToArray()).ToArray();

            return Json(result, JsonRequestBehavior.AllowGet);
        }
Esempio n. 3
0
 public RuleEngineRule(string id, string name, string expression, RuleEngineRule parent)
 {
     Id = id;
     Name = name;
     RuleExpression = expression;
     Parent = parent;
     Expression = new Expression(expression);
 }
Esempio n. 4
0
 public IEnumerable<RuleBookError> ValidateRule(RuleEngineRule rule)
 {
     foreach (var lookup in rule.Lookups)
     {
         if (!LookupTables.Contains(lookup) && !PredefinedFunctions.Contains(lookup))
         {
             yield return new RuleBookError("Validator", string.Format("Lookup/Method {0} not found.", lookup));
         }
     }
 }
Esempio n. 5
0
 public ActionResult SaveRule(RuleEngineRule model)
 {
     // Is this an override of the current rulebook already
     var forceNew = CurrentRuleBookId != model.RuleBookId;
     // Set the rulebook id to the the current rule book to override it
     model.RuleBookId = CurrentRuleBookId;
     // Save the rule
     Strategy.SaveRule(model, forceNew);
     // Return the result view
     return View("Index", RuleHelper.SortRules(Strategy.GetRuleBookRules(CurrentRuleBookId).ToArray()));
 }
Esempio n. 6
0
 public static IEnumerable<RuleEngineRule> SortRules(RuleEngineRule[] rules)
 {
     var ratingRule = new RuleEngineRule();
     ratingRule.Children.AddRange(rules);
     try
     {
         SortRules(ratingRule);
     }
     catch (Exception ex)
     {
         return rules;
     }
     return ratingRule.Children;
 }
Esempio n. 7
0
        public static void SortRules(RuleEngineRule rule, ContextList<string> variables)
        {
            //var childList = rule.Children.ToArray();
            // Clear the children
            //rule.Children.Clear();
            if (rule.Children.Count > 0)
            {
                variables.PushContext();
                // Push a new variable context

                rule.Children = new RulesCollection(RuleEngineRule.SortedRules(rule.Children, variables.All.ToArray()), rule);
                foreach (var child in rule.Children)
                {
                    SortRules(child, variables);
                }
                variables.PopContext();
            }
            variables.Add(rule.Name);
        }
Esempio n. 8
0
        public static void SortRules(RuleEngineRule ratingRule)
        {
            var children = ratingRule.Children.ToArray();

            var variableContext = new ContextList<string>();
            variableContext.PushContext();

            var outputs = children.SelectMany(p => p.Outputs).ToArray();
            var variables = children.SelectMany(p => p.AllInputs).Except(outputs).ToList();

            foreach (var variable in variables)
            {
                variableContext.Add(variable);
            }

            SortRules(ratingRule, variableContext);

            variableContext.PopContext();
        }
Esempio n. 9
0
        //
        // GET: /RatingEngine/Intellisense/
        public ActionResult RuleVars(string id)
        {
            var result = new object[] { };
            if (id != null)
            {
                var root = new RuleEngineRule();
                root.Children.AddRange(Strategy.GetRuleBookRules(CurrentRuleBookId, null));

                var item = root.Find(id);
                if (item != null)
                {
                    result = result.Union(item.AccessibleVars.OrderBy(p => p)
                        .Select(p => new
                    {
                        name = p,
                        value = p,
                        type = "variable",
                        description = p
                    })).ToArray();
                }
            }
            return Json(result, JsonRequestBehavior.AllowGet);
        }
Esempio n. 10
0
 public RuleBookTemplateModel(string name, RuleEngineRule[] rules, LookupTable[] tables)
     : this(name, "CompiledRuleBookBase", rules, tables)
 {
 }
Esempio n. 11
0
 public RuleEngineRule(string name, RuleEngineRule parent)
 {
     Name = name;
     Parent = parent;
 }
 private void TraverseRules(RuleEngineRule root, Action<RuleEngineRule> action)
 {
     foreach (var child in root.Children)
     {
         action(child);
         TraverseRules(root, action);
     }
 }
        public void SaveRule(RuleEngineRule ratingRule, bool forceNew = false)
        {
            var id = Convert.ToInt32(ratingRule.Id);
            var rule = Db.RuleBookRules.FirstOrDefault(p => p.Id == id && p.RuleBookId == ratingRule.RuleBookId);

            if (rule == null || rule.EffectiveDate < EffectiveDate || forceNew)
            {
                rule = new RuleBookRule
                           {
                               ChangeId = new Guid(ratingRule.ChangeId),
                               EffectiveDate = EffectiveDate
                           };

                Db.RuleBookRules.AddObject(rule);
            }

            rule.Context = ratingRule.LoopContext;
            rule.Name = ratingRule.Name;
            rule.RuleBookId = ratingRule.RuleBookId;
            rule.ParentChangeId = ratingRule.ParentChangeId;
            rule.RuleExpression = ratingRule.RuleExpression ?? "true";
            rule.Active = ratingRule.Active;
            Db.SaveChanges();
        }
        public IEnumerable<RuleEngineRule> GetRuleBookRules(int ruleBookId, Predicate<RuleEngineRule> filter, bool validate = true)
        {
            var root = new RuleEngineRule();

            var rules = GetBaseRuleBookRules(ruleBookId).ToArray();

            FillRules(filter, validate, root, rules.Where(p => p.ParentChangeId == null), rules);

            return root.Children;
        }