Пример #1
0
        private static Object ParseNumber(IRuleNode number, int factor)
        {
            var tokenType = GetSingleChildTokenType(number);

            if (tokenType == EsperEPL2GrammarLexer.IntegerLiteral)
            {
                return(ParseIntLongByte(number.GetText(), factor));
            }

            else if (tokenType == EsperEPL2GrammarLexer.FloatingPointLiteral)
            {
                var numberText = number.GetText();
                if (numberText.EndsWith("m"))
                {
                    return(DecimalValue.ParseString(number.GetText()) * factor);
                }
                else if (numberText.EndsWith("f") || numberText.EndsWith("F"))
                {
                    return(FloatValue.ParseString(number.GetText()) * factor);
                }
                else
                {
                    return(DoubleValue.ParseString(number.GetText()) * factor);
                }
            }
            throw ASTWalkException.From("Encountered unrecognized constant", number.GetText());
        }
        private AggSvcGroupByReclaimAgedEvalFuncFactory GetEvaluationFunction(VariableService variableService, String hintValue, String optionalContextName)
        {
            VariableMetaData variableMetaData = variableService.GetVariableMetaData(hintValue);

            if (variableMetaData != null)
            {
                if (!variableMetaData.VariableType.IsNumeric())
                {
                    throw new ExprValidationException("Variable type of variable '" + variableMetaData.VariableName + "' is not numeric");
                }
                String message = VariableServiceUtil.CheckVariableContextName(optionalContextName, variableMetaData);
                if (message != null)
                {
                    throw new ExprValidationException(message);
                }
                return(new ProxyAggSvcGroupByReclaimAgedEvalFuncFactory
                {
                    ProcMake = agentInstanceContext =>
                    {
                        VariableReader reader = variableService.GetReader(
                            variableMetaData.VariableName, agentInstanceContext.AgentInstanceId);
                        return new AggSvcGroupByReclaimAgedEvalFuncVariable(reader);
                    }
                });
            }
            else
            {
                double valueDouble;
                try {
                    valueDouble = DoubleValue.ParseString(hintValue);
                }
                catch (Exception) {
                    throw new ExprValidationException("Failed to parse hint parameter value '" + hintValue + "' as a double-typed seconds value or variable name");
                }
                if (valueDouble <= 0)
                {
                    throw new ExprValidationException("Hint parameter value '" + hintValue + "' is an invalid value, expecting a double-typed seconds value or variable name");
                }
                return(new ProxyAggSvcGroupByReclaimAgedEvalFuncFactory
                {
                    ProcMake = agentInstanceContext => new AggSvcGroupByReclaimAgedEvalFuncConstant(valueDouble)
                });
            }
        }