Пример #1
0
        private Symbol ProcessAliasedQuerySource(VerificationContext context, HeD.Engine.Model.Node source)
        {
            var sourceAlias      = source.GetAttribute <String>("alias");
            var sourceExpression = source.Children[0] as ASTNode;

            if (sourceExpression == null)
            {
                throw new InvalidOperationException(String.Format("Could not determine source expression for alias '{0}'.", sourceAlias));
            }

            Verifier.Verify(context, sourceExpression);
            return(new Symbol(sourceAlias, sourceExpression.ResultType));
        }
Пример #2
0
        private SQLModel.SelectClause TranslateReturnClause(TranslationContext context, Node returnClause)
        {
            var result = new SQLModel.SelectClause();
            result.Distinct = returnClause.GetAttribute<Boolean>("distinct", true);
            var expression = returnClause.Children.Single(n => n.Name == "expression");
            if (expression.NodeType.GetLocalName() == "Tuple")
            {
                foreach (var element in expression.Children)
                {
                    var column =
                        new SQLModel.ColumnExpression
                        (
                            (Model.Expression)context.TranslateNode((ASTNode)element.Children.Single(n => n.Name == "value")),
                            element.GetAttribute<String>("name")
                        );
                }
            }

            return result;
        }
Пример #3
0
 private SQLModel.TableSpecifier TranslateAliasedQuerySource(TranslationContext context, Node source)
 {
     var expression = (ASTNode)source.Children.Where(n => n.Name == "expression").Single();
     var alias = source.GetAttribute<String>("alias");
     var sqlContext = (SQLTranslationContext)context;
     sqlContext.PushQueryContext();
     try
     {
         return new SQLModel.TableSpecifier(SQLTranslationUtilities.EnsureExpression(context.TranslateNode(expression)), alias);
     }
     finally
     {
         sqlContext.PopQueryContext();
     }
 }
Пример #4
0
        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);
            }
        }
Пример #5
0
 public static T GetAttribute <T>(this Node node, string attributeName)
 {
     return(node.GetAttribute(attributeName, default(T)));
 }
		private string GetGroupSelectionBehavior(Node node)
		{
			var behaviorsNode = node.Children.FirstOrDefault(c => c.Name == "behaviors");
			if (behaviorsNode != null)
			{
				var behaviorNode = node.Children.FirstOrDefault(c => c.Name == "behavior" && c.NodeType.GetLocalName() == "GroupSelectionBehavior");
				if (behaviorNode != null)
				{
					return node.GetAttribute<string>("value");
				}
			}

			return "All";
		}