Exemplo n.º 1
0
        /// <summary>
        /// Constraint that defines whether a sequence of events is valid.
        /// </summary>
        /// <param name="es">The events.</param>
        /// <returns>A Zen value for if the sequence is valid.</returns>
        internal static Zen <bool> IsValidSequence(Zen <IList <Event> > es)
        {
            var areTimesAscending  = PairwiseInvariant(es, (x, y) => x.GetTimeStamp() < y.GetTimeStamp());
            var areTimeGapsValid   = PairwiseInvariant(es, (x, y) => y.GetTimeStamp() - x.GetTimeStamp() <= maxEventTimeGap);
            var arePrioritiesValid = es.All(e => e.GetPriorityClass() <= 1);

            var hasPollingEvents = True();

            for (int i = 0; i < numPollingIntervals; i++)
            {
                var et              = Event.EventTypeAsInt(EventType.PollingIntervalEvent);
                var value           = (ushort)(pollingInterval * i);
                var hasPollingEvent = es.Any(e => And(e.GetTimeStamp() == value, e.GetEventType() == et));
                hasPollingEvents = And(hasPollingEvent, hasPollingEvents);
            }

            return(And(areTimesAscending, areTimeGapsValid, arePrioritiesValid, hasPollingEvents));
        }