Esempio n. 1
0
        /// <summary>
        /// Starts all processing Timers.
        /// </summary>
        /// <description>This Method performs immediate processing
        /// if the time where processing is supposed to start is already in
        /// the past.</description>
        public static void StartProcessing()
        {
            DateTime TodaysStartTime;
            DateTime TomorrowsStartTime;
            TimeSpan InitialSleepTime;
            TimeSpan TwentyfourHrs;

            TLogging.LogAtLevel(1, "TTimedProcessing.StartProcessing got called");

            // Check if any Processing is enabled at all
            if (FProcessDelegates.Count == 0)
            {
                // No Processing is enabled, therefore we don't do anything here!
                return;
            }

            /*
             * Calculate the Timer's time periods
             */

            // Calculate the DateTime of the processing time of today
            TodaysStartTime = DateTime.Now.Date.Add(
                new TimeSpan(FDailyStartTime24Hrs.Hour, FDailyStartTime24Hrs.Minute, 0));

            // Calculate the DateTime of the processing time of the following day
            TomorrowsStartTime = TodaysStartTime.AddDays(1);

            // Calculate the time that the Timer should sleep until it wakes up on processing time of the following day
            InitialSleepTime = TomorrowsStartTime.Subtract(DateTime.Now);

            // Create a TimeSpan that is 1 day (=24 hrs). This is the interval in which following Timer wakeups will occur
            TwentyfourHrs = new TimeSpan(1, 0, 0, 0);             // = 1 day

            if (TLogging.DebugLevel >= 9)
            {
                TLogging.Log("TTimedProcessing.StartProcessing: TodaysStartTime: " + TodaysStartTime.ToString());
                TLogging.Log("TTimedProcessing.StartProcessing: TomorrowsStartTime: " + TomorrowsStartTime.ToString());
                TLogging.Log("TTimedProcessing.StartProcessing: InitialSleepTime: " + InitialSleepTime.ToString());
                TLogging.Log("TTimedProcessing.StartProcessing: TomorrowsStartTime + TwentyfourHrs: " +
                             TomorrowsStartTime.AddTicks(TwentyfourHrs.Ticks).ToString());
            }

            // If the daily start time is earlier that the current time: process individual Processing processes
            // immediately to ensure that they were run today.
            if (TodaysStartTime < DateTime.Now)
            {
                foreach (string delegatename in FProcessDelegates.Keys)
                {
                    // run the job
                    GenericProcessor(delegatename);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Starts all processing Timers.
        /// </summary>
        /// <description>This Method performs immediate processing
        /// if the time where processing is supposed to start is already in
        /// the past.</description>
        public static void StartProcessing()
        {
            DateTime TodaysStartTime;
            DateTime TomorrowsStartTime;
            TimeSpan InitialSleepTime;
            TimeSpan TwentyfourHrs;

            // Check if any Processing is enabled at all
            if (FProcessDelegates.Count == 0)
            {
                // No Processing is enabled, therefore we don't do anything here!
                return;
            }

            /*
             * Calculate the Timer's time periods
             */

            // Calculate the DateTime of the processing time of today
            TodaysStartTime = DateTime.Now.Date.Add(
                new TimeSpan(FDailyStartTime24Hrs.Hour, FDailyStartTime24Hrs.Minute, 0));

            // Calculate the DateTime of the processing time of the following day
            TomorrowsStartTime = TodaysStartTime.AddDays(1);

            // Calculate the time that the Timer should sleep until it wakes up on processing time of the following day
            InitialSleepTime = TomorrowsStartTime.Subtract(DateTime.Now);

            // Create a TimeSpan that is 1 day (=24 hrs). This is the interval in which following Timer wakeups will occur
            TwentyfourHrs = new TimeSpan(1, 0, 0, 0);             // = 1 day

            if (TLogging.DebugLevel >= 9)
            {
                TLogging.Log("TTimedProcessing.StartProcessing: TodaysStartTime: " + TodaysStartTime.ToString());
                TLogging.Log("TTimedProcessing.StartProcessing: TomorrowsStartTime: " + TomorrowsStartTime.ToString());
                TLogging.Log("TTimedProcessing.StartProcessing: InitialSleepTime: " + InitialSleepTime.ToString());
                TLogging.Log("TTimedProcessing.StartProcessing: TomorrowsStartTime + TwentyfourHrs: " +
                             TomorrowsStartTime.AddTicks(TwentyfourHrs.Ticks).ToString());
            }

            /*
             * If the daily start time is earlier that the current time: process individual Processing processes
             * immediately to ensure that they were run today.
             */
            if (TodaysStartTime < DateTime.Now)
            {
                foreach (string delegatename in FProcessDelegates.Keys)
                {
                    // run the job
                    GenericProcessor(delegatename);
                }
            }

            /*
             * Start the Timer(s) for the individual processing Processes
             */
            foreach (string delegatename in FProcessDelegates.Keys)
            {
                InitialSleepTime = InitialSleepTime.Add(new TimeSpan(0, MINUTES_DELAY_BETWEEN_INDIV_PROCESSES, 0));
                TwentyfourHrs    = TwentyfourHrs.Add(new TimeSpan(0, MINUTES_DELAY_BETWEEN_INDIV_PROCESSES, 0));

                // Schedule the regular processing calls.
                FTimers.Add(new System.Threading.Timer(
                                new TimerCallback(new TGenericProcessor(GenericProcessor)),
                                delegatename,
                                InitialSleepTime,
                                TwentyfourHrs));
            }
        }