Example #1
0
        public void SetObserverParameters(
            IList <ExprNode> parameters,
            MatchedEventConvertor convertor,
            ExprValidationContext validationContext)
        {
            ObserverParameterUtil.ValidateNoNamedParameters("timer:at", parameters);
            if (Log.IsDebugEnabled)
            {
                Log.Debug(".setObserverParameters " + parameters);
            }

            if ((parameters.Count < 5) || (parameters.Count > 7))
            {
                throw new ObserverParameterException("Invalid number of parameters for timer:at");
            }

            _parameters = parameters;
            _convertor  = convertor;

            // if all parameters are constants, lets try to evaluate and build a schedule for early validation
            bool allConstantResult = true;

            foreach (ExprNode param in parameters)
            {
                if (!param.IsConstantResult)
                {
                    allConstantResult = false;
                }
            }

            if (allConstantResult)
            {
                try
                {
                    var observerParameters = PatternExpressionUtil.Evaluate(
                        "Timer-at observer", new MatchedEventMapImpl(convertor.MatchedEventMapMeta), parameters,
                        convertor, null);
                    _spec = ScheduleSpecUtil.ComputeValues(observerParameters.ToArray());
                }
                catch (ScheduleParameterException e)
                {
                    throw new ObserverParameterException(
                              "Error computing crontab schedule specification: " + e.Message, e);
                }
            }
        }
        public void SetObserverParameters(IList <ExprNode> parameters, MatchedEventConvertor convertor, ExprValidationContext validationContext)
        {
            ObserverParameterUtil.ValidateNoNamedParameters(NAME, parameters);
            const string errorMessage = NAME + " requires a single numeric or time period parameter";

            if (parameters.Count != 1)
            {
                throw new ObserverParameterException(errorMessage);
            }

            if (parameters[0] is ExprTimePeriod)
            {
                var returnType = parameters[0].ExprEvaluator.ReturnType;
                if (!returnType.IsNumeric())
                {
                    throw new ObserverParameterException(errorMessage);
                }
            }

            _parameter = parameters[0];
            _convertor = convertor;
        }