public void ValidateConstraint(Element element, Constraint constraint) { if (constraint.IsValid) { Log(Group.Constraint, Status.Valid, "Constraint is valid"); } else { Log(Group.Constraint, Status.Failed, "Constraint [{0}] ({1}) has an invalid XPath: {2}", constraint.Name, constraint.HumanReadable, constraint.CompilerError.Message); } }
private void HarvestConstraints(Profile.ElementDefinitionComponent source, Element target) { if (source.Constraint == null) return; foreach(Profile.ElementDefinitionConstraintComponent c in source.Constraint) { Constraint constraint = new Constraint(); constraint.Name = c.Name ?? c.Key; constraint.XPath = c.Xpath; constraint.HumanReadable = c.Human; target.Constraints.Add(constraint); } }
public void ValidateConstraint(Vector vector, Constraint constraint) { if (constraint.IsValid) { try { bool valid = vector.Evaluate(constraint); if (valid) Log(Group.Constraint, Status.Valid, vector, "Node [{0}] conforms to constraint [{1}]", vector.Node.Name, constraint.Name); else Log(Group.Constraint, Status.Failed, vector, "Node [{0}] does not conform to constraint [{1}]: \"{2}\" ", vector.Node.Name, constraint.Name, constraint.HumanReadable); } catch (XPathException e) { Log(Group.Constraint, Status.Failed, vector, "Evaluation of constraint [{0}] evaluation failed: {1}", constraint.Name, e.Message); } } }
public bool Evaluate(Constraint constraint) { bool valid = (bool)Node.Evaluate(constraint.Expression); return valid; }
public void ReadConstraints(Element element, XPathNavigator node) { foreach (XPathNavigator nav in node.Select("f:definition/f:constraint", ns)) { Constraint constraint = new Constraint(); XPathNavigator xName = nav.SelectSingleNode("f:name/@value", ns); string key = OptionalValue(nav, "f:key/@value"); constraint.Name = (xName != null) ? xName.Value : element.Path+", Key:"+key; constraint.XPath = nav.SelectSingleNode("f:xpath/@value", ns).Value; constraint.HumanReadable = OptionalValue(nav, "f:human/@value"); element.Constraints.Add(constraint); } }