示例#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));
        }
        /// <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)
        {
            const string methodName = "CalculateNextRunTime";

            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("ScheduledMonthly: uponDocking = true; last run time=" + lastRunTime.ToShortDateString() + ", dockedTime=" + dockedTime.ToShortDateString());
                if (lastRunTime < dockedTime)
                {
                    return(dockedTime);
                }
            }

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

            DateTime lastRunDate = lastRunTime.Date; // we're only interested in the date portion, not the time.

            Log.Assert(Interval > 0,
                       string.Format("Invalid Interval ({0}) encountered in {1}.{2}", Interval, GetType(), methodName));

            // The schedule has two options... "Day X of every Y months" or
            // ""Xth DayOfWeek of every Y months".  Determine which option it's
            // configured for and make appropriate corresponding call to calculate.

            // "Day X of every Y months"?  e.g. "Day 2 of every 3 months, at 02:30"
            if (DayOfMonth != DomainModelConstant.NullShort)
            {
                return(CalculateNextDayXofEveryYmonths(lastRunDate));
            }

            // "Xth DayOfWeek of every Y months".  e.g. "4th Tuesday of every 3 months, at 02:30"
            if (Week != DomainModelConstant.NullShort)
            {
                return(CalculateXthDayOfWeekofEveryYmonths(lastRunDate));
            }

            Log.Assert(string.Format("Invalid data encountered in {0}.{1}", GetType(), methodName));

            return(DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Local));
        } // end-CalculateNextRunTime
示例#3
0
 /// <summary>
 /// Converts the local time of the source time-zone to the local time of the
 /// destination time-zone.
 /// </summary>
 /// <param name="source">The source time-zone</param>
 /// <param name="destination">The destination time-zone</param>
 /// <param name="sourceLocalTime">The local time of the source time-zone that is
 /// to be converted to the local time in the destination time-zone</param>
 /// <returns>The local time in the destination time-zone.</returns>
 public static DateTime Convert(TimeZoneInfo source, TimeZoneInfo destination,
                                DateTime sourceLocalTime)
 {
     //since we now have the UtcTime, we can forward the call to the ConvertUtcTimeZone
     //method and return that functions return value
     return(TimeZoneInfo.ToLocalTime(destination,
                                     TimeZoneInfo.ToUniversalTime(source, sourceLocalTime)));
 }
示例#4
0
        /// <summary>
        /// Convert the specified UTC time stamp to this time zone's local time.
        /// </summary>
        /// <param name="utcTime"></param>
        /// <returns>if utcTime is null, then DateTime.MinValue is returned.</returns>
        public DateTime ToLocalTime(DateTime?utcTime)
        {
            if (utcTime == null)
            {
                return(DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Local));
            }

            return(TimeZoneInfo.ToLocalTime(this, (DateTime)utcTime));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="lastRunTime">Will be converted to the passed-in TimeZoneInfo's local time if Kind is UTC.</param>
        /// <param name="dockedTime">Will be converted to the passed-in TimeZoneInfo's local time if Kind is UTC.</param>
        /// <param name="tzi">The docking station's local time zone setting.</param>
        /// <returns>
        /// If the last time it was run is prior to when it was docked, then it's overdue,
        /// so MinValue is returned to ensure it's considered overdue.
        /// Otherwise, it's already been run since being docked,
        /// so MaxValue is returned to ensure it doesn't run again.
        /// </returns>
        public override DateTime CalculateNextRunTime(DateTime lastRunTime, DateTime dockedTime, TimeZoneInfo tzi)
        {
            if (lastRunTime.Kind == DateTimeKind.Utc)
            {
                lastRunTime = tzi.ToLocalTime(lastRunTime);
            }

            if (dockedTime.Kind == DateTimeKind.Utc)
            {
                dockedTime = tzi.ToLocalTime(dockedTime);
            }

            // If the last time it was run is prior to the docked time, then it's overdue.
            // So return MinValue to ensure it's seen as overdue.
            // Otherwise, it's already been run since it was last docked,
            // so return MaxValue to ensure it doesn't run again.
            return((lastRunTime < dockedTime)
                ? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Local)
                : DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Local));
        }
示例#6
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("ScheduledDaily: UponDocking = true; last run time=" + lastRunTime.ToShortDateString() + ", dockedTime=" + dockedTime.ToShortDateString());
                if (lastRunTime < dockedTime)
                {
                    return(dockedTime);
                }
            }

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

            DateTime lastRunDate = lastRunTime.Date; // we're only interested in the date portion, not the time.

            // SGF  26-Jan-2012  INS-2390 -- Revised the calculations for next run date for Every X Days
            DateTime nextRunDate = lastRunDate.AddDays(Interval);

            Log.Trace("ScheduledDaily: interval=" + Interval.ToString() + " days, last run date=" + lastRunDate.ToShortDateString() + ", next run date=" + nextRunDate.ToShortDateString());
            return(SetToRunAtTime(nextRunDate));
        }
        /// <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("ScheduledWeekly: uponDocking = true; last run time=" + lastRunTime.ToShortDateString() + ", dockedTime=" + dockedTime.ToShortDateString());
                if (lastRunTime < dockedTime)
                {
                    return(dockedTime);
                }
            }


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

            DateTime nextRunDate = lastRunTime.Date; // we're only interested in the date portion, not the time.

            // First, see if this schedule needs to run for any more days in the week
            int daysCount = 1;

            for (DayOfWeek dayOfWeek = lastRunTime.DayOfWeek + 1; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek++, daysCount++)
            {
                if (Days[(int)dayOfWeek])
                {
                    return(SetToRunAtTime(nextRunDate.AddDays(daysCount)));
                }
            }

            // Advance Interval weeks into the future...
            nextRunDate = _gregorianCalendar.AddWeeks(nextRunDate, Interval);
            // ...and wow back up to Sunday of that future week.
            nextRunDate = nextRunDate.AddDays(((int)nextRunDate.DayOfWeek - (int)DayOfWeek.Sunday) * -1);

            // Now, advance to the first day of the week that is marked for recurrence

            // Enum.GetValues is not supported by compact framework.  So we just hardcode in the range instead.
            // foreach ( DayOfWeek dayOfWeek in Enum.GetValues( typeof( DayOfWeek ) ) )
            for (DayOfWeek dayOfWeek = DayOfWeek.Sunday; dayOfWeek <= DayOfWeek.Saturday; dayOfWeek++)
            {
                if (Days[(int)dayOfWeek])
                {
                    return(SetToRunAtTime(nextRunDate.AddDays((int)dayOfWeek)));
                }
            }

            Log.Assert("No recurring DayOfWeek found in " + GetType() + ".CalculateNextRunTime");

            return(DateTime.SpecifyKind(DateTime.MaxValue, DateTimeKind.Local));
        }
示例#8
0
 /// <summary>
 /// Convert the specified UTC time stamp to this time zone's local time.
 /// </summary>
 /// <param name="utcTime"></param>
 public DateTime ToLocalTime(DateTime utcTime)
 {
     return(TimeZoneInfo.ToLocalTime(this, utcTime));
 }