Asp.Net MVC 3 + ExtJs 4.01做一个Quartz.Net管理平台
在原来的公司曾经用asp.net + extjs 2做过一个Quartz.Net简单管理平台(后来申请了著作权,尽然也可以),随着Asp.Net MVC 3和ExtJs 4的发布,突然有了重新用Asp.Net MVC 3 + ExtJs 4重新做一下的冲动(冲动是魔鬼呀。。。)。本次只实现了显示触发器Trigger的信息。
效果图:
1.定义TriggerInfo,这里为了方便起见只列出了TriggerInfo的定义
View Code
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 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
View Code
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 }
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的信息
View Code
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 }
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 });
2 extend: 'Ext.data.Model',
3 fields: ['Name', 'Group', 'JobName', 'JobGroup', 'TriggerType', 'StartTimeUtc', 'PreviousFireTimeUtc', 'NextFireTimeUtc', 'MisfireInstruction', 'TriggerState']
4 });
6.出于方便,我直接利用了Ext的desktop,下面是用于显示所有Trigger信息的Grid
1 Ext.define('MyDesktop.GridWindow', {
2 extend: 'Ext.ux.desktop.Module',
3
4 requires: [
5 'Ext.data.*',
6 'Ext.util.Format',
7 'Ext.grid.Panel',
8 'Ext.grid.RowNumberer'
9 ],
10
11 id: 'grid-win',
12
13 init: function () {
14 this.launcher = {
15 text: 'Grid Window',
16 iconCls: 'icon-grid',
17 handler: this.createWindow,
18 scope: this
19 };
20 },
21
22 createWindow: function () {
23 var desktop = this.app.getDesktop();
24 var win = desktop.getWindow('grid-win');
25 var store = new Ext.data.Store({
26 model: 'Vancl.Cxcp.TriggerInfo',
27 proxy: {
28 type: 'ajax',
29 url: 'schedule/gettriggers',
30 reader: {
31 type: 'json',
32 root: ''
33 }
34 }
35 });
36 if (!win) {
37 win = desktop.createWindow({
38 id: 'grid-win',
39 title: '触发器信息',
40 width: 740,
41 height: 480,
42 iconCls: 'icon-grid',
43 animCollapse: false,
44 constrainHeader: true,
45 layout: 'fit',
46 items: [
47 {
48 border: false,
49 xtype: 'grid',
50 store: store,
51 columns: [{
52 text: 'Name',
53 dataIndex: 'Name'
54 }, {
55 text: 'Group',
56 dataIndex: 'Group'
57 }, {
58 text: 'JobName',
59 dataIndex: 'JobName'
60 }, {
61 text: 'JobGroup',
62 dataIndex: 'JobGroup'
63 }, {
64 text: 'TriggerType',
65 dataIndex: 'TriggerType'
66 }, {
67 text: 'StartTimeUtc',
68 dataIndex: 'StartTimeUtc'
69 }, {
70 text: 'PreviousFireTimeUtc',
71 dataIndex: 'PreviousFireTimeUtc'
72 }, {
73 text: 'NextFireTimeUtc',
74 dataIndex: 'NextFireTimeUtc'
75 }, {
76 text: 'MisfireInstruction',
77 dataIndex: 'MisfireInstruction'
78 }, {
79 text: 'TriggerState',
80 dataIndex: 'TriggerState'
81 }]
82 }
83 ],
84 tbar: [{
85 text: 'Add',
86 tooltip: 'Add a new trigger',
87 iconCls: 'add'
88 }, '-', {
89 text: 'Remove Trigger',
90 tooltip: 'Remove the selected trigger',
91 iconCls: 'remove'
92 }]
93 });
94 }
95 win.show();
96 store.load();
97
98 return win;
99 }
100 });
2 extend: 'Ext.ux.desktop.Module',
3
4 requires: [
5 'Ext.data.*',
6 'Ext.util.Format',
7 'Ext.grid.Panel',
8 'Ext.grid.RowNumberer'
9 ],
10
11 id: 'grid-win',
12
13 init: function () {
14 this.launcher = {
15 text: 'Grid Window',
16 iconCls: 'icon-grid',
17 handler: this.createWindow,
18 scope: this
19 };
20 },
21
22 createWindow: function () {
23 var desktop = this.app.getDesktop();
24 var win = desktop.getWindow('grid-win');
25 var store = new Ext.data.Store({
26 model: 'Vancl.Cxcp.TriggerInfo',
27 proxy: {
28 type: 'ajax',
29 url: 'schedule/gettriggers',
30 reader: {
31 type: 'json',
32 root: ''
33 }
34 }
35 });
36 if (!win) {
37 win = desktop.createWindow({
38 id: 'grid-win',
39 title: '触发器信息',
40 width: 740,
41 height: 480,
42 iconCls: 'icon-grid',
43 animCollapse: false,
44 constrainHeader: true,
45 layout: 'fit',
46 items: [
47 {
48 border: false,
49 xtype: 'grid',
50 store: store,
51 columns: [{
52 text: 'Name',
53 dataIndex: 'Name'
54 }, {
55 text: 'Group',
56 dataIndex: 'Group'
57 }, {
58 text: 'JobName',
59 dataIndex: 'JobName'
60 }, {
61 text: 'JobGroup',
62 dataIndex: 'JobGroup'
63 }, {
64 text: 'TriggerType',
65 dataIndex: 'TriggerType'
66 }, {
67 text: 'StartTimeUtc',
68 dataIndex: 'StartTimeUtc'
69 }, {
70 text: 'PreviousFireTimeUtc',
71 dataIndex: 'PreviousFireTimeUtc'
72 }, {
73 text: 'NextFireTimeUtc',
74 dataIndex: 'NextFireTimeUtc'
75 }, {
76 text: 'MisfireInstruction',
77 dataIndex: 'MisfireInstruction'
78 }, {
79 text: 'TriggerState',
80 dataIndex: 'TriggerState'
81 }]
82 }
83 ],
84 tbar: [{
85 text: 'Add',
86 tooltip: 'Add a new trigger',
87 iconCls: 'add'
88 }, '-', {
89 text: 'Remove Trigger',
90 tooltip: 'Remove the selected trigger',
91 iconCls: 'remove'
92 }]
93 });
94 }
95 win.show();
96 store.load();
97
98 return win;
99 }
100 });
从以上示例可以看出,ExtJs 4相对于ExtJs 2/3已经有了很大的变化。比如 data model,对于对象的定义更加简单明了。