Ejemplo n.º 1
0
        internal static string ConvertRuleCondition(RuleCondition condition)
        {
            var builder = new StringBuilder();

            if (condition is RuleExpressionCondition)
            {
                builder.Append(ConvertRuleExpressionCondition((RuleExpressionCondition)condition));
            }
            else
            {
                throw new NotSupportedException("Unknown condition type :" + condition.GetType() + " for rule name " + condition.Name);
            }
            return(builder.ToString());
        }
Ejemplo n.º 2
0
        private void Evaluate(XmlTextWriter output, RuleCondition <RuleContext> condition, RuleContext ruleContext, RuleStack stack, Database database, XElement element)
        {
            var andCondition = condition as AndCondition <RuleContext>;

            if (andCondition != null)
            {
                Evaluate(output, andCondition.LeftOperand, ruleContext, stack, database, element.Element(0));
                if (!(bool)stack.Pop())
                {
                    stack.Push(false);
                }
                else
                {
                    Evaluate(output, andCondition.RightOperand, ruleContext, stack, database, element.Element(1));
                }

                return;
            }

            var orCondition = condition as OrCondition <RuleContext>;

            if (orCondition != null)
            {
                Evaluate(output, orCondition.LeftOperand, ruleContext, stack, database, element.Element(0));
                if ((bool)stack.Pop())
                {
                    stack.Push(true);
                }
                else
                {
                    Evaluate(output, orCondition.RightOperand, ruleContext, stack, database, element.Element(1));
                }

                return;
            }

            var notCondition = condition as NotCondition <RuleContext>;

            if (notCondition != null)
            {
                Evaluate(output, notCondition.Operand, ruleContext, stack, database, element.Element(0));

                var flag = (bool)stack.Pop();
                stack.Push(!flag);

                return;
            }

            condition.Evaluate(ruleContext, stack);

            var text = condition.GetType().Name;

            var conditionItem = database.GetItem(element.GetAttributeValue("id"));

            if (conditionItem != null)
            {
                text = Expand(database, conditionItem["Text"], element);
            }

            var result = stack.Peek();

            output.WriteElementString("entry", string.Format("        Condition \"{0}\" returned \"{1}\".", text, result.ToString()));
        }