static TaskManager() { if (ScheduleConfigs.GetConfig().TimerMinutesInterval > 0) { TimerMinutesInterval = ScheduleConfigs.GetConfig().TimerMinutesInterval; } }
public ActionResult Delete(int?currentPageNum, int?pageSize, string Key) { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); sci.Events = sci.Events.Where(p => p.Key != Key).ToArray(); ScheduleConfigs.SaveConfig(sci); return(RedirectToAction("Index", new { currentPageNum = currentPageNum.Value, pageSize = pageSize.Value })); }
public override void Initialize(IApp app) { Logger.LogInfo("UIShell.BusinessEvent Initialize...."); if (eventTimer == null && ScheduleConfigs.GetConfig().Enabled) { eventTimer = new System.Threading.Timer(new TimerCallback(ScheduledEventWorkCallback), null, 60000, EventManager.TimerMinutesInterval * 60000); } }
public CustomJsonResult AjaxEdit(ScheduledEvents model) { var key = LRequest.GetFormString("Key"); #region MyRegion ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); foreach (EventInfo ev1 in sci.Events) { if (ev1.Key == model.Key.Trim()) { ModelState.AddModelError("Key", "消息:计划任务名称已经存在!"); //return RedirectToAction("Index", new { currentPageNum = model.CurrentPageNum, pageSize = model.PageSize }); } } foreach (EventInfo ev1 in sci.Events) { if (ev1.Key == key) { ev1.Key = model.Key.Trim(); ev1.ScheduleType = model.ScheduleType.Trim(); if (model.ExetimeType) { ev1.TimeOfDay = model.hour * 60 + model.minute; ev1.Minutes = sci.TimerMinutesInterval; } else { if (model.timeserval < sci.TimerMinutesInterval) { ev1.Minutes = sci.TimerMinutesInterval; } else { ev1.Minutes = model.timeserval; } ev1.TimeOfDay = -1; } if (!ev1.IsSystemEvent) { ev1.Enabled = model.Enable; } break; } } ScheduleConfigs.SaveConfig(sci); #endregion var result = new Result(true); var json = new CustomJsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; json.Data = result; return(json); }
public CustomJsonResult AjaxAdd(ScheduledEvents model, FormCollection collection) { int Entity_ExetimeType = 0; if (collection.GetValues("Entity.ExetimeType") != null) { Entity_ExetimeType = int.Parse(collection.GetValue("Entity.ExetimeType").AttemptedValue); } #region MyRegion ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); foreach (EventInfo ev1 in sci.Events) { if (ev1.Key == model.Key.Trim()) { ModelState.AddModelError("Key", "消息:计划任务名称已经存在!"); //return RedirectToAction("Index", new { currentPageNum = model.CurrentPageNum, pageSize = model.PageSize }); } } EventInfo ev = new EventInfo(); ev.Key = model.Key; ev.Enabled = true; ev.IsSystemEvent = false; ev.ScheduleType = model.ScheduleType.ToString(); model.ExetimeType = Entity_ExetimeType == 0 ? false : true; if (model.ExetimeType) { ev.TimeOfDay = model.hour * 60 + model.minute; ev.Minutes = sci.TimerMinutesInterval; } else { ev.Minutes = model.timeserval; ev.TimeOfDay = -1; } EventInfo[] es = new EventInfo[sci.Events.Length + 1]; for (int i = 0; i < sci.Events.Length; i++) { es[i] = sci.Events[i]; } es[es.Length - 1] = ev; sci.Events = es; ScheduleConfigs.SaveConfig(sci); #endregion var result = new Result(true); var json = new CustomJsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; json.Data = result; return(json); }
/// <summary> /// 实现接口的Init方法 /// </summary> /// <param name="context"></param> public void Init(HttpApplication context) { OnlineUsers.ResetOnlineList(); context.BeginRequest += new EventHandler(ReUrl_BeginRequest); if (eventTimer == null && ScheduleConfigs.GetConfig().Enabled) { EventLogs.LogFileName = Utils.GetMapPath(string.Format("{0}cache/scheduleeventfaildlog.config", BaseConfigs.GetForumPath)); EventManager.RootPath = Utils.GetMapPath(BaseConfigs.GetForumPath); eventTimer = new Timer(new TimerCallback(ScheduledEventWorkCallback), context.Context, 60000, EventManager.TimerMinutesInterval * 60000); } context.Error += new EventHandler(Application_OnError); }
private void ScheduledEventWorkCallback(object sender) { try { if (ScheduleConfigs.GetConfig().Enabled) { EventManager.Execute(); } } catch (Exception ex) { EventLogs.WriteFailedLog("Failed ScheduledEventCallBack," + ex.Source + "," + ex.Data + "," + ex); } }
private void ScheduledEventWorkCallback(object sender) { try { if (ScheduleConfigs.GetConfig().Enabled) { EventManager.Execute(); } } catch { EventLogs.WriteFailedLog("Failed ScheduledEventCallBack"); } }
private void ScheduledEventWorkCallback(object state) { try { if (ScheduleConfigs.GetConfig().Enabled) { EventManager.Execute(); } } catch (Exception ex) { Logger.LogError("Failed ScheduledEventCallBack: ", ex); } }
public ActionResult Edit(AddOrEditViewModel <ScheduledEvents> model, FormCollection collection) { var key = LRequest.GetFormString("Key"); #region MyRegion ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); foreach (EventInfo ev1 in sci.Events) { if (ev1.Key == model.Entity.Key.Trim()) { ModelState.AddModelError("Key", "消息:计划任务名称已经存在!"); return(RedirectToAction("Index", new { currentPageNum = model.CurrentPageNum, pageSize = model.PageSize })); } } foreach (EventInfo ev1 in sci.Events) { if (ev1.Key == key) { ev1.Key = model.Entity.Key.Trim(); ev1.ScheduleType = model.Entity.ScheduleType.Trim(); if (model.Entity.ExetimeType) { ev1.TimeOfDay = model.Entity.hour * 60 + model.Entity.minute; ev1.Minutes = sci.TimerMinutesInterval; } else { if (model.Entity.timeserval < sci.TimerMinutesInterval) { ev1.Minutes = sci.TimerMinutesInterval; } else { ev1.Minutes = model.Entity.timeserval; } ev1.TimeOfDay = -1; } if (!ev1.IsSystemEvent) { ev1.Enabled = model.Entity.Enable; } break; } } ScheduleConfigs.SaveConfig(sci); #endregion return(RedirectToAction("Index", new { currentPageNum = model.CurrentPageNum, pageSize = model.PageSize })); }
public static void Execute() { Discuz.Config.Event[] simpleItems = ScheduleConfigs.GetConfig().Events; Event[] items; #if NET1 ArrayList list = new ArrayList(); #else List <Event> list = new List <Event>(); #endif foreach (Discuz.Config.Event 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); } #if NET1 items = (Event[])list.ToArray(typeof(Event)); #else items = list.ToArray(); #endif 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)); } } } }
public CustomJsonResult AjaxDelete(string Key) { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); sci.Events = sci.Events.Where(p => p.Key != Key).ToArray(); ScheduleConfigs.SaveConfig(sci); var result = new Result(true); var json = new CustomJsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; json.Data = result; return(json); }
public ActionResult ExecCommand(string Key) { 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(HttpContext); Event.SetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName, DateTime.Now); break; } } } return(RedirectToAction("Index")); }
protected void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName == "exec") { Discuz.Config.Event[] events = ScheduleConfigs.GetConfig().Events; foreach (Discuz.Config.Event ev in events) { if (ev.Key == e.CommandArgument.ToString()) { ((Discuz.Forum.ScheduledEvents.IEvent)Activator.CreateInstance(Type.GetType(ev.ScheduleType))).Execute(HttpContext.Current); DatabaseProvider.GetInstance().SetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName, DateTime.Now); break; } } //base.RegisterStartupScript("exec", "window.location.href=window.location;"); } }
/// <summary> /// 实现接口的Init方法 /// </summary> /// <param name="context"></param> public void Init(HttpApplication context) { try { OnlineUsers.ResetOnlineList(); context.BeginRequest += new EventHandler(ReUrl_BeginRequest); if (eventTimer == null && ScheduleConfigs.GetConfig().Enabled) { EventManager.RootPath = AppDomain.CurrentDomain.BaseDirectory; eventTimer = new Timer(new TimerCallback(ScheduledEventWorkCallback), context.Context, 60000, EventManager.TimerMinutesInterval * 60000); } } catch (Exception e) { EventLogs.WriteFailedLog("Discuz.Forum.HttpModule Init:" + e.Message); } }
public List <ScheduledEvents> FindAll() { 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()); }
protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("key"); dt.Columns.Add("scheduletype"); dt.Columns.Add("exetime"); dt.Columns.Add("lastexecute"); dt.Columns.Add("issystemevent"); dt.Columns.Add("enable"); Discuz.Config.Event[] events = ScheduleConfigs.GetConfig().Events; foreach (Discuz.Config.Event 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 = Discuz.Forum.ScheduledEvents.Event.GetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName); if (lastExecute == DateTime.MinValue) { dr["lastexecute"] = "从未执行"; } else { dr["lastexecute"] = lastExecute.ToString("yyyy-MM-dd HH:mm:ss"); } dr["issystemevent"] = ev.IsSystemEvent ? "系统级" : "非系统级"; dr["enable"] = ev.Enabled ? "启用" : "禁用"; dt.Rows.Add(dr); } DataGrid1.DataSource = dt; DataGrid1.DataKeyField = "key"; DataGrid1.DataBind(); }
public CustomJsonResult AjaxExecCommand(string Key) { 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(HttpContext); Event.SetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName, DateTime.Now); break; } } } var result = new Result(true); var json = new CustomJsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; json.Data = result; return(json); }
/// <summary> /// 建立邀请计划任务 /// </summary> private void CreateInvitationSchedule() { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); //检查该事件是否存在 foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == "InvitationEvent") { return; } } //建立新的邀请计划任务 Discuz.Config.Event ev = new Discuz.Config.Event(); ev.Key = "InvitationEvent"; ev.Enabled = true; ev.IsSystemEvent = true; ev.ScheduleType = "Discuz.Event.InvitationEvent, Discuz.Event"; ev.TimeOfDay = 2; ev.Minutes = 1; ScheduleConfigs.SaveConfig(sci); }
protected void savepassportinfo_Click(object sender, EventArgs e) { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); if (key.Text.Trim() == "") { base.RegisterStartupScript("PAGE", "alert('计划任务名称不能为空!');"); return; } if (scheduletype.Text.Trim() == "") { base.RegisterStartupScript("PAGE", "alert('计划任务类型不能为空!');"); return; } if (type2.Checked && (timeserval.Text == "" || !Utils.IsNumeric(timeserval.Text))) { base.RegisterStartupScript("PAGE", "alert('周期执行时间必须为数值!');"); return; } if (DNTRequest.GetString("keyid") == "") { foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == key.Text.Trim()) { base.RegisterStartupScript("PAGE", "alert('计划任务名称已经存在!');"); return; } } Discuz.Config.Event ev = new Discuz.Config.Event(); ev.Key = key.Text; ev.Enabled = true; ev.IsSystemEvent = false; ev.ScheduleType = scheduletype.Text.Trim(); if (type1.Checked) { ev.TimeOfDay = int.Parse(hour.Text) * 60 + int.Parse(minute.Text); ev.Minutes = sci.TimerMinutesInterval; } else { ev.Minutes = int.Parse(timeserval.Text.Trim()); ev.TimeOfDay = -1; } Discuz.Config.Event[] es = new Discuz.Config.Event[sci.Events.Length + 1]; for (int i = 0; i < sci.Events.Length; i++) { es[i] = sci.Events[i]; } es[es.Length - 1] = ev; sci.Events = es; } else { foreach (Discuz.Config.Event ev1 in sci.Events) { if (key.Text.Trim() != oldkey.Value && ev1.Key == key.Text.Trim()) { base.RegisterStartupScript("PAGE", "alert('计划任务名称已经存在!');"); return; } } foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == oldkey.Value) { ev1.Key = key.Text.Trim(); ev1.ScheduleType = scheduletype.Text.Trim(); if (type1.Checked) { ev1.TimeOfDay = int.Parse(hour.Text) * 60 + int.Parse(minute.Text); ev1.Minutes = sci.TimerMinutesInterval; } else { if (int.Parse(timeserval.Text.Trim()) < sci.TimerMinutesInterval) { ev1.Minutes = sci.TimerMinutesInterval; } else { ev1.Minutes = int.Parse(timeserval.Text.Trim()); } ev1.TimeOfDay = -1; } if (!ev1.IsSystemEvent) { if (eventenable.Items[0].Selected) { ev1.Enabled = true; } else { ev1.Enabled = false; } } break; } } } ScheduleConfigs.SaveConfig(sci); Response.Redirect("global_schedulemanage.aspx"); #region /*if (appname.Text.Trim() == "") * { * base.RegisterStartupScript("PAGE", "alert('整合程序名称不能为空!');"); * return; * } * if (appurl.Text.Trim() == "") * { * base.RegisterStartupScript("PAGE", "alert('整合程序 Url 地址不能为空!');"); * return; * } * if (callbackurl.Text.Trim() == "") * { * base.RegisterStartupScript("PAGE", "alert('登录完成后返回地址不能为空!');"); * return; * } * if (ipaddresses.Text.Trim() != "") * { * foreach (string ip in ipaddresses.Text.Replace("\r\n","").Replace(" ","").Split(',')) * { * if (!Utils.IsIP(ip)) * { * base.RegisterStartupScript("PAGE", "alert('IP地址格式错误!');"); * return; * } * } * } * if (apikeyhidd.Value == "") //增加 * { * ApplicationInfo ai = new ApplicationInfo(); * ai.AppName = appname.Text; * ai.AppUrl = appurl.Text; * ai.APIKey = Utils.MD5(System.Guid.NewGuid().ToString()); * ai.Secret = Utils.MD5(System.Guid.NewGuid().ToString()); * ai.CallbackUrl = callbackurl.Text; * ai.IPAddresses = ipaddresses.Text.Replace("\r\n","").Replace(" ",""); * APIConfigInfo aci = APIConfigs.GetConfig(); * if (aci.AppCollection == null) * aci.AppCollection = new ApplicationInfoCollection(); * aci.AppCollection.Add(ai); * APIConfigs.SaveConfig(aci); * } * else //修改 * { * APIConfigInfo aci = APIConfigs.GetConfig(); * foreach (ApplicationInfo ai in aci.AppCollection) * { * if (ai.APIKey == apikeyhidd.Value) * { * ai.AppName = appname.Text; * ai.AppUrl = appurl.Text; * ai.CallbackUrl = callbackurl.Text; * ai.IPAddresses = ipaddresses.Text.Replace("\r\n","").Replace(" ",""); * break; * } * } * APIConfigs.SaveConfig(aci); * } * Response.Redirect("global_passportmanage.aspx");*/ #endregion }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { type1.Attributes.Add("onclick", "changetimespan(this.value)"); type2.Attributes.Add("onclick", "changetimespan(this.value)"); for (int i = 0; i < 24; i++) { hour.Items.Add(new ListItem(i.ToString("00"), i.ToString())); } for (int i = 0; i < 60; i++) { minute.Items.Add(new ListItem(i.ToString("00"), i.ToString())); } if (DNTRequest.GetString("keyid") != "") { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == DNTRequest.GetString("keyid")) { oldkey.Value = ev1.Key; key.Text = ev1.Key; key.Enabled = !ev1.IsSystemEvent; scheduletype.Text = ev1.ScheduleType; scheduletype.Enabled = !ev1.IsSystemEvent; timeserval.HintInfo = "设置执行时间间隔,最小值:" + sci.TimerMinutesInterval + "分钟.如果设置值小于最小值,将取最小值"; if (ev1.TimeOfDay != -1) { int _hour = ev1.TimeOfDay / 60; int _minute = ev1.TimeOfDay % 60; type1.Checked = true; hour.SelectedValue = _hour.ToString(); minute.SelectedValue = _minute.ToString(); hour.Enabled = true; minute.Enabled = true; timeserval.Enabled = false; } else { type2.Checked = true; timeserval.Text = ev1.Minutes.ToString(); hour.Enabled = false; minute.Enabled = false; timeserval.Enabled = true; } if (!ev1.IsSystemEvent) { eventenabletr.Visible = true; if (ev1.Enabled) { eventenable.Items[0].Selected = true; } else { eventenable.Items[1].Selected = true; } } } } } #region /*string apikey = DNTRequest.GetString("apikey"); * if (apikey != "") * { * APIConfigInfo aci = APIConfigs.GetConfig(); * foreach (ApplicationInfo ai in aci.AppCollection) * { * if (ai.APIKey == apikey) * { * appname.Text = ai.AppName; * appurl.Text = ai.AppUrl; * callbackurl.Text = ai.CallbackUrl; * ipaddresses.Text = ai.IPAddresses; * break; * } * } * } * apikeyhidd.Value = apikey;*/ #endregion } }
protected void Page_Load(object sender, EventArgs e) { //if (!IsPostBack) //{ DataTable dt = new DataTable(); dt.Columns.Add("key"); dt.Columns.Add("scheduletype"); dt.Columns.Add("exetime"); dt.Columns.Add("lastexecute"); dt.Columns.Add("issystemevent"); dt.Columns.Add("enable"); Discuz.Config.Event[] events = ScheduleConfigs.GetConfig().Events; foreach (Discuz.Config.Event 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 = DatabaseProvider.GetInstance().GetLastExecuteScheduledEventDateTime(ev.Key, Environment.MachineName); if (lastExecute == DateTime.MinValue) { dr["lastexecute"] = "从未执行"; } else { dr["lastexecute"] = lastExecute.ToString("yyyy-MM-dd HH:mm:ss"); } dr["issystemevent"] = ev.IsSystemEvent ? "系统级" : "非系统级"; dr["enable"] = ev.Enabled ? "启用" : "禁用"; dt.Rows.Add(dr); } //DataGrid1.TableHeaderName = "计划任务列表"; DataGrid1.DataSource = dt; DataGrid1.DataKeyField = "key"; DataGrid1.DataBind(); #region /*APIConfigInfo aci = APIConfigs.GetConfig(); * allowpassport.SelectedValue = aci.Enable ? "1" : "0"; * passportbody.Attributes.Add("style", "display:" + (aci.Enable ? "block" : "none")); * allowpassport.Items[0].Attributes.Add("onclick", "setAllowPassport(1)"); * allowpassport.Items[1].Attributes.Add("onclick", "setAllowPassport(0)"); * ApplicationInfoCollection appColl = aci.AppCollection; * DataTable dt = new DataTable(); * dt.Columns.Add("appname"); * dt.Columns.Add("appurl"); * dt.Columns.Add("apikey"); * dt.Columns.Add("secret"); * foreach (ApplicationInfo ai in appColl) * { * DataRow dr = dt.NewRow(); * dr["appname"] = ai.AppName; * dr["appurl"] = ai.AppUrl; * dr["apikey"] = ai.APIKey; * dr["secret"] = ai.Secret; * dt.Rows.Add(dr); * } * DataGrid1.TableHeaderName = "整合程序列表"; * DataGrid1.DataKeyField = "apikey"; * DataGrid1.DataSource = dt; * DataGrid1.DataBind();*/ #endregion //} }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { type1.Attributes.Add("onclick", "changetimespan(this.value)"); type2.Attributes.Add("onclick", "changetimespan(this.value)"); for (int i = 0; i < 24; i++) { hour.Items.Add(new ListItem(i.ToString("00"), i.ToString())); } for (int i = 0; i < 60; i++) { minute.Items.Add(new ListItem(i.ToString("00"), i.ToString())); } if (DNTRequest.GetString("keyid") != "") { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == DNTRequest.GetString("keyid")) { oldkey.Value = ev1.Key; key.Text = ev1.Key; key.Enabled = !ev1.IsSystemEvent; scheduletype.Text = ev1.ScheduleType; scheduletype.Enabled = !ev1.IsSystemEvent; timeserval.HintInfo = "设置执行时间间隔,最小值:" + sci.TimerMinutesInterval + "分钟.如果设置值小于最小值,将取最小值"; if (ev1.TimeOfDay != -1) { int _hour = ev1.TimeOfDay / 60; int _minute = ev1.TimeOfDay % 60; type1.Checked = true; hour.SelectedValue = _hour.ToString(); minute.SelectedValue = _minute.ToString(); hour.Enabled = true; minute.Enabled = true; timeserval.Enabled = false; } else { type2.Checked = true; timeserval.Text = ev1.Minutes.ToString(); hour.Enabled = false; minute.Enabled = false; timeserval.Enabled = true; } if (!ev1.IsSystemEvent) { //eventenabletr.Visible = true; if (ev1.Enabled) { eventenable.Items[0].Selected = true; } else { eventenable.Items[1].Selected = true; } } else { eventenable.Items[0].Selected = true; eventenable.Enabled = false; } } } } } }
protected void savepassportinfo_Click(object sender, EventArgs e) { ScheduleConfigInfo sci = ScheduleConfigs.GetConfig(); if (key.Text.Trim() == "") { base.RegisterStartupScript("PAGE", "alert('计划任务名称不能为空!');"); return; } if (scheduletype.Text.Trim() == "") { base.RegisterStartupScript("PAGE", "alert('计划任务类型不能为空!');"); return; } if (type2.Checked && (timeserval.Text == "" || !Utils.IsNumeric(timeserval.Text))) { base.RegisterStartupScript("PAGE", "alert('周期执行时间必须为数值!');"); return; } if (DNTRequest.GetString("keyid") == "") { foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == key.Text.Trim()) { base.RegisterStartupScript("PAGE", "alert('计划任务名称已经存在!');"); return; } } Discuz.Config.Event ev = new Discuz.Config.Event(); ev.Key = key.Text; ev.Enabled = true; ev.IsSystemEvent = false; ev.ScheduleType = scheduletype.Text.Trim(); if (type1.Checked) { ev.TimeOfDay = int.Parse(hour.Text) * 60 + int.Parse(minute.Text); ev.Minutes = sci.TimerMinutesInterval; } else { ev.Minutes = int.Parse(timeserval.Text.Trim()); ev.TimeOfDay = -1; } Discuz.Config.Event[] es = new Discuz.Config.Event[sci.Events.Length + 1]; for (int i = 0; i < sci.Events.Length; i++) { es[i] = sci.Events[i]; } es[es.Length - 1] = ev; sci.Events = es; } else { foreach (Discuz.Config.Event ev1 in sci.Events) { if (key.Text.Trim() != oldkey.Value && ev1.Key == key.Text.Trim()) { base.RegisterStartupScript("PAGE", "alert('计划任务名称已经存在!');"); return; } } foreach (Discuz.Config.Event ev1 in sci.Events) { if (ev1.Key == oldkey.Value) { ev1.Key = key.Text.Trim(); ev1.ScheduleType = scheduletype.Text.Trim(); if (type1.Checked) { ev1.TimeOfDay = int.Parse(hour.Text) * 60 + int.Parse(minute.Text); ev1.Minutes = sci.TimerMinutesInterval; } else { if (int.Parse(timeserval.Text.Trim()) < sci.TimerMinutesInterval) { ev1.Minutes = sci.TimerMinutesInterval; } else { ev1.Minutes = int.Parse(timeserval.Text.Trim()); } ev1.TimeOfDay = -1; } if (!ev1.IsSystemEvent) { if (eventenable.Items[0].Selected) { ev1.Enabled = true; } else { ev1.Enabled = false; } } break; } } } ScheduleConfigs.SaveConfig(sci); Response.Redirect("global_schedulemanage.aspx"); }