예제 #1
0
        public static ExprEvaluator ValidateSizeParam(
            string viewName,
            StatementContext statementContext,
            ExprNode sizeNode,
            int expressionNumber)
        {
            var sizeEvaluator = sizeNode.ExprEvaluator;
            var returnType    = sizeEvaluator.ReturnType.GetBoxedType();

            if (!returnType.IsNumeric() ||
                returnType.IsFloatingPointClass() ||
                returnType.IsBoxedType <long>())
            {
                throw new ViewParameterException(GetViewParamMessage(viewName));
            }
            if (sizeNode.IsConstantResult)
            {
                var size = ViewFactorySupport.Evaluate(sizeEvaluator, expressionNumber, viewName, statementContext);
                if (!ValidateSize(size))
                {
                    throw new ViewParameterException(GetSizeValidationMsg(viewName, size));
                }
            }
            return(sizeEvaluator);
        }
예제 #2
0
 public static ExprEvaluator ValidateSizeSingleParam(
     string viewName,
     ViewFactoryContext viewFactoryContext,
     IList <ExprNode> expressionParameters)
 {
     ExprNode[] validated = ViewFactorySupport.Validate(
         viewName, viewFactoryContext.StatementContext, expressionParameters);
     if (validated.Length != 1)
     {
         throw new ViewParameterException(GetViewParamMessage(viewName));
     }
     return(ValidateSizeParam(viewName, viewFactoryContext.StatementContext, validated[0], 0));
 }
예제 #3
0
 public static ExprTimePeriodEvalDeltaConstFactory ValidateAndEvaluateTimeDeltaFactory(
     string viewName,
     StatementContext statementContext,
     ExprNode expression,
     string expectedMessage,
     int expressionNumber)
 {
     var streamTypeService = new StreamTypeServiceImpl(statementContext.EngineURI, false);
     ExprTimePeriodEvalDeltaConstFactory factory;
     if (expression is ExprTimePeriod)
     {
         var validated = (ExprTimePeriod) ViewFactorySupport.ValidateExpr(
             viewName, statementContext, expression, streamTypeService, expressionNumber);
         factory = validated.ConstEvaluator(new ExprEvaluatorContextStatement(statementContext, false));
     }
     else
     {
         var validated = ViewFactorySupport.ValidateExpr(
             viewName, statementContext, expression, streamTypeService, expressionNumber);
         var secondsEvaluator = validated.ExprEvaluator;
         var returnType = secondsEvaluator.ReturnType.GetBoxedType();
         if (!returnType.IsNumeric())
         {
             throw new ViewParameterException(expectedMessage);
         }
         if (validated.IsConstantResult)
         {
             var time = ViewFactorySupport.Evaluate(secondsEvaluator, 0, viewName, statementContext);
             if (!ExprTimePeriodUtil.ValidateTime(time, statementContext.TimeAbacus))
             {
                 throw new ViewParameterException(ExprTimePeriodUtil.GetTimeInvalidMsg(viewName, "view", time));
             }
             var msec = statementContext.TimeAbacus.DeltaForSecondsNumber(time);
             factory = new ExprTimePeriodEvalDeltaConstGivenDelta(msec);
         }
         else
         {
             factory = new ExprTimePeriodEvalDeltaConstFactoryMsec(secondsEvaluator, statementContext.TimeAbacus);
         }
     }
     return factory;
 }
예제 #4
0
        public static ExprTimePeriodEvalDeltaConst ValidateAndEvaluateTimeDelta(String viewName,
                                                                                StatementContext statementContext,
                                                                                ExprNode expression,
                                                                                String expectedMessage,
                                                                                int expressionNumber)
        {
            StreamTypeService            streamTypeService = new StreamTypeServiceImpl(statementContext.EngineURI, false);
            ExprTimePeriodEvalDeltaConst timeDelta;

            if (expression is ExprTimePeriod)
            {
                ExprTimePeriod validated = (ExprTimePeriod)ViewFactorySupport.ValidateExpr(viewName, statementContext, expression, streamTypeService, expressionNumber);
                timeDelta = validated.ConstEvaluator(new ExprEvaluatorContextStatement(statementContext, false));
            }
            else
            {
                var result = ViewFactorySupport.ValidateAndEvaluateExpr(viewName, statementContext, expression, streamTypeService, expressionNumber);
                if (!result.IsNumber())
                {
                    throw new ViewParameterException(expectedMessage);
                }

                long millisecondsBeforeExpiry;
                if (TypeHelper.IsFloatingPointNumber(result))
                {
                    millisecondsBeforeExpiry = (long)Math.Round(1000d * result.AsDouble());
                }
                else
                {
                    millisecondsBeforeExpiry = 1000 * result.AsLong();
                }
                timeDelta = new ExprTimePeriodEvalDeltaConstMsec(millisecondsBeforeExpiry);
            }
            if (timeDelta.DeltaMillisecondsAdd(0) < 1)
            {
                throw new ViewParameterException(viewName + " view requires a size of at least 1 msec");
            }
            return(timeDelta);
        }