private void AssertParse(
            string text,
            long?expectedNumRepeats,
            string expectedDate,
            TimePeriod expectedTimePeriod)
        {
            var spec = TimerScheduleISO8601Parser.Parse(text);

            Assert.AreEqual(expectedNumRepeats, spec.OptionalRepeatCount);
            if (expectedTimePeriod == null)
            {
                Assert.IsNull(spec.OptionalTimePeriod);
            }
            else
            {
                Assert.AreEqual(
                    expectedTimePeriod,
                    spec.OptionalTimePeriod,
                    "expected '" + expectedTimePeriod.ToStringISO8601() + "' got '" + spec.OptionalTimePeriod.ToStringISO8601() + "'");
            }

            if (expectedDate == null)
            {
                Assert.IsNull(spec.OptionalDate);
            }
            else
            {
                Assert.AreEqual(DateTimeParsingFunctions.ParseDefaultMSecWZone(expectedDate), spec.OptionalDate.UtcMillis);
            }
        }
 private void TryInvalid(
     string iso8601,
     string message)
 {
     try
     {
         TimerScheduleISO8601Parser.Parse(iso8601);
         Assert.Fail();
     }
     catch (ScheduleParameterException ex)
     {
         Assert.AreEqual(message, ex.Message);
     }
 }
        private void AssertTimeParse(
            string date,
            int year,
            int month,
            int day,
            int hour,
            int minute,
            int second,
            int millis,
            string zone)
        {
            var spec = TimerScheduleISO8601Parser.Parse(date);

            SupportDateTimeUtil.CompareDate(spec.OptionalDate, year, month, day, hour, minute, second, millis);
            Assert.AreEqual(zone, spec.OptionalDate.TimeZone.DisplayName);
        }
Пример #4
0
        protected internal static TimerScheduleSpec Compute(
            ExprEvaluator parameter,
            EventBean[] events,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            object param = PatternExpressionUtil.EvaluateChecked(
                NAME_OBSERVER,
                parameter,
                events,
                exprEvaluatorContext);
            string iso = (string) param;
            if (iso == null) {
                throw new ScheduleParameterException("Received null parameter value");
            }

            return TimerScheduleISO8601Parser.Parse(iso);
        }
        protected internal static TimerScheduleSpec Compute(
            ExprEvaluator date,
            ExprEvaluator repetitions,
            TimePeriodEval timePeriod,
            EventBean[] eventsPerStream,
            ExprEvaluatorContext exprEvaluatorContext,
            TimeZoneInfo timeZone,
            TimeAbacus timeAbacus)
        {
            DateTimeEx optionalDate = null;
            long? optionalRemainder = null;
            if (date != null) {
                object param = PatternExpressionUtil.EvaluateChecked(
                    TimerScheduleObserverForge.NAME_OBSERVER,
                    date,
                    eventsPerStream,
                    exprEvaluatorContext);
                if (param is string) {
                    optionalDate = TimerScheduleISO8601Parser.ParseDate((string) param);
                }
                else if (TypeHelper.IsNumber(param)) {
                    long msec = param.AsInt64();
                    optionalDate = DateTimeEx.GetInstance(timeZone);
                    optionalRemainder = timeAbacus.DateTimeSet(msec, optionalDate);
                }
                else if (param is DateTimeEx dateTimeEx) {
                    optionalDate = DateTimeEx.GetInstance(timeZone, dateTimeEx);
                }
                else if (param is DateTime dateTime) {
                    optionalDate = DateTimeEx.GetInstance(timeZone, dateTime);
                }
                else if (param is DateTimeOffset dateTimeOffset) {
                    optionalDate = DateTimeEx.GetInstance(timeZone, dateTimeOffset);
                }
                else if (param == null) {
                    throw new EPException("Null date-time value returned from date evaluation");
                }
                else {
                    throw new EPException("Unrecognized date-time value " + param.GetType());
                }
            }

            TimePeriod optionalTimePeriod = null;
            if (timePeriod != null) {
                try {
                    optionalTimePeriod = timePeriod.TimePeriodEval(eventsPerStream, true, exprEvaluatorContext);
                }
                catch (EPException) {
                    throw;
                }
                catch (Exception ex) {
                    PatternExpressionUtil.HandleRuntimeEx(ex, NAME_OBSERVER);
                }
            }

            long? optionalRepeatCount = null;
            if (repetitions != null) {
                object param = PatternExpressionUtil.EvaluateChecked(
                    NAME_OBSERVER,
                    repetitions,
                    eventsPerStream,
                    exprEvaluatorContext);
                if (param != null) {
                    optionalRepeatCount = (param).AsInt64();
                }
            }

            if (optionalDate == null && optionalTimePeriod == null) {
                throw new EPException("Required date or time period are both null for " + NAME_OBSERVER);
            }

            return new TimerScheduleSpec(optionalDate, optionalRemainder, optionalRepeatCount, optionalTimePeriod);
        }