private int Position(AssertionContext contextObj) { DesignByContract.Check.Require(this.functionName.Equals("position", StringComparison.InvariantCultureIgnoreCase), "functionName must be position"); AssertionContext parent = contextObj.Parent; System.Collections.IList list = parent.Data as System.Collections.IList; if (list != null) { return(list.IndexOf(contextObj.Data)); } AssumedTypes.IList assumedList = parent.Data as AssumedTypes.IList; if (assumedList != null) { for (int i = 0; i < assumedList.Count; i++) { if (contextObj.Data.Equals(assumedList[i])) { return(i + 1); } } } return(-1); }
internal override AssertionContext Evaluate(AssertionContext contextObj) { if (this.pathSteps == null || this.pathSteps.Count == 0) return contextObj; AssertionContext tempContext = contextObj; foreach (PathStep pathStep in this.pathSteps) { string attributeName = pathStep.Attribute; if (attributeName !="//*" && attributeName!="/*") { object attrObj = CallGetAttributeObject(attributeName, tempContext.Data); if (attrObj == null) return null; tempContext = new AssertionContext(attrObj, tempContext); tempContext = ProcessPathPartWithAttrObject(tempContext, pathStep); } else // deal with path starts with wildcard key //* { // only consider all properties of the rootObject children if (attributeName == "/*") { // get all attribute object rootObj = tempContext.Data; tempContext = ProcessPathPartWithAllProperties(tempContext, pathStep); } else { if (attributeName != "//*") throw new ApplicationException("anyAttribute must be //*, but it's " + attributeName); if (pathStep.ArchetypeNodeId.StartsWith("openehr", StringComparison.InvariantCultureIgnoreCase) || !string.IsNullOrEmpty(pathStep.NodePattern)) { AssertionContext archetypesContext = ProcessPathPartWithWildcardForArId(tempContext, pathStep); if (archetypesContext == null) return null; tempContext = ProcessPathPartWithAttrObject(archetypesContext, pathStep); } else throw new NotSupportedException("//*[none archetypeId] path not supported."); } } if (tempContext == null) return null; } return tempContext; }
internal AssertionContext Evaluate(AssertionContext contextObj) { if (contextObj == null) return null; AssumedTypes.IList assumedIList = contextObj.Data as AssumedTypes.IList; if (assumedIList != null) { AssumedTypes.List<object> results = new OpenEhr.AssumedTypes.List<object>(); foreach (object obj in assumedIList) { AssertionContext assertObj = new AssertionContext(obj, contextObj); AssertionContext evaluateResult = Evaluate(assertObj); if (evaluateResult != null) { AssumedTypes.List<object> aList = evaluateResult.Data as AssumedTypes.List<object>; if (aList == null) results.Add(evaluateResult.Data); else foreach (object o in aList) results.Add(o); } } if (results.Count == 0) return null; return new AssertionContext(results, contextObj); } System.Collections.IList list = contextObj.Data as System.Collections.IList; if (list == null) { return EvaluateSingleAttri(contextObj); } else { AssumedTypes.List<object> results = new AssumedTypes.List<object>(); foreach (object obj in list) { AssertionContext assertObj = new AssertionContext(obj, contextObj); AssertionContext evaluateResult = Evaluate(assertObj); if (evaluateResult != null) results.Add(evaluateResult.Data); } if (results.Count == 0) return null; return new AssertionContext(results, contextObj); } }
internal override AssertionContext Evaluate(AssertionContext contextObj) { DesignByContract.Check.Require(!string.IsNullOrEmpty(this.functionName), "functionName must not be null or empty."); switch (this.functionName) { case "position": int position = Position(contextObj); return new AssertionContext(position, null); default: throw new NotImplementedException(this.functionName + " function is not implemented."); } }
internal override AssertionContext Evaluate(AssertionContext contextObj) { DesignByContract.Check.Require(!string.IsNullOrEmpty(this.functionName), "functionName must not be null or empty."); switch (this.functionName) { case "position": int position = Position(contextObj); return(new AssertionContext(position, null)); default: throw new NotImplementedException(this.functionName + " function is not implemented."); } }
internal override OpenEhr.Paths.AssertionContext Evaluate (OpenEhr.Paths.AssertionContext obj) { switch (this.ReferenceType.ToLower(System.Globalization.CultureInfo.InvariantCulture)) { case "constraint": case "pattern": return(new OpenEhr.Paths.AssertionContext(this.Item, obj)); case "path": string path = this.item.ToString(); Path pathProcessor = new Path(path); object objectAtPath = pathProcessor.ItemAtPath(obj.Data); return(new OpenEhr.Paths.AssertionContext(objectAtPath, obj)); default: throw new ApplicationException(string.Format( AmValidationStrings.UnsupportedExprLeafReferenceType, this.ReferenceType)); } }
private int Position(AssertionContext contextObj) { DesignByContract.Check.Require(this.functionName.Equals("position", StringComparison.InvariantCultureIgnoreCase), "functionName must be position"); AssertionContext parent = contextObj.Parent; System.Collections.IList list = parent.Data as System.Collections.IList; if (list != null) { return list.IndexOf(contextObj.Data); } AssumedTypes.IList assumedList = parent.Data as AssumedTypes.IList; if(assumedList != null) for (int i = 0; i < assumedList.Count; i++) { if (contextObj.Data.Equals(assumedList[i])) return i+1; } return -1; }
private AssertionContext ProcessPathPartWithAllProperties(AssertionContext rootObjContext, PathStep pathStep) { DesignByContract.Check.Require(rootObjContext != null && rootObjContext.Data != null, "attributeObjContext and attributeObjContext.Data must not be null."); object rootObj = rootObjContext.Data; AssumedTypes.List <object> objList = new OpenEhr.AssumedTypes.List <object>(); // go through all properties System.Reflection.PropertyInfo[] allProperties = rootObj.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance); foreach (System.Reflection.PropertyInfo property in allProperties) { object propertyValue = property.GetValue(rootObj, null); if (propertyValue != null) { AssertionContext propertyContext = new AssertionContext(propertyValue, rootObjContext); AssertionContext tempContext = ProcessPathPartWithAttrObject(propertyContext, pathStep); if (tempContext != null && tempContext.Data != null) { objList.Add(tempContext.Data); } } } if (objList.Count == 0) { return(null); } if (objList.Count == 1) { return(new AssertionContext(objList[0], rootObjContext)); } return(new AssertionContext(objList, rootObjContext)); }
internal AssertionContext EvaluateSingleAttri(AssertionContext contextObj) { System.Collections.IList list = contextObj.Data as System.Collections.IList; if (list != null) { throw new ApplicationException("contextObj.Data must not be a list."); } AssertionContext obj = this.predicate.Evaluate(contextObj); bool boolValue = false; if (bool.TryParse(obj.Data.ToString(), out boolValue)) { if (boolValue == true) { return(contextObj); } return(null); } throw new ApplicationException("obj must be type of boolean value."); }
private AssertionContext ProcessPathPartWithAttrObject(AssertionContext attributeObjContext, PathStep pathStep) { DesignByContract.Check.Require(attributeObjContext != null && attributeObjContext.Data != null, "attributeObjContext and attributeObjContext.Data must not be null."); AssertionContext tempContext = attributeObjContext; if (pathStep.Predicates != null) { foreach (PredicateExpr predicate in pathStep.Predicates) { AssertionContext predicateObj = predicate.Evaluate(tempContext); if (predicateObj == null) { return(null); } tempContext = predicateObj; } } return(tempContext); }
internal AssertionContext Evaluate(AssertionContext contextObj) { if (contextObj == null) { return(null); } AssumedTypes.IList assumedIList = contextObj.Data as AssumedTypes.IList; if (assumedIList != null) { AssumedTypes.List <object> results = new OpenEhr.AssumedTypes.List <object>(); foreach (object obj in assumedIList) { AssertionContext assertObj = new AssertionContext(obj, contextObj); AssertionContext evaluateResult = Evaluate(assertObj); if (evaluateResult != null) { AssumedTypes.List <object> aList = evaluateResult.Data as AssumedTypes.List <object>; if (aList == null) { results.Add(evaluateResult.Data); } else { foreach (object o in aList) { results.Add(o); } } } } if (results.Count == 0) { return(null); } return(new AssertionContext(results, contextObj)); } System.Collections.IList list = contextObj.Data as System.Collections.IList; if (list == null) { return(EvaluateSingleAttri(contextObj)); } else { AssumedTypes.List <object> results = new AssumedTypes.List <object>(); foreach (object obj in list) { AssertionContext assertObj = new AssertionContext(obj, contextObj); AssertionContext evaluateResult = Evaluate(assertObj); if (evaluateResult != null) { results.Add(evaluateResult.Data); } } if (results.Count == 0) { return(null); } return(new AssertionContext(results, contextObj)); } }
internal AssertionContext(object data, AssertionContext parent) { this.data = data; this.parent = parent; }
internal AssertionContext EvaluateSingleAttri(AssertionContext contextObj) { System.Collections.IList list = contextObj.Data as System.Collections.IList; if (list != null) throw new ApplicationException("contextObj.Data must not be a list."); AssertionContext obj = this.predicate.Evaluate(contextObj); bool boolValue = false; if (bool.TryParse(obj.Data.ToString(), out boolValue)) { if (boolValue == true) return contextObj; return null; } throw new ApplicationException("obj must be type of boolean value."); }
internal override AssertionContext Evaluate(AssertionContext contextObj) { if (this.pathSteps == null || this.pathSteps.Count == 0) { return(contextObj); } AssertionContext tempContext = contextObj; foreach (PathStep pathStep in this.pathSteps) { string attributeName = pathStep.Attribute; if (attributeName != "//*" && attributeName != "/*") { object attrObj = CallGetAttributeObject(attributeName, tempContext.Data); if (attrObj == null) { return(null); } tempContext = new AssertionContext(attrObj, tempContext); tempContext = ProcessPathPartWithAttrObject(tempContext, pathStep); } else // deal with path starts with wildcard key //* { // only consider all properties of the rootObject children if (attributeName == "/*") { // get all attribute object rootObj = tempContext.Data; tempContext = ProcessPathPartWithAllProperties(tempContext, pathStep); } else { if (attributeName != "//*") { throw new ApplicationException("anyAttribute must be //*, but it's " + attributeName); } if (pathStep.ArchetypeNodeId.StartsWith("openehr", StringComparison.InvariantCultureIgnoreCase) || !string.IsNullOrEmpty(pathStep.NodePattern)) { AssertionContext archetypesContext = ProcessPathPartWithWildcardForArId(tempContext, pathStep); if (archetypesContext == null) { return(null); } tempContext = ProcessPathPartWithAttrObject(archetypesContext, pathStep); } else { throw new NotSupportedException("//*[none archetypeId] path not supported."); } } } if (tempContext == null) { return(null); } } return(tempContext); }
private AssertionContext ProcessPathPartWithWildcardForArId(AssertionContext contextObj, PathStep pathStep) { DesignByContract.Check.Require(pathStep.Attribute == "//*", "anyAttribute value must be //*."); Locatable locatable = contextObj.Data as Locatable; if (locatable != null) { ArchetypedPathProcessor archetypePathProcessor = new ArchetypedPathProcessor(locatable); string archetypePathWithWildcardKey = null; if (!string.IsNullOrEmpty(pathStep.ArchetypeNodeId)) { archetypePathWithWildcardKey = pathStep.Attribute + "[" + pathStep.ArchetypeNodeId + "]"; } else if (!string.IsNullOrEmpty(pathStep.NodePattern)) { archetypePathWithWildcardKey = pathStep.Attribute + "[{/" + pathStep.NodePattern + "/}]"; } else { throw new NotSupportedException(pathStep.Value + " path not supported"); } object obj = null; if (!archetypePathProcessor.PathExists(archetypePathWithWildcardKey)) { return(null); } if (archetypePathProcessor.PathUnique(archetypePathWithWildcardKey)) { obj = archetypePathProcessor.ItemAtPath(archetypePathWithWildcardKey); } else { obj = archetypePathProcessor.ItemsAtPath(archetypePathWithWildcardKey); } if (obj == null) { throw new ApplicationException("obj must not be null."); } return(new AssertionContext(obj, contextObj)); } AssumedTypes.IList ilist = contextObj.Data as AssumedTypes.IList; if (ilist == null) { throw new ApplicationException("only support either locatable or ilist"); } AssumedTypes.List <object> results = new OpenEhr.AssumedTypes.List <object>(); foreach (Locatable locatableItem in ilist) { AssertionContext assertionContext = new AssertionContext(locatableItem, contextObj); AssertionContext result = ProcessPathPartWithWildcardForArId(assertionContext, pathStep); if (result != null && result.Data != null) { results.Add(result.Data); } } if (results.Count > 0) { return(new AssertionContext(results, contextObj)); } return(null); }
private AssertionContext ProcessPathPartWithWildcardForArId(AssertionContext contextObj, PathStep pathStep) { DesignByContract.Check.Require(pathStep.Attribute == "//*", "anyAttribute value must be //*."); Locatable locatable = contextObj.Data as Locatable; if (locatable != null) { ArchetypedPathProcessor archetypePathProcessor = new ArchetypedPathProcessor(locatable); string archetypePathWithWildcardKey = null; if (!string.IsNullOrEmpty(pathStep.ArchetypeNodeId)) archetypePathWithWildcardKey = pathStep.Attribute + "[" + pathStep.ArchetypeNodeId + "]"; else if (!string.IsNullOrEmpty(pathStep.NodePattern)) archetypePathWithWildcardKey = pathStep.Attribute + "[{/" + pathStep.NodePattern + "/}]"; else throw new NotSupportedException(pathStep.Value+" path not supported"); object obj = null; if (!archetypePathProcessor.PathExists(archetypePathWithWildcardKey)) return null; if (archetypePathProcessor.PathUnique(archetypePathWithWildcardKey)) obj = archetypePathProcessor.ItemAtPath(archetypePathWithWildcardKey); else obj = archetypePathProcessor.ItemsAtPath(archetypePathWithWildcardKey); if (obj == null) throw new ApplicationException("obj must not be null."); return new AssertionContext(obj, contextObj); } AssumedTypes.IList ilist = contextObj.Data as AssumedTypes.IList; if (ilist == null) throw new ApplicationException("only support either locatable or ilist"); AssumedTypes.List<object> results = new OpenEhr.AssumedTypes.List<object>(); foreach (Locatable locatableItem in ilist) { AssertionContext assertionContext = new AssertionContext(locatableItem, contextObj); AssertionContext result = ProcessPathPartWithWildcardForArId(assertionContext, pathStep); if (result != null && result.Data != null) results.Add(result.Data); } if (results.Count > 0) return new AssertionContext(results, contextObj); return null; }
private AssertionContext ProcessPathPartWithAttrObject(AssertionContext attributeObjContext, PathStep pathStep) { DesignByContract.Check.Require(attributeObjContext != null && attributeObjContext.Data != null, "attributeObjContext and attributeObjContext.Data must not be null."); AssertionContext tempContext = attributeObjContext; if (pathStep.Predicates != null) { foreach (PredicateExpr predicate in pathStep.Predicates) { AssertionContext predicateObj = predicate.Evaluate(tempContext); if (predicateObj == null) return null; tempContext = predicateObj; } } return tempContext; }
private AssertionContext ProcessPathPartWithAllProperties(AssertionContext rootObjContext, PathStep pathStep) { DesignByContract.Check.Require(rootObjContext != null && rootObjContext.Data != null, "attributeObjContext and attributeObjContext.Data must not be null."); object rootObj = rootObjContext.Data; AssumedTypes.List<object> objList = new OpenEhr.AssumedTypes.List<object>(); // go through all properties System.Reflection.PropertyInfo[] allProperties = rootObj.GetType().GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance); foreach (System.Reflection.PropertyInfo property in allProperties) { object propertyValue = property.GetValue(rootObj, null); if (propertyValue != null) { AssertionContext propertyContext = new AssertionContext(propertyValue, rootObjContext); AssertionContext tempContext = ProcessPathPartWithAttrObject(propertyContext, pathStep); if (tempContext != null && tempContext.Data != null) { objList.Add(tempContext.Data); } } } if (objList.Count == 0) return null; if (objList.Count == 1) return new AssertionContext(objList[0], rootObjContext); return new AssertionContext(objList, rootObjContext); }