/// <summary> /// 保存配置类实例 /// </summary> /// <returns></returns> public static bool SaveConfig(ScheduleConfigInfo scheduleconfiginfo) { ScheduleConfigFileManager scfm = new ScheduleConfigFileManager(); ScheduleConfigFileManager.ConfigInfo = scheduleconfiginfo; return(scfm.SaveConfig()); }
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 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); }
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 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); }
/// <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); }
/// <summary> /// 初始化文件修改时间和对象实例 /// </summary> static ScheduleConfigFileManager() { m_fileoldchange = System.IO.File.GetLastWriteTime(ConfigFilePath); m_configinfo = (ScheduleConfigInfo)DefaultConfigFileManager.DeserializeInfo(ConfigFilePath, typeof(ScheduleConfigInfo)); }
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"); }
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 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 }
/// <summary> /// 保存配置类实例 /// </summary> /// <returns></returns> public static bool SaveConfig(ScheduleConfigInfo scheduleconfiginfo) { ScheduleConfigFileManager scfm = new ScheduleConfigFileManager(); ScheduleConfigFileManager.ConfigInfo = scheduleconfiginfo; return scfm.SaveConfig(); }