public IEnumerable <VerificationException> Verify(Library library) { // Parameters must be validated without access to parameter definitions, or expression definitions var initialContext = new VerificationContext(library.Models, library.Libraries, null, null, null, null, null); // Resolve parameter types and verify default expressions foreach (var parameter in library.Parameters) { try { parameter.ParameterType = initialContext.ResolveType(parameter.TypeName); if (parameter.Default != null) { Verifier.Verify(initialContext, parameter.Default); initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType); } } catch (Exception e) { initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null); } } var context = new VerificationContext(library.Models, library.Libraries, library.Parameters, library.Expressions, library.CodeSystems, library.ValueSets, initialContext.Messages); // Verify expressions foreach (var expression in library.Expressions) { // If the result type is already set, this expression ref has already been resolved. if (expression.Expression.ResultType == null) { Verifier.Verify(context, expression.Expression); } } return(context.Messages); }
public IEnumerable<VerificationException> Verify(Library library) { // Parameters must be validated without access to parameter definitions, or expression definitions var initialContext = new VerificationContext(library.Models, library.Libraries, null, null, null, null, null); // Resolve parameter types and verify default expressions foreach (var parameter in library.Parameters) { try { parameter.ParameterType = initialContext.ResolveType(parameter.TypeName); if (parameter.Default != null) { Verifier.Verify(initialContext, parameter.Default); initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType); } } catch (Exception e) { initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null); } } var context = new VerificationContext(library.Models, library.Libraries, library.Parameters, library.Expressions, library.CodeSystems, library.ValueSets, initialContext.Messages); // Verify expressions foreach (var expression in library.Expressions) { // If the result type is already set, this expression ref has already been resolved. if (expression.Expression.ResultType == null) { Verifier.Verify(context, expression.Expression); } } return context.Messages; }
public IEnumerable <VerificationException> Verify(Artifact artifact) { // Parameters must be validated without access to parameter definitions, or expression definitions var initialContext = new VerificationContext(artifact.Models, null, null, null); // Resolve parameter types and verify default expressions foreach (var parameter in artifact.Parameters) { try { parameter.ParameterType = initialContext.ResolveType(parameter.TypeName); if (parameter.Default != null) { Verifier.Verify(initialContext, parameter.Default); initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType); } } catch (Exception e) { initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null); } } var context = new VerificationContext(artifact.Models, artifact.Parameters, artifact.Expressions, initialContext.Messages); // Verify expressions foreach (var expression in artifact.Expressions) { // If the result type is already set, this expression ref has already been resolved. if (expression.Expression.ResultType == null) { Verifier.Verify(context, expression.Expression); } } // Verify conditions foreach (var condition in artifact.Conditions) { Verifier.Verify(context, condition); if (!DataTypes.Equal(condition.ResultType, DataTypes.Boolean)) { context.ReportMessage(new InvalidOperationException("Condition must evaluate to a value of type boolean."), condition); } } // Verify trigger expressions foreach (var trigger in artifact.Triggers) { VerifyExpressionNodes(context, trigger); } // Verify action conditions if (artifact.ActionGroup != null) { var containers = new Dictionary <string, ParameterDef>(); // Verify documentation template conditions and binding expressions VerifyResponseBindings(context, artifact.ActionGroup, containers); foreach (var parameter in containers.Values) { context.AddParameterDef(parameter); } VerifyExpressionNodes(context, artifact.ActionGroup); } return(context.Messages); }
private void VerifyResponseBindings(VerificationContext context, Node node, Dictionary <string, ParameterDef> containers) { // foreach action // If DeclareResponseAction // Create a parameter with that name // If CollectInformationAction // Create a property on the appropriate parameter with the correct type // Name = responseBinding.property // Type = responseCardinality = Single ? responseDataType : List<responseDataType> try { switch (node.NodeType.GetLocalName()) { case "DeclareResponseAction": { var containerName = node.GetAttribute <string>("name"); var container = new ParameterDef { Name = containerName, ParameterType = new ObjectType(containerName + "Type", new List <PropertyDef> { }) }; containers.Add(container.Name, container); } break; case "CollectInformationAction": { var responseBinding = node.Children.FirstOrDefault(c => c.Name == "responseBinding"); if (responseBinding != null) { var containerName = responseBinding.GetAttribute <string>("container"); if (String.IsNullOrEmpty(containerName)) { containerName = "Responses"; } if (!containers.ContainsKey(containerName)) { throw new InvalidOperationException(String.Format("Could not resolve response container name {0}.", containerName)); } var container = containers[containerName]; var containerType = (ObjectType)container.ParameterType; DataType responseType = null; var responseName = responseBinding.GetAttribute <string>("property"); var documentationConcept = node.Children.FirstOrDefault(c => c.Name == "documentationConcept"); if (documentationConcept != null) { var responseDataType = documentationConcept.Children.FirstOrDefault(c => c.Name == "responseDataType"); if (responseDataType != null) { responseType = context.ResolveType(responseDataType.GetAttribute <string>("value")); } else { responseType = DataTypes.String; } var responseCardinality = documentationConcept.Children.FirstOrDefault(c => c.Name == "responseCardinality"); if (responseCardinality != null) { if (responseCardinality.GetAttribute <string>("value") == "Multiple") { responseType = new ListType(responseType); } } } if (responseType == null) { responseType = DataTypes.String; } if (containerType.Properties.FirstOrDefault(pd => pd.Name == responseName) != null) { throw new InvalidOperationException(String.Format("The response container {0} already has a response named {1}.", container.Name, responseName)); } containerType.Properties.Add(new PropertyDef(responseName, responseType)); } } break; } } catch (Exception e) { context.ReportMessage(e, node); } foreach (var child in node.Children) { VerifyResponseBindings(context, child, containers); } }
public void Verify(VerificationContext context, ASTNode node) { var valueNode = ((Node)node).Children.FirstOrDefault(c => c.Name == "value"); if (valueNode == null) { throw new InvalidOperationException("Could not resolve value element for complex literal."); } var resultType = context.ResolveType(valueNode.NodeType); node.ResultType = resultType; }
public void Verify(VerificationContext context, ASTNode node) { node.ResultType = context.ResolveType((String)node.Attributes["valueType"]); }
protected override void InternalVerify(VerificationContext context, ASTNode node) { base.InternalVerify(context, node); node.ResultType = context.ResolveType(node.GetAttribute<String>("valueType")); }
protected override void InternalVerify(VerificationContext context, ASTNode node) { base.InternalVerify(context, node); var testType = context.ResolveType(node.GetAttribute<string>("isType")); node.ResultType = DataTypes.Boolean; }
public void Verify(VerificationContext context, ASTNode node) { node.ResultType = context.ResolveType(node.GetAttribute<string>("valueType")); }
public void Verify(VerificationContext context, ASTNode node) { // Determine model type and validate relevant attributes // dataType - Must reference a valid type in a known model in the context var dataType = context.ResolveType(node.GetAttribute<string>("dataType")) as ObjectType; InternalVerify(context, node, dataType); // cardinality - If single, the result is an object type with all the properties of the type in question. var cardinality = (RequestCardinality)Enum.Parse(typeof(RequestCardinality), node.GetAttribute<string>("cardinality", "Multiple"), true); // If multiple, the result is a list type of that type. if (cardinality == RequestCardinality.Single) { node.ResultType = dataType; } else { node.ResultType = new ListType(dataType); } }
protected override void InternalVerify(VerificationContext context, ASTNode node) { base.InternalVerify(context, node); var numerator = ((Node)node).Children[0]; var denominator = ((Node)node).Children[1]; var numeratorType = context.ResolveType(numerator.NodeType); var denominatorType = context.ResolveType(denominator.NodeType); context.VerifyType(numeratorType, DataTypes.Quantity); context.VerifyType(denominatorType, DataTypes.Quantity); node.ResultType = DataTypes.ResolveType(typeof(RTO)); }
public void Verify(VerificationContext context, ASTNode node) { // objectType var objectTypeName = node.GetAttribute<string>("classType"); if (objectTypeName != null) { var objectType = context.ResolveType(node.GetAttribute<string>("classType")) as ObjectType; // foreach property foreach (var child in ((Node)node).Children) { if (child.Name == "element") { // Verify the property exists var childPropertyType = context.ResolveProperty(objectType, child.GetAttribute<string>("name")); // Verify the value var value = (ASTNode)child.Children[0]; Verifier.Verify(context, value); // Verify the value type is appropriate for the property type context.VerifyType(value.ResultType, childPropertyType); } } node.ResultType = objectType; } else { var propertyList = new List<PropertyDef>(); foreach (var child in ((Node)node).Children) { if (child.Name == "element") { var value = (ASTNode)child.Children[0]; Verifier.Verify(context, value); var property = new PropertyDef(child.GetAttribute<string>("name"), value.ResultType); propertyList.Add(property); } } var objectType = new ObjectType(Guid.NewGuid().ToString(), propertyList); node.ResultType = objectType; } }
public IEnumerable<VerificationException> Verify(Artifact artifact) { // Parameters must be validated without access to parameter definitions, or expression definitions var initialContext = new VerificationContext(artifact.Models, null, null, null); // Resolve parameter types and verify default expressions foreach (var parameter in artifact.Parameters) { try { parameter.ParameterType = initialContext.ResolveType(parameter.TypeName); if (parameter.Default != null) { Verifier.Verify(initialContext, parameter.Default); initialContext.VerifyType(parameter.Default.ResultType, parameter.ParameterType); } } catch (Exception e) { initialContext.ReportMessage(new VerificationException(String.Format("Exceptions occurred verifying parameter {0}.", parameter.Name), e), null); } } var context = new VerificationContext(artifact.Models, artifact.Parameters, artifact.Expressions, initialContext.Messages); // Verify expressions foreach (var expression in artifact.Expressions) { // If the result type is already set, this expression ref has already been resolved. if (expression.Expression.ResultType == null) { Verifier.Verify(context, expression.Expression); } } // Verify conditions foreach (var condition in artifact.Conditions) { Verifier.Verify(context, condition); if (!DataTypes.Equal(condition.ResultType, DataTypes.Boolean)) { context.ReportMessage(new InvalidOperationException("Condition must evaluate to a value of type boolean."), condition); } } // Verify trigger expressions foreach (var trigger in artifact.Triggers) { VerifyExpressionNodes(context, trigger); } // Verify action conditions if (artifact.ActionGroup != null) { var containers = new Dictionary<string, ParameterDef>(); // Verify documentation template conditions and binding expressions VerifyResponseBindings(context, artifact.ActionGroup, containers); foreach (var parameter in containers.Values) { context.AddParameterDef(parameter); } VerifyExpressionNodes(context, artifact.ActionGroup); } return context.Messages; }
private void VerifyResponseBindings(VerificationContext context, Node node, Dictionary<string, ParameterDef> containers) { // foreach action // If DeclareResponseAction // Create a parameter with that name // If CollectInformationAction // Create a property on the appropriate parameter with the correct type // Name = responseBinding.property // Type = responseCardinality = Single ? responseDataType : List<responseDataType> try { switch (node.NodeType.GetLocalName()) { case "DeclareResponseAction" : { var containerName = node.GetAttribute<string>("name"); var container = new ParameterDef { Name = containerName, ParameterType = new ObjectType(containerName + "Type", new List<PropertyDef> { }) }; containers.Add(container.Name, container); } break; case "CollectInformationAction" : { var responseBinding = node.Children.FirstOrDefault(c => c.Name == "responseBinding"); if (responseBinding != null) { var containerName = responseBinding.GetAttribute<string>("container"); if (String.IsNullOrEmpty(containerName)) { containerName = "Responses"; } if (!containers.ContainsKey(containerName)) { throw new InvalidOperationException(String.Format("Could not resolve response container name {0}.", containerName)); } var container = containers[containerName]; var containerType = (ObjectType)container.ParameterType; DataType responseType = null; var responseName = responseBinding.GetAttribute<string>("property"); var documentationConcept = node.Children.FirstOrDefault(c => c.Name == "documentationConcept"); if (documentationConcept != null) { var responseDataType = documentationConcept.Children.FirstOrDefault(c => c.Name == "responseDataType"); if (responseDataType != null) { responseType = context.ResolveType(responseDataType.GetAttribute<string>("value")); } else { responseType = DataTypes.String; } var responseCardinality = documentationConcept.Children.FirstOrDefault(c => c.Name == "responseCardinality"); if (responseCardinality != null) { if (responseCardinality.GetAttribute<string>("value") == "Multiple") { responseType = new ListType(responseType); } } } if (responseType == null) { responseType = DataTypes.String; } if (containerType.Properties.FirstOrDefault(pd => pd.Name == responseName) != null) { throw new InvalidOperationException(String.Format("The response container {0} already has a response named {1}.", container.Name, responseName)); } containerType.Properties.Add(new PropertyDef(responseName, responseType)); } } break; } } catch (Exception e) { context.ReportMessage(e, node); } foreach (var child in node.Children) { VerifyResponseBindings(context, child, containers); } }