Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lastRunTime">Will be converted to the passed-in TimeZoneInfo's local time if Kind is UTC.</param>
        /// <param name="dockedTime">The time the instrument was docked; if more recent than the last run, and if On Docking is true, this time is returned</param>
        /// <param name="tzi">The docking station's local time zone setting.</param>
        /// <returns></returns>
        public override DateTime CalculateNextRunTime(DateTime lastRunTime, DateTime dockedTime, TimeZoneInfo tzi)
        {
            if (lastRunTime.Kind == DateTimeKind.Utc)
            {
                lastRunTime = tzi.ToLocalTime(lastRunTime);
            }

            if (UponDocking)
            {
                // The schedule has been specified to allow for the event to be run upon docking.
                // If the docked time is more recent than the journal run time, return the docked time to run the event.
                if (dockedTime.Kind == DateTimeKind.Utc)
                {
                    dockedTime = tzi.ToLocalTime(dockedTime);
                }
                Log.Trace("ScheduledHourly: uponDocking = true; last run time=" + lastRunTime.ToShortDateString() + ", dockedTime=" + dockedTime.ToShortDateString());
                if (lastRunTime < dockedTime)
                {
                    return(dockedTime);
                }
            }

            Log.Trace("ScheduledHourly: start date time=" + StartDateTime.ToLongDateString() + " interval=" + Interval.ToString() + " days, last run time=" + lastRunTime.ToLongDateString() + ", docked time=" + dockedTime.ToShortDateString());

            // Not yet the StartDateTime? Then just return StartDateTime
            if (lastRunTime < StartDateTime)
            {
                return(GetNextRunDay(StartDateTime));
            }

            // SGF  5-Feb-2013  INS-3655 -- Corrected to begin checking for the next run time on the day prior to the last run,
            // and then advance the current time based on the interval defined for that event schedule. When a time has been
            // found that is later than the last run time, and that time occurs on a day that has been selected as a valid run day,
            // that time is returned to the caller.
            DateTime nextRunTime = new DateTime(lastRunTime.Date.Year, lastRunTime.Date.Month, lastRunTime.Date.Day, 0, 0, 0, DateTimeKind.Local);

            nextRunTime = nextRunTime.AddDays(-1);
            nextRunTime = nextRunTime.Add(RunAtTime);

            while (nextRunTime < lastRunTime)
            {
                nextRunTime = nextRunTime.AddHours(Interval);
                DayOfWeek nextRunDayOfWeek = (DayOfWeek)nextRunTime.DayOfWeek;
                if (!Days[(int)nextRunDayOfWeek])
                {
                    continue;
                }
                if (nextRunTime > lastRunTime)
                {
                    return(nextRunTime);
                }
            }

            // if we make it to here, then lastRunDate is in the future (?)

            return(DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Local));
        }