예제 #1
0
        /// <summary>
        /// Returns the first time the <see cref="NthIncludedDayTrigger" /> will fire
        /// after the specified date.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Because of the conceptual design of <see cref="NthIncludedDayTrigger" />,
        /// it is not always possible to decide with certainty that the trigger
        /// will <i>never</i> fire again. Therefore, it will search for the next
        /// fire time up to a given cutoff. These cutoffs can be changed by using the
        /// <see cref="NextFireCutoffInterval" /> property. The default cutoff is 12
        /// of the intervals specified by <see cref="IntervalType" /> intervalType.
        /// </para>
        /// <para>
        /// Therefore, for triggers with intervalType =
        /// <see cref="IntervalTypeWeekly" />, if the trigger
        /// will not fire within 12
        /// weeks after the given date/time, <see langword="null" /> will be returned. For
        /// triggers with intervalType =
        /// <see cref="IntervalTypeMonthly" />
        /// , if the trigger will not fire within 12
        /// months after the given date/time, <see langword="null" /> will be returned.
        /// For triggers with intervalType =
        /// <see cref="IntervalTypeYearly" />
        /// , if the trigger will not fire within 12
        /// years after the given date/time, <see langword="null" /> will be returned.  In
        /// all cases, if the trigger will not fire before <see field="endTime" />,
        /// <see langword="null" /> will be returned.
        /// </para>
        /// </remarks>
        /// <param name="afterTimeUtc">The time after which to find the nearest fire time.
        /// This argument is treated as exclusive &#x8212; that is,
        /// if afterTime is a valid fire time for the trigger, it
        /// will not be returned as the next fire time.
        /// </param>
        /// <returns>
        /// the first time the trigger will fire following the specified date
        /// </returns>
        public override DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTimeUtc)
        {
            if (!afterTimeUtc.HasValue)
            {
                afterTimeUtc = SystemTime.UtcNow();
            }

            if ((afterTimeUtc.Value < StartTimeUtc))
            {
                afterTimeUtc = StartTimeUtc.AddMilliseconds(-1 * 1000);
            }

            if (intervalType == IntervalTypeWeekly)
            {
                return(GetWeeklyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeMonthly)
            {
                return(GetMonthlyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeYearly)
            {
                return(GetYearlyFireTimeAfter(afterTimeUtc.Value));
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns the first time the <see cref="NthIncludedDayTrigger" /> will fire
        /// after the specified date.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Because of the conceptual design of <see cref="NthIncludedDayTrigger" />,
        /// it is not always possible to decide with certainty that the trigger
        /// will <i>never</i> fire again. Therefore, it will search for the next
        /// fire time up to a given cutoff. These cutoffs can be changed by using the
        /// <see cref="NextFireCutoffInterval" /> property. The default cutoff is 12
        /// of the intervals specified by <see cref="IntervalType" /> intervalType.
        /// </p>
        /// <p>
        /// Therefore, for triggers with intervalType =
        /// <see cref="IntervalTypeWeekly" />, if the trigger
        /// will not fire within 12
        /// weeks after the given date/time, <see langword="null" /> will be returned. For
        /// triggers with intervalType =
        /// <see cref="IntervalTypeMonthly" />
        /// , if the trigger will not fire within 12
        /// months after the given date/time, <see langword="null" /> will be returned.
        /// For triggers with intervalType =
        /// <see cref="IntervalTypeYearly" />
        /// , if the trigger will not fire within 12
        /// years after the given date/time, <see langword="null" /> will be returned.  In
        /// all cases, if the trigger will not fire before <see field="endTime" />,
        /// <see langword="null" /> will be returned.
        /// </p>
        /// </remarks>
        /// <param name="afterTimeUtc">The time after which to find the nearest fire time.
        /// This argument is treated as exclusive &#x8212; that is,
        /// if afterTime is a valid fire time for the trigger, it
        /// will not be returned as the next fire time.
        /// </param>
        /// <returns>
        /// the first time the trigger will fire following the specified date
        /// </returns>
        public override NullableDateTime GetFireTimeAfter(NullableDateTime afterTimeUtc)
        {
            afterTimeUtc = DateTimeUtil.AssumeUniversalTime(afterTimeUtc);
            if (!afterTimeUtc.HasValue)
            {
                afterTimeUtc = DateTime.UtcNow;
            }

            if ((afterTimeUtc.Value < StartTimeUtc))
            {
                afterTimeUtc = StartTimeUtc.AddMilliseconds(-1 * 1000);
            }

            if (intervalType == IntervalTypeWeekly)
            {
                return(GetWeeklyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeMonthly)
            {
                return(GetMonthlyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeYearly)
            {
                return(GetYearlyFireTimeAfter(afterTimeUtc.Value));
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        /// <summary>
        /// Called by the scheduler at the time a <see cref="ITrigger" /> is first
        /// added to the scheduler, in order to have the <see cref="ITrigger" />
        /// compute its first fire time, based on any associated calendar.
        /// <para>
        /// After this method has been called, <see cref="GetNextFireTimeUtc" />
        /// should return a valid answer.
        /// </para>
        ///
        /// </summary>
        /// <returns> the first time at which the <see cref="ITrigger" /> will be fired
        /// by the scheduler, which is also the same value
        /// <see cref="GetNextFireTimeUtc" /> will return (until after the first
        /// firing of the <see cref="ITrigger" />).
        /// </returns>
        public override DateTimeOffset?ComputeFirstFireTimeUtc(ICalendar cal)
        {
            calendar = cal;
            DateTimeOffset dt = StartTimeUtc.AddMilliseconds(-1 * 1000);

            nextFireTimeUtc = GetFireTimeAfter(dt);

            return(nextFireTimeUtc);
        }
예제 #4
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="ISimpleTrigger" /> will
        /// fire, before the given time. If the trigger will not fire before the
        /// given time, <see langword="null" /> will be returned.
        /// </summary>
        public virtual DateTimeOffset?GetFireTimeBefore(DateTimeOffset?endUtc)
        {
            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            int numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * repeatInterval.TotalMilliseconds));
        }
예제 #5
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="ZmanimTrigger" /> will
        /// fire, before the given time. If the trigger will not fire before the
        /// given time, <see langword="null" /> will be returned.
        /// </summary>
        public virtual DateTime?GetFireTimeBefore(DateTime?endUtc)
        {
            endUtc = ComputePreviousZmanTime(DateTimeUtil.AssumeUniversalTime(endUtc));
            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            int numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * repeatInterval.TotalMilliseconds));
        }
예제 #6
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="Trigger" /> will
        /// fire, before the given time. If the trigger will not fire before the
        /// given time, <see langword="null" /> will be returned.
        /// </summary>
        public virtual NullableDateTime GetFireTimeBefore(NullableDateTime endUtc)
        {
            endUtc = DateTimeUtils.AssumeUniversalTime(endUtc);
            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            int numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * _repeatInterval));
        }