private static ExprOptionalConstant GetExprOrConstant(ExprNode exprNode, TimeAbacus timeAbacus) { if (exprNode is ExprTimePeriod) { var timePeriod = (ExprTimePeriod)exprNode; if (!timePeriod.HasMonth && !timePeriod.HasYear) { // no-month and constant if (exprNode.IsConstantResult) { var sec = timePeriod.EvaluateAsSeconds(null, true, null); var l = timeAbacus.DeltaForSecondsDouble(sec); IntervalDeltaExprEvaluator eval = new ProxyIntervalDeltaExprEvaluator { ProcEvaluate = (reference, eventsPerStream, isNewData, context) => l, }; return(new ExprOptionalConstant(eval, l)); } // no-month and not constant else { IntervalDeltaExprEvaluator eval = new ProxyIntervalDeltaExprEvaluator { ProcEvaluate = (reference, eventsPerStream, isNewData, context) => { double sec = timePeriod.EvaluateAsSeconds(eventsPerStream, isNewData, context); return(timeAbacus.DeltaForSecondsDouble(sec)); }, }; return(new ExprOptionalConstant(eval, null)); } } // has-month else { // has-month and constant if (exprNode.IsConstantResult) { ExprTimePeriodEvalDeltaConst timerPeriodConst = timePeriod.ConstEvaluator(null); IntervalDeltaExprEvaluator eval = new ProxyIntervalDeltaExprEvaluator { ProcEvaluate = (reference, eventsPerStream, isNewData, context) => { return(timerPeriodConst.DeltaAdd(reference)); }, }; return(new ExprOptionalConstant(eval, null)); } // has-month and not constant else { ExprTimePeriodEvalDeltaNonConst timerPeriodNonConst = timePeriod.NonconstEvaluator(); IntervalDeltaExprEvaluator eval = new ProxyIntervalDeltaExprEvaluator { ProcEvaluate = (reference, eventsPerStream, isNewData, context) => timerPeriodNonConst.DeltaAdd( reference, eventsPerStream, isNewData, context), }; return(new ExprOptionalConstant(eval, null)); } } } else if (ExprNodeUtility.IsConstantValueExpr(exprNode)) { var constantNode = (ExprConstantNode)exprNode; long l = constantNode.GetConstantValue(null).AsLong(); IntervalDeltaExprEvaluator eval = new ProxyIntervalDeltaExprEvaluator { ProcEvaluate = (reference, eventsPerStream, isNewData, context) => l, }; return(new ExprOptionalConstant(eval, l)); } else { var evaluator = exprNode.ExprEvaluator; IntervalDeltaExprEvaluator eval = new ProxyIntervalDeltaExprEvaluator { ProcEvaluate = (reference, eventsPerStream, isNewData, context) => evaluator.Evaluate( new EvaluateParams(eventsPerStream, isNewData, context)).AsLong(), }; return(new ExprOptionalConstant(eval, null)); } }
/// <summary> /// Constructor. /// </summary> /// <param name="timePeriod">is the number of minutes or seconds to batch events for, may include variables</param> /// <param name="isStartConditionOnCreation">if set to <c>true</c> [is start condition on creation].</param> public OutputConditionTimeFactory(ExprTimePeriod timePeriod, bool isStartConditionOnCreation) { _timePeriod = timePeriod; _timePeriodDeltaComputation = timePeriod.NonconstEvaluator(); _isStartConditionOnCreation = isStartConditionOnCreation; }