public long ComputeMilliseconds(MatchedEventMap beginState, PatternAgentInstanceContext context)
        {
            if (_parameter is ExprTimePeriod)
            {
                ExprTimePeriod timePeriod = (ExprTimePeriod)_parameter;
                return(timePeriod.NonconstEvaluator().DeltaMillisecondsUseEngineTime(
                           _convertor.Convert(beginState), context.AgentInstanceContext));
            }
            else
            {
                var result = _parameter.ExprEvaluator.Evaluate(new EvaluateParams(_convertor.Convert(beginState), true, context.AgentInstanceContext));
                if (result == null)
                {
                    throw new EPException("Null value returned for guard expression");
                }

                if (result.IsFloatingPointNumber())
                {
                    return((long)Math.Round(1000d * result.AsDouble()));
                }
                else
                {
                    return(1000 * result.AsLong());
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="objectName">is the pattern object name</param>
        /// <param name="beginState">the pattern begin state</param>
        /// <param name="parameters">object parameters</param>
        /// <param name="convertor">for converting to a event-per-stream view for use to evaluate expressions</param>
        /// <param name="exprEvaluatorContext">expression evaluation context</param>
        /// <exception cref="EPException">if the evaluate failed</exception>
        /// <returns>expression results</returns>
        public static IList <Object> Evaluate(
            string objectName,
            MatchedEventMap beginState,
            IList <ExprNode> parameters,
            MatchedEventConvertor convertor,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            var results = new List <Object>();
            int count   = 0;

            EventBean[] eventsPerStream = convertor.Convert(beginState);
            foreach (ExprNode expr in parameters)
            {
                try
                {
                    Object result = Evaluate(objectName, expr, eventsPerStream, exprEvaluatorContext);
                    results.Add(result);
                    count++;
                }
                catch (Exception ex)
                {
                    string message = objectName + " invalid parameter in expression " + count;
                    if (!string.IsNullOrEmpty(ex.Message))
                    {
                        message += ": " + ex.Message;
                    }
                    Log.Error(message, ex);
                    throw new EPException(message);
                }
            }
            return(results);
        }
Beispiel #3
0
        public bool Inspect(MatchedEventMap matchEvent)
        {
            EventBean[] eventsPerStream = _convertor.Convert(matchEvent);

            try
            {
                var evaluateParams = new EvaluateParams(eventsPerStream, true, _quitable.Context.AgentInstanceContext);
                var result         = _expression.Evaluate(evaluateParams);
                if (result == null)
                {
                    return(false);
                }

                if (true.Equals(result))
                {
                    return(true);
                }

                _quitable.GuardQuit();
                return(false);
            }
            catch (Exception ex)
            {
                String message = "Failed to evaluate expression for pattern-guard for statement '" + _quitable.Context.PatternContext.StatementName + "'";
                if (ex.Message != null)
                {
                    message += ": " + ex.Message;
                }
                Log.Error(message, ex);
                throw new EPException(message);
            }
        }
 public long ComputeDelta(MatchedEventMap beginState, PatternAgentInstanceContext context)
 {
     if (_parameter is ExprTimePeriod)
     {
         var timePeriod = (ExprTimePeriod)_parameter;
         return(timePeriod.NonconstEvaluator()
                .DeltaUseEngineTime(_convertor.Convert(beginState), context.AgentInstanceContext));
     }
     else
     {
         var result = _parameter.ExprEvaluator.Evaluate(
             new EvaluateParams(_convertor.Convert(beginState), true, context.AgentInstanceContext));
         if (result == null)
         {
             throw new EPException("Null value returned for guard expression");
         }
         return(context.StatementContext.TimeAbacus.DeltaForSecondsNumber(result));
     }
 }
Beispiel #5
0
 public static Object Evaluate(
     string objectName,
     MatchedEventMap beginState,
     ExprNode parameter,
     MatchedEventConvertor convertor,
     ExprEvaluatorContext exprEvaluatorContext)
 {
     EventBean[] eventsPerStream = convertor.Convert(beginState);
     return(Evaluate(objectName, parameter, eventsPerStream, exprEvaluatorContext));
 }
Beispiel #6
0
 /// <summary>
 /// Evaluate the pattern expression.
 /// </summary>
 /// <param name="objectName">pattern object name</param>
 /// <param name="beginState">pattern state</param>
 /// <param name="timePeriod">The time period.</param>
 /// <param name="convertor">to converting from pattern match to event-per-stream</param>
 /// <param name="exprEvaluatorContext">expression evaluation context</param>
 /// <returns>
 /// evaluation result
 /// </returns>
 /// <throws>EPException if the evaluation failed</throws>
 public static Object EvaluateTimePeriod(String objectName, MatchedEventMap beginState, ExprTimePeriod timePeriod, MatchedEventConvertor convertor, ExprEvaluatorContext exprEvaluatorContext)
 {
     EventBean[] eventsPerStream = convertor.Convert(beginState);
     try {
         return(timePeriod.EvaluateGetTimePeriod(new EvaluateParams(eventsPerStream, true, exprEvaluatorContext)));
     }
     catch (Exception ex)
     {
         throw HandleRuntimeException(ex, objectName);
     }
 }
Beispiel #7
0
        public static Object GetKeys(MatchedEventMap matchEvent, MatchedEventConvertor convertor, ExprEvaluator[] expressions, AgentInstanceContext agentInstanceContext)
        {
            var eventsPerStream = convertor.Convert(matchEvent);

            if (expressions.Length == 1)
            {
                return(expressions[0].Evaluate(new EvaluateParams(eventsPerStream, true, agentInstanceContext)));
            }

            var keys = new Object[expressions.Length];

            for (var i = 0; i < keys.Length; i++)
            {
                keys[i] = expressions[i].Evaluate(new EvaluateParams(eventsPerStream, true, agentInstanceContext));
            }
            return(new MultiKeyUntyped(keys));
        }
Beispiel #8
0
 public long ComputeTime(MatchedEventMap beginState, PatternAgentInstanceContext context)
 {
     if (_timeExpr is ExprTimePeriod)
     {
         var timePeriod = (ExprTimePeriod) _timeExpr;
         return timePeriod.NonconstEvaluator()
             .DeltaUseEngineTime(_convertor.Convert(beginState), context.AgentInstanceContext);
     }
     else
     {
         Object time = PatternExpressionUtil.Evaluate(
             "Timer-Within-Or-Max-Count guard", beginState, _timeExpr, _convertor, context.AgentInstanceContext);
         if (null == time)
         {
             throw new EPException("Timer-within-or-max first parameter evaluated to a null-value");
         }
         return context.StatementContext.TimeAbacus.DeltaForSecondsNumber(time);
     }
 }
Beispiel #9
0
 public long ComputeMilliseconds(MatchedEventMap beginState, PatternAgentInstanceContext context)
 {
     if (_millisecondsExpr is ExprTimePeriod)
     {
         var timePeriod = (ExprTimePeriod)_millisecondsExpr;
         return(timePeriod.NonconstEvaluator().DeltaMillisecondsUseEngineTime(
                    _convertor.Convert(beginState), context.AgentInstanceContext));
     }
     else
     {
         var millisecondVal = PatternExpressionUtil.Evaluate(
             "Timer-Within-Or-Max-Count guard", beginState, _millisecondsExpr, _convertor, context.AgentInstanceContext);
         if (null == millisecondVal)
         {
             throw new EPException("Timer-within-or-max first parameter evaluated to a null-value");
         }
         return((long)Math.Round(1000d * millisecondVal.AsDouble()));
     }
 }
Beispiel #10
0
 public long ComputeTime(MatchedEventMap beginState, PatternAgentInstanceContext context)
 {
     if (_timeExpr is ExprTimePeriod)
     {
         var timePeriod = (ExprTimePeriod)_timeExpr;
         return(timePeriod.NonconstEvaluator()
                .DeltaUseEngineTime(_convertor.Convert(beginState), context.AgentInstanceContext));
     }
     else
     {
         var time = PatternExpressionUtil.Evaluate(
             "Timer-within guard", beginState, _timeExpr, _convertor, context.AgentInstanceContext);
         if (time == null)
         {
             throw new EPException("Timer-within guard expression returned a null-value");
         }
         return(context.StatementContext.TimeAbacus.DeltaForSecondsNumber(time));
     }
 }
        public long ComputeMilliseconds(MatchedEventMap beginState, PatternAgentInstanceContext context)
        {
            if (MillisecondsExpr is ExprTimePeriod)
            {
                ExprTimePeriod timePeriod = (ExprTimePeriod)MillisecondsExpr;
                return(timePeriod.NonconstEvaluator()
                       .DeltaMillisecondsUseEngineTime(Convertor.Convert(beginState), context.AgentInstanceContext));
            }
            else
            {
                Object millisecondVal = PatternExpressionUtil.Evaluate(
                    "Timer-within guard", beginState, MillisecondsExpr, Convertor, context.AgentInstanceContext);

                if (millisecondVal == null)
                {
                    throw new EPException("Timer-within guard expression returned a null-value");
                }

                return((long)Math.Round(1000d * millisecondVal.AsDouble()));
            }
        }