Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Computes the number of times fired between the two UTC date times.
        /// </summary>
        /// <param name="startTimeUtc">The UTC start date and time.</param>
        /// <param name="endTimeUtc">The UTC end date and time.</param>
        /// <returns></returns>
        public virtual int ComputeNumTimesFiredBetween(DateTime?startTimeUtc, DateTime?endTimeUtc)
        {
            startTimeUtc = ComputeNextZmanTime(DateTimeUtil.AssumeUniversalTime(startTimeUtc));
            endTimeUtc   = ComputePreviousZmanTime(DateTimeUtil.AssumeUniversalTime(endTimeUtc));

            long time = (long)(endTimeUtc.Value - startTimeUtc.Value).TotalMilliseconds;

            return((int)(time / repeatInterval.TotalMilliseconds));
        }
Esempio n. 3
0
        /// <summary>
        /// Returns the next UTC time at which the <see cref="ZmanimTrigger" /> will
        /// fire, after the given UTC time. If the trigger will not fire after the given
        /// time, <see langword="null" /> will be returned.
        /// </summary>
        public override DateTime?GetFireTimeAfter(DateTime?afterTimeUtc)
        {
            afterTimeUtc = ComputeNextZmanTime(DateTimeUtil.AssumeUniversalTime(afterTimeUtc));

            if (complete)
            {
                return(null);
            }

            if ((timesTriggered > repeatCount) && (repeatCount != RepeatIndefinitely))
            {
                return(null);
            }

            if (!afterTimeUtc.HasValue)
            {
                afterTimeUtc = DateTime.UtcNow;
            }

            if (repeatCount == 0 && afterTimeUtc.Value.CompareTo(StartTimeUtc) >= 0)
            {
                return(null);
            }

            DateTime startMillis = StartTimeUtc;
            DateTime afterMillis = afterTimeUtc.Value;
            DateTime endMillis   = !EndTimeUtc.HasValue ? DateTime.MaxValue : EndTimeUtc.Value;


            if (endMillis <= afterMillis)
            {
                return(null);
            }

            if (afterMillis < startMillis)
            {
                return(startMillis);
            }

            long numberOfTimesExecuted = (long)(((long)(afterMillis - startMillis).TotalMilliseconds / repeatInterval.TotalMilliseconds) + 1);

            if ((numberOfTimesExecuted > repeatCount) &&
                (repeatCount != RepeatIndefinitely))
            {
                return(null);
            }

            DateTime time = startMillis.AddMilliseconds(numberOfTimesExecuted * repeatInterval.TotalMilliseconds);

            if (endMillis <= time)
            {
                return(null);
            }


            return(time);
        }
Esempio n. 4
0
        /// <summary>
        /// 计算在指定时间之间的触发次数
        /// Computes the number of times fired between the two UTC date times.
        /// </summary>
        /// <param name="startTimeUtc">The UTC start date and time.</param>
        /// <param name="endTimeUtc">The UTC end date and time.</param>
        /// <returns></returns>
        public virtual int ComputeNumTimesFiredBetween(NullableDateTime startTimeUtc, NullableDateTime endTimeUtc)
        {
            startTimeUtc = DateTimeUtil.AssumeUniversalTime(startTimeUtc);
            endTimeUtc   = DateTimeUtil.AssumeUniversalTime(endTimeUtc);

            long time = (long)(endTimeUtc.Value - startTimeUtc.Value).TotalMilliseconds;

            return((int)(time / repeatInterval.TotalMilliseconds));
        }
Esempio n. 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));
        }
Esempio n. 6
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="SimpleTrigger" /> 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 = DateTimeUtil.AssumeUniversalTime(endUtc);

            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            var numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * repeatInterval.TotalMilliseconds));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TriggerFiredBundle"/> class.
 /// </summary>
 /// <param name="job">The job.</param>
 /// <param name="trigger">The trigger.</param>
 /// <param name="cal">The calendar.</param>
 /// <param name="jobIsRecovering">if set to <c>true</c> [job is recovering].</param>
 /// <param name="fireTimeUtc">The fire time.</param>
 /// <param name="scheduledFireTimeUtc">The scheduled fire time.</param>
 /// <param name="prevFireTimeUtc">The previous fire time.</param>
 /// <param name="nextFireTimeUtc">The next fire time.</param>
 public TriggerFiredBundle(JobDetail job, Trigger trigger, ICalendar cal, bool jobIsRecovering,
                           NullableDateTime fireTimeUtc,
                           NullableDateTime scheduledFireTimeUtc,
                           NullableDateTime prevFireTimeUtc,
                           NullableDateTime nextFireTimeUtc)
 {
     this.job                  = job;
     this.trigger              = trigger;
     this.cal                  = cal;
     this.jobIsRecovering      = jobIsRecovering;
     this.fireTimeUtc          = DateTimeUtil.AssumeUniversalTime(fireTimeUtc);
     this.scheduledFireTimeUtc = DateTimeUtil.AssumeUniversalTime(scheduledFireTimeUtc);
     this.prevFireTimeUtc      = DateTimeUtil.AssumeUniversalTime(prevFireTimeUtc);
     this.nextFireTimeUtc      = DateTimeUtil.AssumeUniversalTime(nextFireTimeUtc);
 }
Esempio n. 8
0
 /// <summary>
 /// Set the previous UTC time at which the <see cref="ZmanimTrigger" /> fired.
 /// <strong>This method should not be invoked by client code.</strong>
 /// </summary>
 public virtual void SetPreviousFireTime(DateTime?fireTimeUtc)
 {
     previousFireTimeUtc = DateTimeUtil.AssumeUniversalTime(fireTimeUtc);
 }
Esempio n. 9
0
 /// <summary>
 /// Set the next UTC time at which the <see cref="ZmanimTrigger" /> should fire.
 /// <strong>This method should not be invoked by client code.</strong>
 /// </summary>
 public void SetNextFireTime(DateTime?fireTimeUtc)
 {
     nextFireTimeUtc = DateTimeUtil.AssumeUniversalTime(fireTimeUtc);
 }
Esempio n. 10
0
 /// <summary>
 /// 设置下一次触发时间
 /// Set the next UTC time at which the <see cref="SimpleTrigger" /> should fire.
 /// <strong>This method should not be invoked by client code.</strong>
 /// </summary>
 public void SetNextFireTime(NullableDateTime fireTimeUtc)
 {
     nextFireTimeUtc = DateTimeUtil.AssumeUniversalTime(fireTimeUtc);
 }