Exemplo n.º 1
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            if (DataTypes.Equal(node.ResultType, DataTypes.DateTimeInterval))
            {
                var result = new CREFModel.DateRange();

                var beginOpen = Convert.ToBoolean(node.GetAttribute <string>("beginOpen"));
                var endOpen   = Convert.ToBoolean(node.GetAttribute <string>("endOpen"));
                if (beginOpen || endOpen)
                {
                    throw new NotSupportedException("Translation for open intervals is not supported because CREF only supports closed interval values.");
                }

                foreach (var child in node.Children)
                {
                    result.Items.Add(context.TranslateNode(child));
                }

                return(result);
            }
            else
            {
                throw new NotSupportedException("Translation for intervals with point types other than Timestamp is not supported because CREF does not support generic interval values.");
            }
        }
Exemplo n.º 2
0
        private Model.Statement TranslateExpressionDef(SQLTranslationContext context, string artifactName, ExpressionDef expressionDef)
        {
            var result = new SQLModel.CreateViewStatement();

            result.ViewName = context.GetExpressionObjectName(String.Format("{0}.{1}", artifactName, expressionDef.Name));
            var translatedExpression = context.TranslateNode(expressionDef.Expression);

            if (DataTypes.Equal(expressionDef.Expression.ResultType, DataTypes.Boolean))
            {
                translatedExpression = SQLTranslationUtilities.PromoteBooleanValuedExpression(translatedExpression);
            }

            result.Expression = SQLTranslationUtilities.EnsureSelectExpression(translatedExpression);
            return(result);
        }
Exemplo n.º 3
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.ValueExpression();

            if (DataTypes.Equal(node.ResultType, DataTypes.String))
            {
                result.Type          = Model.ValueType.String;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Integer))
            {
                result.Type          = Model.ValueType.Int32;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Boolean))
            {
                result.Type          = Model.ValueType.Boolean;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.Decimal))
            {
                result.Type          = Model.ValueType.Decimal;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");
            }
            else if (DataTypes.Equal(node.ResultType, DataTypes.DateTime))
            {
                result.Type          = Model.ValueType.Date;
                result.TypeSpecified = true;
                result.Value         = node.GetAttribute <string>("value");        // TODO: Convert to format expected by CREF
            }
            else
            {
                throw new NotSupportedException(String.Format("Unsupported literal type: {0}.", node.ResultType.Name));
            }

            return(result);
        }
Exemplo n.º 4
0
        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);
        }