/// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="spec">The spec.</param>
 /// <param name="beginState">start state</param>
 /// <param name="observerEventEvaluator">receiver for events</param>
 /// <param name="isFilterChildNonQuitting">if set to <c>true</c> [is filter child non quitting].</param>
 public TimerScheduleObserver(TimerScheduleSpec spec, MatchedEventMap beginState, ObserverEventEvaluator observerEventEvaluator, bool isFilterChildNonQuitting)
 {
     _beginState             = beginState;
     _observerEventEvaluator = observerEventEvaluator;
     _scheduleSlot           = observerEventEvaluator.Context.PatternContext.ScheduleBucket.AllocateSlot();
     _spec = spec;
     _isFilterChildNonQuitting = isFilterChildNonQuitting;
 }
Beispiel #2
0
        private void AssertTimeParse(string date, int year, int month, int day, int hour, int minute, int second, int millis, string zone)
        {
            TimeZoneInfo      timeZoneInfoTarget = TimeZoneHelper.GetTimeZoneInfo(zone);
            TimeZoneInfo      timeZoneInfoLocal  = TimeZoneHelper.Local;
            TimerScheduleSpec spec = TimerScheduleISO8601Parser.Parse(date);
            // the date time will be parsed by the ISO8601 parser but the time returned will be in "offset" terms
            DateTimeOffset specDate = spec.OptionalDate.DateTime.TranslateTo(timeZoneInfoTarget);

            SupportDateTimeUtil.CompareDate(specDate, year, month, day, hour, minute, second, millis);
            //Assert.AreEqual(zone, spec.OptionalDate.TimeZone.DisplayName);
        }
Beispiel #3
0
        private void AssertParse(string text, long?expectedNumRepeats, string expectedDate, TimePeriod expectedTimePeriod)
        {
            TimerScheduleSpec spec = TimerScheduleISO8601Parser.Parse(text);

            Assert.AreEqual(expectedNumRepeats, (object)spec.OptionalRepeatCount);
            if (expectedTimePeriod == null)
            {
                Assert.IsNull(spec.OptionalTimePeriod);
            }
            else
            {
                Assert.AreEqual(expectedTimePeriod, spec.OptionalTimePeriod,
                                string.Format("expected '{0}' got '{1}'", expectedTimePeriod.ToStringISO8601(), spec.OptionalTimePeriod.ToStringISO8601()));
            }
            if (expectedDate == null)
            {
                Assert.IsNull(spec.OptionalDate);
            }
            else
            {
                Assert.AreEqual(DateTimeParser.ParseDefaultMSecWZone(expectedDate), spec.OptionalDate.TimeInMillis);
            }
        }
        public void SetObserverParameters(IList<ExprNode> parameters, MatchedEventConvertor convertor, ExprValidationContext validationContext)
        {
            Convertor = convertor;

            // obtains name parameters
            IDictionary<string, ExprNamedParameterNode> namedExpressions;
            try
            {
                namedExpressions = ExprNodeUtility.GetNamedExpressionsHandleDups(parameters);
                ExprNodeUtility.ValidateNamed(namedExpressions, NAMED_PARAMETERS);
            }
            catch (ExprValidationException e)
            {
                throw new ObserverParameterException(e.Message, e);
            }

            bool allConstantResult;
            ExprNamedParameterNode isoStringExpr = namedExpressions.Get(ISO_NAME);
            if (namedExpressions.Count == 1 && isoStringExpr != null)
            {
                try
                {
                    allConstantResult = ExprNodeUtility.ValidateNamedExpectType(
                        isoStringExpr, new Type[]
                        {
                            typeof (string)
                        });
                }
                catch (ExprValidationException ex)
                {
                    throw new ObserverParameterException(ex.Message, ex);
                }
                ScheduleComputer = new TimerScheduleSpecComputeISOString(isoStringExpr.ChildNodes[0]);
            }
            else if (isoStringExpr != null)
            {
                throw new ObserverParameterException(
                    "The '" + ISO_NAME + "' parameter is exclusive of other parameters");
            }
            else if (namedExpressions.Count == 0)
            {
                throw new ObserverParameterException("No parameters provided");
            }
            else
            {
                allConstantResult = true;
                ExprNamedParameterNode dateNamedNode = namedExpressions.Get(DATE_NAME);
                ExprNamedParameterNode repetitionsNamedNode = namedExpressions.Get(REPETITIONS_NAME);
                ExprNamedParameterNode periodNamedNode = namedExpressions.Get(PERIOD_NAME);
                if (dateNamedNode == null && periodNamedNode == null)
                {
                    throw new ObserverParameterException("Either the date or period parameter is required");
                }
                try
                {
                    if (dateNamedNode != null)
                    {
                        allConstantResult = ExprNodeUtility.ValidateNamedExpectType(
                            dateNamedNode, new Type[]
                            {
                                typeof (string),
                                typeof (DateTime),
                                typeof (DateTimeOffset),
                                typeof (long?)
                            });
                    }
                    if (repetitionsNamedNode != null)
                    {
                        allConstantResult &= ExprNodeUtility.ValidateNamedExpectType(
                            repetitionsNamedNode, new Type[]
                            {
                                typeof (int?),
                                typeof (long?)
                            });
                    }
                    if (periodNamedNode != null)
                    {
                        allConstantResult &= ExprNodeUtility.ValidateNamedExpectType(
                            periodNamedNode, new Type[]
                            {
                                typeof (TimePeriod)
                            });
                    }
                }
                catch (ExprValidationException ex)
                {
                    throw new ObserverParameterException(ex.Message, ex);
                }
                ExprNode dateNode = dateNamedNode == null ? null : dateNamedNode.ChildNodes[0];
                ExprNode repetitionsNode = repetitionsNamedNode == null ? null : repetitionsNamedNode.ChildNodes[0];
                ExprTimePeriod periodNode = periodNamedNode == null
                    ? null
                    : (ExprTimePeriod) periodNamedNode.ChildNodes[0];
                ScheduleComputer = new TimerScheduleSpecComputeFromExpr(dateNode, repetitionsNode, periodNode);
            }

            if (allConstantResult)
            {
                try
                {
                    Spec = ScheduleComputer.Compute(
                        convertor, new MatchedEventMapImpl(convertor.MatchedEventMapMeta), null, validationContext.MethodResolutionService.EngineImportService.TimeZone);
                }
                catch (ScheduleParameterException ex)
                {
                    throw new ObserverParameterException(ex.Message, ex);
                }
            }
        }