示例#1
0
        public RuleEngineResult <Telement> ExecuteStepTopDown(Telement item)
        {
            RuleEngineResult <Telement>  result         = new RuleEngineResult <Telement>();
            IList <RuleBase <Telement> > appliableRules = (from rule in Rules where rule.Source != null && rule.Source.Id.Equals(item.Id) select rule).ToList <RuleBase <Telement> >();

            result.isValid = (appliableRules.Count == 0);

            foreach (var rule in appliableRules)
            {
                Boolean res = false;

                if (rule.Source.OverrideRules)
                {
                    res = true;
                }
                else
                {
                    res = rule.Execute();
                }

                result.isValid = result.isValid || res;

                if (!res)
                {
                    result.ViolatedRules.Add(rule);
                }
                else
                {
                    result.ValidRules.Add(rule);
                }
            }


            return(result);
        }
示例#2
0
        public IList <KeyValuePair <Telement, RuleEngineResult <Telement> > > ExecuteFromTop(Telement item, IList <KeyValuePair <Telement, RuleEngineResult <Telement> > > previous = null)
        {
            IList <KeyValuePair <Telement, RuleEngineResult <Telement> > > result = previous;

            if (result == null)
            {
                result  = new List <KeyValuePair <Telement, RuleEngineResult <Telement> > >();
                visited = new List <Telement>();
            }

            if (!visited.Contains(item))
            {
                visited.Add(item);
                RuleEngineResult <Telement> res = ExecuteStepTopDown(item);

                result.Add(new KeyValuePair <Telement, RuleEngineResult <Telement> >(item, res));

                foreach (var rule in res.ValidRules)
                {
                    ExecuteFromTop(rule.Destination, result);
                }
            }
            return(result);
        }