コード例 #1
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;
 }
コード例 #2
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);
        }