Beispiel #1
0
        public static TimePeriodComputeForge ValidateAndEvaluateTimeDeltaFactory(
            string viewName,
            ExprNode expression,
            string expectedMessage,
            int expressionNumber,
            ViewForgeEnv viewForgeEnv,
            int streamNumber)
        {
            StreamTypeService streamTypeService = new StreamTypeServiceImpl(false);
            TimePeriodComputeForge forge;
            if (expression is ExprTimePeriod) {
                var validated = (ExprTimePeriod) ViewForgeSupport.ValidateExpr(
                    viewName,
                    expression,
                    streamTypeService,
                    viewForgeEnv,
                    expressionNumber,
                    streamNumber);
                forge = validated.TimePeriodComputeForge;
            }
            else {
                var validated = ViewForgeSupport.ValidateExpr(
                    viewName,
                    expression,
                    streamTypeService,
                    viewForgeEnv,
                    expressionNumber,
                    streamNumber);
                var returnType = validated.Forge.EvaluationType.GetBoxedType();
                if (!returnType.IsNumeric()) {
                    throw new ViewParameterException(expectedMessage);
                }

                if (validated.Forge.ForgeConstantType.IsCompileTimeConstant) {
                    var timeAbacus = viewForgeEnv.ImportServiceCompileTime.TimeAbacus;
                    var secondsEvaluator = validated.Forge.ExprEvaluator;
                    var time = ViewForgeSupport.Evaluate(secondsEvaluator, 0, viewName);
                    if (!time.IsNumber()) {
                        throw new IllegalStateException(nameof(time) + " is not a number");
                    }

                    if (!ExprTimePeriodUtil.ValidateTime(time, timeAbacus)) {
                        throw new ViewParameterException(ExprTimePeriodUtil.GetTimeInvalidMsg(viewName, "view", time));
                    }

                    var msec = timeAbacus.DeltaForSecondsNumber(time);
                    forge = new TimePeriodComputeConstGivenDeltaForge(msec);
                }
                else {
                    forge = new TimePeriodComputeNCGivenExprForge(
                        validated.Forge,
                        viewForgeEnv.ImportServiceCompileTime.TimeAbacus);
                }
            }

            return forge;
        }
Beispiel #2
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;
 }