Пример #1
0
 static EventManager()
 {
     if (ScheduleConfigs.GetConfig().TimerMinutesInterval > 0)
     {
         TimerMinutesInterval = ScheduleConfigs.GetConfig().TimerMinutesInterval;
     }
 }
        public Result AjaxExecCommand(string Key, HttpContextBase context)
        {
            var result = new Result(true);

            try
            {
                if (!string.IsNullOrWhiteSpace(Key))
                {
                    EventInfo[] events = ScheduleConfigs.GetConfig().Events;
                    foreach (EventInfo ev in events)
                    {
                        if (ev.Key == Key)
                        {
                            ((IEvent)Activator.CreateInstance(Type.GetType(ev.ScheduleType))).Execute(context);
                            Event.SetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName, DateTime.Now);
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                result = new Result(false);
            }
            return(result);
        }
        public Result Delete(string Key)
        {
            ScheduleConfigInfo sci = ScheduleConfigs.GetConfig();

            sci.Events = sci.Events.Where(p => p.Key != Key).ToArray();
            ScheduleConfigs.SaveConfig(sci);
            return(new Result(true));
        }
        public List <ScheduledEvents> GetAll()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("key", typeof(string));
            dt.Columns.Add("scheduletype", typeof(string));
            dt.Columns.Add("exetime", typeof(string));
            dt.Columns.Add("lastexecuted", typeof(DateTime));
            dt.Columns.Add("issystemevent", typeof(bool));
            dt.Columns.Add("enable", typeof(bool));
            EventInfo[] events = ScheduleConfigs.GetConfig().Events;
            foreach (EventInfo ev in events)
            {
                DataRow dr = dt.NewRow();
                dr["key"]          = ev.Key;
                dr["scheduletype"] = ev.ScheduleType;
                if (ev.TimeOfDay != -1)
                {
                    dr["exetime"] = "定时执行:" + (ev.TimeOfDay / 60) + "时" + (ev.TimeOfDay % 60) + "分";
                }
                else
                {
                    dr["exetime"] = "周期执行:" + ev.Minutes + "分钟";
                }
                DateTime lastExecute = Event.GetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName);
                if (lastExecute == DateTime.MinValue)
                {
                    dr["lastexecuted"] = Convert.ToDateTime("1999-01-01").ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    dr["lastexecuted"] = lastExecute.ToString("yyyy-MM-dd HH:mm:ss");
                }
                dr["issystemevent"] = ev.IsSystemEvent.ToString(); // ? "系统级" : "非系统级";
                dr["enable"]        = ev.Enabled.ToString();       // ? "启用" : "禁用";
                dt.Rows.Add(dr);
            }
            var list = dt.ToArray <ScheduledEvents>();

            return(list.ToList());
        }
Пример #5
0
        public static void Execute()
        {
            EventInfo[]  simpleItems = ScheduleConfigs.GetConfig().Events;
            Event[]      items;
            List <Event> list = new List <Event>();

            foreach (EventInfo newEvent in simpleItems)
            {
                if (!newEvent.Enabled)
                {
                    continue;
                }
                Event e = new Event();
                e.Key          = newEvent.Key;
                e.Minutes      = newEvent.Minutes;
                e.ScheduleType = newEvent.ScheduleType;
                e.TimeOfDay    = newEvent.TimeOfDay;

                list.Add(e);
            }
            items = list.ToArray();
            Event item = null;

            if (items != null)
            {
                for (int i = 0; i < items.Length; i++)
                {
                    item = items[i];
                    if (item.ShouldExecute)
                    {
                        item.UpdateTime();
                        IEvent e = item.IEventInstance;
                        ManagedThreadPool.QueueUserWorkItem(new WaitCallback(e.Execute));
                    }
                }
            }
        }