Esempio n. 1
0
        /// <summary>
        /// Returns the number of milliseconds.
        /// </summary>
        public long GetScheduleForwardDelta(long fromTime, AgentInstanceContext agentInstanceContext)
        {
            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().QRegIntervalValue(TimePeriodExpr);
            }
            if (_timeDeltaComputation == null)
            {
                _timeDeltaComputation = TimePeriodExpr.ConstEvaluator(new ExprEvaluatorContextStatement(agentInstanceContext.StatementContext, false));
            }
            long result = _timeDeltaComputation.DeltaMillisecondsAdd(fromTime);

            if (InstrumentationHelper.ENABLED)
            {
                InstrumentationHelper.Get().ARegIntervalValue(result);
            }
            return(result);
        }
Esempio n. 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);
        }