protected override void FillObject(FillObjectRequest req) { XmlNode valuesNode = req.Descriptor.Element.SelectSingleNode(RuleConstants.ValuesNodeName); if (valuesNode?.HasChildNodes == true) { foreach (XmlNode valueNode in valuesNode.ChildNodes) { RuleExpression valueElement = SerializerRoot.Container <RuleExpression>() .Deserialize(new XmlDescriptor() { Element = valueNode }, req.Parent); (req.Element as Case).ValuesElements.Add(valueElement); } } XmlNode actionNode = req.Descriptor.Element.SelectSingleNode(RuleConstants.ActionNodeName); if (actionNode != null) { (req.Element as Case).ActionElement = SerializerRoot.Container <ExecContainer>() .Deserialize(new XmlDescriptor() { Element = actionNode }, req.Parent); } }
public virtual bool ValueExpressionEquals(RuleExpression entity) { return((entity != null) //&& entity is RuleExpression && ValueExpression.Equals(entity.ValueExpression)); //&& this == (RuleExpression<ExpType>)entity; }
protected override void Validate() { if (ChildElements.Count == 0) { AddBrokenConstraint(LogicalExpressionBusinessConstraint.ChildrenRequired, ElementName); } if (ChildElements.Count < 2) { AddBrokenConstraint(LogicalExpressionBusinessConstraint.NotEnoughChildren, ElementName); } RuleExpression exp1 = null; RuleExpression exp2 = null; for (int i = 0; i < ChildElements.Count; i++) { exp2 = ChildElements[i]; if (exp2 == null) { AddBrokenConstraint(LogicalExpressionBusinessConstraint.InvalidChild, ElementName); } else { //Проверяем, элемент с каким выходным типом значения //сравниваем ExpressionType элементов if (exp1?.ExpressionTypeEquals(exp2) == false) { AddBrokenConstraint(LogicalExpressionBusinessConstraint.TypeMismatch, ElementName); } } exp1 = exp2; } }
protected override void Validate() { if (ValuesElements.Count == 0) { AddBrokenConstraint(CaseBusinessConstraint.ValuesRequired, ElementName); } RuleExpression prevValueElement = null; foreach (RuleExpression valueElement in ValuesElements) { //проверяем, одного ли типа элементы if (prevValueElement != null) { if (prevValueElement.ExpressionType != valueElement.ExpressionType) { AddBrokenConstraint(CaseBusinessConstraint.ValuesTypeMismatch, ElementName); } } prevValueElement = valueElement; } if (ActionElement == null) { AddBrokenConstraint(CaseBusinessConstraint.ActionsRequired, ElementName); } }
protected override bool Operate(RuleExpression exp1, RuleExpression exp2, bool?previousValue) { int compared = ((RuleComparableExpression)exp1).CompareTo((RuleComparableExpression)exp2); bool result = (compared >= 0); return((previousValue != null) ? (result && (bool)previousValue) : result); }
public override bool ExpressionTypeEquals(RuleExpression entity) { if (IsValid) { return(ValuesElements.First().ExpressionTypeEquals(entity)); } return(false); }
public override bool ValueCalculatedEquals(RuleExpression entity) { foreach (RuleExpression valueElement in ValuesElements) { if (valueElement.ValueCalculatedEquals(entity)) { return(true); } } return(false); }
protected override void InnerInterpret(IRuleHandler handler) { RuleExpression exp1 = null; RuleExpression exp2 = null; bool?expValue = null; for (int i = 0; i < ChildElements.Count; i++) { exp2 = ChildElements[i]; exp2.Interpret(handler); if (exp1 != null) { expValue = Operate(exp1, exp2, expValue); } exp1 = exp2; } ValueCalculated = expValue; }
protected override bool Operate(RuleExpression exp1, RuleExpression exp2, bool?previousValue) { return((previousValue != null) ? ((bool)exp1.ValueCalculated && (bool)exp2.ValueCalculated && (bool)previousValue) : ((bool)exp1.ValueCalculated && (bool)exp2.ValueCalculated)); }
//public virtual bool ValueCalculatedEquals(RuleExpression exp) //{ // return (exp?.ValueCalculatedEquals(this) == true); //} /// <summary> /// Метод сравнивает типы выражений объектов /// </summary> /// <param name="obj"></param> /// <returns></returns> public bool ExpressionTypeEquals(RuleExpression obj) { return((obj != null) && ExpressionType.Equals(obj.ExpressionType)); }
protected override bool Operate(RuleExpression exp1, RuleExpression exp2, bool?previousValue) { bool result = (int)exp1.ValueCalculated <= (int)exp2.ValueCalculated; return((previousValue != null) ? (result && (bool)previousValue) : result); }
/// <summary> /// Метод должен быть реализован во всех наследниках. Используется в методе InnerInterpret /// </summary> /// <param name="previousValue">предыдущее значение в цепочке</param> /// <returns></returns> protected abstract bool Operate(RuleExpression exp1, RuleExpression exp2, bool?previousValue);
public abstract bool ValueCalculatedEquals(RuleExpression entity);
public abstract bool ExpressionTypeEquals(RuleExpression entity);