예제 #1
0
 // method to set the time when the timer should wake up to invoke the next schedule
 private static void SetNextEventTime()
 {
     if (m_schedulesList.Count == 0) {
         m_timer.Change(Timeout.Infinite, Timeout.Infinite); // this will put the timer to sleep
         return;
     }
     m_nextSchedule = (Schedule) m_schedulesList[0];
     TimeSpan ts = m_nextSchedule.NextInvokeTime.Subtract(DateTime.Now);
     if (ts < TimeSpan.Zero)
         ts = TimeSpan.Zero; // cannot be negative !
     m_timer.Change((int) ts.TotalMilliseconds, Timeout.Infinite); // invoke after the timespan
 }
예제 #2
0
 /// <summary>
 /// Shutdown the scheduler
 /// </summary>
 /// <remarks>
 /// once shutdown, the only way to restart the scheduler is to restart the whole application
 /// </remarks>
 public static void Shutdown()
 {
     lock (lockObj) {
         if (IsShutDown) return;
         m_timer = null;
         m_schedulesList.Clear();
         m_nextSchedule = null;
         Logger.InfoFormat(WINDOWINFOFORMAT, "Scheduler Shutdown");
         LogManager.Shutdown();
     }
 }
예제 #3
0
 /// <summary>
 /// remove a schedule object from the list
 /// </summary>
 /// <param name="s"></param>
 public static void RemoveSchedule(Schedule s)
 {
     m_schedulesList.Remove(s);
     SetNextEventTime();
     if (OnSchedulerEvent != null)
         OnSchedulerEvent(SchedulerEventType.DELETED, s.Name);
 }
예제 #4
0
 public static bool Contains(Schedule val)
 {
     return m_schedulesList.Contains(val);
 }
예제 #5
0
        /// <summary>
        /// add a new schedule
        /// </summary>
        /// <param name="s"></param>
        /// <param name="i"></param>
        public static void AddSchedule(Schedule s, IInterceptor i)
        {
            if (IsShutDown)
                throw new SchedulerException("Scheduler is already shutdown");
            if (GetSchedule(s.Name) != null)
                throw new SchedulerException("Schedule with the same name already exists");
            m_schedulesList.Add(s);
            if (i != null) {
                s.PreTrigger += new Invoke(i.SchedulePreTrigger);
                s.PostTrigger += new Invoke(i.SchedulePostTrigger);
            }
            m_schedulesList.Sort();

            // adjust the next event time if schedule is added at the top of the list
            if (m_schedulesList[0] == s)
                SetNextEventTime();
            if (OnSchedulerEvent != null)
                OnSchedulerEvent(SchedulerEventType.CREATED, s.Name);
        }
예제 #6
0
 public static void AddSchedule(Schedule s)
 {
     AddSchedule(s, null);
 }