private void BindlstReecntTimes() { BindControl.BindListBox(lstReecntTimes, new List <KVEntity>()); if (rdoOneTimes.Checked) { if (cbxOneTimesHour.SelectedIndex == 0 || cbxOneTimesMinute.SelectedIndex == 0) { return; } } else { if (cbxMultiTimesMinute.SelectedIndex == 0) { return; } } string cronString = QuartzHelper.GenerateCronExpression(BuildCronExpression()); List <DateTime> list = QuartzHelper.GetNextFireTime(cronString, 8); List <KVEntity> kvList = list.Select(item => new KVEntity { K = item.ToString(), V = item.ToString() }).ToList(); BindControl.BindListBox(lstReecntTimes, kvList); }
public ActionResult CalcRunTime(string CronExpression) { List <DateTime> list = QuartzHelper.GetNextFireTime(CronExpression, 20); List <string> sList = new List <string>(); list.ForEach(k => sList.Add(k.ToString())); return(Json(sList, JsonRequestBehavior.AllowGet)); }
private void BindlstReecntTimes() { BindControl.BindListBox(lstRecentTimes, new List <KVEntity>()); if (cbxHour.SelectedIndex == 0 || cbxMinute.SelectedIndex == 0 || chklstMonths.CheckedItems.Count == 0) { return; } string cronString = QuartzHelper.GenerateCronExpression(_cronExpressionEntity); List <DateTime> list = QuartzHelper.GetNextFireTime(cronString, 8); List <KVEntity> kvList = list.Select(item => new KVEntity { K = item.ToString(), V = item.ToString() }).ToList(); BindControl.BindListBox(lstRecentTimes, kvList); }
private void PreviewPalnExcuteTimeFrm_Load(object sender, EventArgs e) { try { lblTaskName.Text = _TaskName; List <DateTime> dateTimeList = QuartzHelper.GetNextFireTime(_CronString, 50); List <KVEntity> list = dateTimeList.Select(item => new KVEntity { K = item.ToString("yyyy-MM-dd HH:mm:ss") }).ToList(); BindControl.BindListBox(lstList, list); } catch (Exception ex) { base.ShowErrorMessage($"Cron表达解析错误,错误信息:[{ex.Message}]"); } }
/// <summary> /// 调度作业 /// </summary> /// <param name="task"></param> /// <param name="isDeleteOldTask"></param> public static void ScheduleJob(TaskEntity task, bool isDeleteOldTask = false) { try { if (isDeleteOldTask) { DeleteJob(task.TaskID); } //验证Cron表达式 if (QuartzHelper.ValidExpression(task.Cron)) { IJobDetail job = new JobDetailImpl(task.TaskID, typeof(TaskJob)); //添加任务参数 job.JobDataMap.Add("TaskParam", task); job.JobDataMap.Add("CanellationTokenParam", cts.Token); CronTriggerImpl trigger = new CronTriggerImpl(); trigger.CronExpressionString = task.Cron; trigger.Name = task.TaskID; trigger.Description = task.TaskName; scheduler.ScheduleJob(job, trigger); if (task.TaskStatus == TaskStatus.STOP) { JobKey jk = new JobKey(task.TaskID); scheduler.PauseJob(jk); } else { List <DateTime> list = QuartzHelper.GetNextFireTime(task.Cron, 5); string msg = string.Join("\r\n", list.Select(item => item.ToString("yyyy-MM-dd HH:mm:ss"))); LogUtil.WriteLog($"任务[{task.TaskID}]启动成功,未来5次运行时间如下:\r\n{msg}"); } } else { throw new Exception($"任务[{task.TaskID}],Cron表达式[{task.Cron}]不正确,无法启动任务"); } } catch (Exception ex) { throw new Exception($"ScheduleJob()方法出现异常,异常信息[{ex.Message}]"); } }
public JsonResult NextFireTime() { string cronExpressionString = Request.Params["CronExpression"].ToString(); try { var result = QuartzHelper.GetNextFireTime(cronExpressionString, 5); string msg = JsonHelper.ToJson(result); return(Json(new { result = true, msg = msg })); } catch { return(Json(new { result = false, msg = "" })); } }
public JsonResult NextFireTime() { string cronExpressionString = Request.Params["CronExpression"].ToString(); try { var result = QuartzHelper.GetNextFireTime(cronExpressionString, 5); JavaScriptSerializer js = new JavaScriptSerializer(); string msg = js.Serialize(result); return(Json(new { result = true, msg = msg })); } catch { return(Json(new { result = false, msg = "" })); } }