在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在原来的公司曾经用asp.net + extjs 2做过一个Quartz.Net简单管理平台(后来申请了著作权,尽然也可以),随着Asp.Net MVC 3和ExtJs 4的发布,突然有了重新用Asp.Net MVC 3 + ExtJs 4重新做一下的冲动(冲动是魔鬼呀。。。)。本次只实现了显示触发器Trigger的信息。 效果图:
1.定义TriggerInfo,这里为了方便起见只列出了TriggerInfo的定义
1 using System; 2 using System.Runtime.Serialization; 3 4 [DataContract] 5 public class TriggerInfo 6 { 7 [DataMember] 8 public string CalendarName { get; set; } 9 10 [DataMember] 11 public string Description { get; set; } 12 13 [DataMember] 14 public DateTime? EndTimeUtc { get; set; } 15 16 [DataMember] 17 public DateTime? FinalFireTimeUtc { get; set; } 18 19 [DataMember] 20 public string FireInstanceId { set; get; } 21 22 [DataMember] 23 public string FullJobName { get; set; } 24 25 [DataMember] 26 public string FullName { get; set; } 27 28 [DataMember] 29 public string Group { get; set; } 30 31 [DataMember] 32 public bool HasAdditionalProperties { get; set; } 33 34 [DataMember] 35 public bool HasMillisecondPrecision { get; set; } 36 37 [DataMember] 38 public string JobGroup { get; set; } 39 40 [DataMember] 41 public string JobName { get; set; } 42 43 [DataMember] 44 public string Key { get; set; } 45 46 [DataMember] 47 public bool MayFireAgain { get; set; } 48 49 [DataMember] 50 public int MisfireInstruction { get; set; } 51 52 [DataMember] 53 public string Name { get; set; } 54 55 [DataMember] 56 public DateTime? NextFireTimeUtc { get; set; } 57 58 [DataMember] 59 public DateTime? PreviousFireTimeUtc { get; set; } 60 61 [DataMember] 62 public int Priority { get; set; } 63 64 [DataMember] 65 public DateTime StartTimeUtc { get; set; } 66 67 [DataMember] 68 public string[] TriggerListenerNames { get; set; } 69 70 [DataMember] 71 public TriggerType TriggerType { get; set; } 72 73 [DataMember] 74 public TriggerStateInfo TriggerState { get; set; } 75 76 [DataMember] 77 public bool Volatile { get; set; } 78 79 [DataMember] 80 public int RepeatCount { get; set; } 81 82 [DataMember] 83 public TimeSpan RepeatInterval { get; set; } 84 85 [DataMember] 86 public int TimesTriggered { get; set; } 87 88 [DataMember] 89 public int RepeatIndefinitely { get; set; } 90 91 [DataMember] 92 public string CronExpressionString { get; set; } 93 94 [DataMember] 95 public TimeZoneInfo TimeZone { get; set; } 96 } 2.定义服务契约IScheduleService
1 using System; 2 using System.ServiceModel; 3 4 using DataContract; 5 6 [ServiceContract] 7 public interface IScheduleService 8 { 9 [OperationContract] 10 void AddJob(JobInfo jobInfo, bool replace); 11 12 [OperationContract] 13 bool DeleteJob(string jobName, string groupName); 14 15 [OperationContract] 16 string[] GetJobGroupNames(); 17 18 [OperationContract] 19 JobInfo GetJobDetail(string jobName, string groupName); 20 21 [OperationContract] 22 string[] GetJobNames(string groupName); 23 24 [OperationContract] 25 TriggerInfo GetTrigger(string triggerName, string groupName); 26 27 [OperationContract] 28 string[] GetTriggerGroupNames(); 29 30 [OperationContract] 31 string[] GetTriggerNames(string groupName); 32 33 [OperationContract] 34 TriggerStateInfo GetTriggerState(string triggerName, string triggerGroup); 35 36 [OperationContract] 37 bool IsJobGroupPaused(string groupName); 38 39 [OperationContract] 40 bool IsTriggerGroupPaused(string groupName); 41 42 [OperationContract] 43 void PauseAll(); 44 45 [OperationContract] 46 void PauseJob(string jobName, string groupName); 47 48 [OperationContract] 49 void PauseJobGroup(string groupName); 50 51 [OperationContract] 52 void PauseTrigger(string triggerName, string triggerGroup); 53 54 [OperationContract] 55 void PauseTriggerGroup(string triggerGroup); 56 57 [OperationContract] 58 DateTime? RescheduleJob(string triggerName, string triggerGroup, TriggerInfo newTrigger); 59 60 [OperationContract] 61 void ResumeAll(); 62 63 [OperationContract] 64 void ResumeJob(string jobName, string groupName); 65 66 [OperationContract] 67 void ResumeJobGroup(string groupName); 68 69 [OperationContract] 70 void ResumeTrigger(string triggerName, string groupName); 71 72 [OperationContract] 73 void ResumeTriggerGroup(string groupName); 74 75 [OperationContract] 76 DateTime ScheduleJob(TriggerInfo trigger); 77 78 [OperationContract] 79 DateTime ScheduleJobByTrigger(JobInfo jobInfo, TriggerInfo trigger); 80 81 [OperationContract] 82 void Shutdown(bool waitForJobsToComplete); 83 84 [OperationContract] 85 void Standby(); 86 87 [OperationContract] 88 void Start(); 89 90 [OperationContract] 91 void StartDelayed(TimeSpan delay); 92 93 [OperationContract] 94 void TriggerJob(string jobName, string groupName); 95 96 [OperationContract] 97 void TriggerJobWithVolatileTrigger(string jobName, string groupName); 98 99 [OperationContract] 100 void UnscheduleJob(string triggerName, string groupName); 101 } 3.实现服务契约IScheduleService的ScheduleService ,由于服务提交代码,只能描述一下了,这个类就是把Quartz.Net的Schedule封装了一下。 4.定义SchduleController,来输出Job和Trigger的信息
1 using System.Collections.Generic; 2 using System.Web.Mvc; 3 4 using Vancl.Schedule.DataContract; 5 using Vancl.Schedule.ServiceContract; 6 using Vancl.Schedule.ServiceImpl; 7 8 public class ScheduleController : Controller 9 { 10 private readonly IScheduleService scheduleService = ScheduleService.Instance; 11 12 /// <summary> 13 /// 获取所有任务 14 /// </summary> 15 /// <returns></returns> 16 public ActionResult GetJobs() 17 { 18 IList<JobInfo> jobInfoes = new List<JobInfo>(); 19 20 string[] groupNames = scheduleService.GetJobGroupNames(); 21 22 if (groupNames != null) 23 { 24 foreach (string groupName in groupNames) 25 { 26 string[] jobNames = scheduleService.GetJobNames(groupName); 27 28 if (jobNames != null) 29 { 30 foreach (string jobName in jobNames) 31 { 32 jobInfoes.Add(scheduleService.GetJobDetail(jobName, groupName)); 33 } 34 } 35 } 36 } 37 38 return new JsonResult() { Data = jobInfoes, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; 39 } 40 41 /// <summary> 42 /// 获取所有触发器 43 /// </summary> 44 /// <returns></returns> 45 public ActionResult GetTriggers() 46 { 47 IList<TriggerInfo> triggerInfoes = new List<TriggerInfo>(); 48 49 string[] groupNames = scheduleService.GetTriggerGroupNames(); 50 51 if (groupNames != null) 52 { 53 foreach (string groupName in groupNames) 54 { 55 string[] triggerNames = scheduleService.GetTriggerNames(groupName); 56 57 if (triggerNames != null) 58 { 59 foreach (string triggerName in triggerNames) 60 { 61 TriggerInfo triggerInfo = scheduleService.GetTrigger(triggerName, groupName); 62 triggerInfo.TriggerState = scheduleService.GetTriggerState(triggerName, groupName); 63 triggerInfoes.Add(triggerInfo); 64 } 65 } 66 } 67 } 68 69 return new JsonResult() { Data = triggerInfoes, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; 70 } 71 } 5.定义TriggerInfo,扩展于Ext.data.Model
1 Ext.define("Vancl.Cxcp.TriggerInfo", { 2 extend: 'Ext.data.Model', 3 fields: ['Name', 'Group', 'JobName', 'JobGroup', 'TriggerType', 'StartTimeUtc', 'PreviousFireTimeUtc', 'NextFireTimeUtc', 'MisfireInstruction', 'TriggerState'] 4 }); 6.出于方便,我直接利用了Ext的desktop,下面是用于显示所有Trigger信息的Grid
< |
请发表评论