From 3812838bb5cd6c75d8f07bd5c22ae2e30f50b15a Mon Sep 17 00:00:00 2001 From: Jay Vilalta Date: Mon, 1 Nov 2010 17:44:49 -0500 Subject: [PATCH] clean up the code, add some exception handling --- ClickForensics.Quartz.Manager/AddJobForm.cs | 2 +- .../ClickForensics.Quartz.Manager.csproj | 3 +- .../JobAssemblies.txt | 3 +- .../MainForm.Designer.cs | 73 ++++++------------- ClickForensics.Quartz.Manager/MainForm.cs | 40 +--------- .../QuartzScheduler.cs | 19 +++-- 6 files changed, 41 insertions(+), 99 deletions(-) diff --git a/ClickForensics.Quartz.Manager/AddJobForm.cs b/ClickForensics.Quartz.Manager/AddJobForm.cs index f5f7b07..ff52468 100644 --- a/ClickForensics.Quartz.Manager/AddJobForm.cs +++ b/ClickForensics.Quartz.Manager/AddJobForm.cs @@ -39,7 +39,7 @@ namespace ClickForensics.Quartz.Manager Assembly assembly = Assembly.LoadFile(Environment.CurrentDirectory + "\\" + line); foreach (Type type in assembly.GetTypes()) { - if (typeof(IJob).IsAssignableFrom(type)) + if (typeof(IJob).IsAssignableFrom(type) && type.IsClass) { jobTypes.Add(type.FullName, assembly.GetName().Name); } diff --git a/ClickForensics.Quartz.Manager/ClickForensics.Quartz.Manager.csproj b/ClickForensics.Quartz.Manager/ClickForensics.Quartz.Manager.csproj index e3b502f..cc36f3e 100644 --- a/ClickForensics.Quartz.Manager/ClickForensics.Quartz.Manager.csproj +++ b/ClickForensics.Quartz.Manager/ClickForensics.Quartz.Manager.csproj @@ -54,8 +54,7 @@ ..\lib\Common.Logging.dll - - False + ..\lib\Quartz.dll diff --git a/ClickForensics.Quartz.Manager/JobAssemblies.txt b/ClickForensics.Quartz.Manager/JobAssemblies.txt index f0d1c3a..55cbc27 100644 --- a/ClickForensics.Quartz.Manager/JobAssemblies.txt +++ b/ClickForensics.Quartz.Manager/JobAssemblies.txt @@ -1,2 +1 @@ -ClickForensics.Quartz.Jobs.dll -Quartz.dll \ No newline at end of file +Quartz.dll \ No newline at end of file diff --git a/ClickForensics.Quartz.Manager/MainForm.Designer.cs b/ClickForensics.Quartz.Manager/MainForm.Designer.cs index a3ba07c..c93ba3a 100644 --- a/ClickForensics.Quartz.Manager/MainForm.Designer.cs +++ b/ClickForensics.Quartz.Manager/MainForm.Designer.cs @@ -32,7 +32,6 @@ this.mainMenuStrip = new System.Windows.Forms.MenuStrip(); this.schedulerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.connectToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.configureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.jobsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addJobToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listenersStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -40,8 +39,6 @@ this.addGlobalJobListenerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addTriggerListenerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.addJobListenerToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.deleteThemAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.serverConnectStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.StripStatusLabel_Job_Groups = new System.Windows.Forms.ToolStripStatusLabel(); @@ -77,8 +74,7 @@ this.mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.schedulerToolStripMenuItem, this.jobsToolStripMenuItem, - this.listenersStripMenuItem, - this.toolStripMenuItem1}); + this.listenersStripMenuItem}); this.mainMenuStrip.Location = new System.Drawing.Point(0, 0); this.mainMenuStrip.Name = "mainMenuStrip"; this.mainMenuStrip.Size = new System.Drawing.Size(913, 24); @@ -88,8 +84,7 @@ // schedulerToolStripMenuItem // this.schedulerToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.connectToolStripMenuItem, - this.configureToolStripMenuItem}); + this.connectToolStripMenuItem}); this.schedulerToolStripMenuItem.Name = "schedulerToolStripMenuItem"; this.schedulerToolStripMenuItem.Size = new System.Drawing.Size(71, 20); this.schedulerToolStripMenuItem.Text = "Scheduler"; @@ -97,17 +92,10 @@ // connectToolStripMenuItem // this.connectToolStripMenuItem.Name = "connectToolStripMenuItem"; - this.connectToolStripMenuItem.Size = new System.Drawing.Size(127, 22); + this.connectToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.connectToolStripMenuItem.Text = "Connect"; this.connectToolStripMenuItem.Click += new System.EventHandler(this.connectToolStripMenuItem_Click); // - // configureToolStripMenuItem - // - this.configureToolStripMenuItem.Name = "configureToolStripMenuItem"; - this.configureToolStripMenuItem.Size = new System.Drawing.Size(127, 22); - this.configureToolStripMenuItem.Text = "Configure"; - this.configureToolStripMenuItem.Click += new System.EventHandler(this.configureToolStripMenuItem_Click); - // // jobsToolStripMenuItem // this.jobsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -163,21 +151,6 @@ this.addJobListenerToolStripMenuItem.Text = "Add Job Listener"; this.addJobListenerToolStripMenuItem.Click += new System.EventHandler(this.addJobListenerToolStripMenuItem_Click); // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.deleteThemAllToolStripMenuItem}); - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); - this.toolStripMenuItem1.Text = "Miscellaneous"; - // - // deleteThemAllToolStripMenuItem - // - this.deleteThemAllToolStripMenuItem.Name = "deleteThemAllToolStripMenuItem"; - this.deleteThemAllToolStripMenuItem.Size = new System.Drawing.Size(152, 22); - this.deleteThemAllToolStripMenuItem.Text = "DeleteThemAll"; - this.deleteThemAllToolStripMenuItem.Click += new System.EventHandler(this.deleteThemAllToolStripMenuItem_Click); - // // statusStrip1 // this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -261,7 +234,7 @@ // btnDeleteJob // this.btnDeleteJob.Enabled = false; - this.btnDeleteJob.Location = new System.Drawing.Point(665, 309); + this.btnDeleteJob.Location = new System.Drawing.Point(533, 306); this.btnDeleteJob.Name = "btnDeleteJob"; this.btnDeleteJob.Size = new System.Drawing.Size(65, 23); this.btnDeleteJob.TabIndex = 8; @@ -272,7 +245,7 @@ // btnRunJobNow // this.btnRunJobNow.Enabled = false; - this.btnRunJobNow.Location = new System.Drawing.Point(523, 309); + this.btnRunJobNow.Location = new System.Drawing.Point(391, 306); this.btnRunJobNow.Name = "btnRunJobNow"; this.btnRunJobNow.Size = new System.Drawing.Size(65, 23); this.btnRunJobNow.TabIndex = 9; @@ -283,7 +256,7 @@ // btnPause // this.btnPause.Enabled = false; - this.btnPause.Location = new System.Drawing.Point(594, 309); + this.btnPause.Location = new System.Drawing.Point(462, 306); this.btnPause.Name = "btnPause"; this.btnPause.Size = new System.Drawing.Size(65, 23); this.btnPause.TabIndex = 10; @@ -294,7 +267,7 @@ // pnlDetails // this.pnlDetails.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pnlDetails.Location = new System.Drawing.Point(523, 48); + this.pnlDetails.Location = new System.Drawing.Point(391, 45); this.pnlDetails.Name = "pnlDetails"; this.pnlDetails.Size = new System.Drawing.Size(342, 252); this.pnlDetails.TabIndex = 11; @@ -302,7 +275,7 @@ // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(520, 32); + this.label3.Location = new System.Drawing.Point(388, 29); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(39, 13); this.label3.TabIndex = 12; @@ -311,7 +284,7 @@ // btnEdit // this.btnEdit.Enabled = false; - this.btnEdit.Location = new System.Drawing.Point(736, 309); + this.btnEdit.Location = new System.Drawing.Point(604, 306); this.btnEdit.Name = "btnEdit"; this.btnEdit.Size = new System.Drawing.Size(65, 23); this.btnEdit.TabIndex = 13; @@ -344,14 +317,13 @@ this.listView_RunningJobs.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.JobName, this.JobDuration}); - this.listView_RunningJobs.Location = new System.Drawing.Point(11, 335); + this.listView_RunningJobs.Location = new System.Drawing.Point(8, 335); this.listView_RunningJobs.Name = "listView_RunningJobs"; - this.listView_RunningJobs.Size = new System.Drawing.Size(719, 268); + this.listView_RunningJobs.Size = new System.Drawing.Size(725, 268); this.listView_RunningJobs.Sorting = System.Windows.Forms.SortOrder.Ascending; this.listView_RunningJobs.TabIndex = 14; this.listView_RunningJobs.UseCompatibleStateImageBehavior = false; this.listView_RunningJobs.View = System.Windows.Forms.View.Details; - this.listView_RunningJobs.SelectedIndexChanged += new System.EventHandler(this.listView_RunningJobs_SelectedIndexChanged); // // JobName // @@ -364,7 +336,7 @@ // button1 // this.button1.Enabled = false; - this.button1.Location = new System.Drawing.Point(665, 309); + this.button1.Location = new System.Drawing.Point(533, 306); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(65, 23); this.button1.TabIndex = 8; @@ -375,7 +347,7 @@ // button2 // this.button2.Enabled = false; - this.button2.Location = new System.Drawing.Point(523, 309); + this.button2.Location = new System.Drawing.Point(391, 306); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(65, 23); this.button2.TabIndex = 9; @@ -386,7 +358,7 @@ // button3 // this.button3.Enabled = false; - this.button3.Location = new System.Drawing.Point(594, 309); + this.button3.Location = new System.Drawing.Point(462, 306); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(65, 23); this.button3.TabIndex = 10; @@ -397,7 +369,7 @@ // button4 // this.button4.Enabled = false; - this.button4.Location = new System.Drawing.Point(736, 309); + this.button4.Location = new System.Drawing.Point(604, 306); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(65, 23); this.button4.TabIndex = 13; @@ -410,24 +382,24 @@ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(913, 661); + this.Controls.Add(this.btnRefreshJobGroups); this.Controls.Add(this.listView_RunningJobs); this.Controls.Add(this.pnlDetails); this.Controls.Add(this.label3); - this.Controls.Add(this.btnRefreshJobGroups); + this.Controls.Add(this.label1); this.Controls.Add(this.button4); this.Controls.Add(this.btnEdit); - this.Controls.Add(this.label1); + this.Controls.Add(this.btnRefreshRunningJobs); this.Controls.Add(this.button3); this.Controls.Add(this.btnPause); - this.Controls.Add(this.btnRefreshRunningJobs); this.Controls.Add(this.label2); - this.Controls.Add(this.button2); this.Controls.Add(this.statusStrip1); - this.Controls.Add(this.btnRunJobNow); + this.Controls.Add(this.button2); this.Controls.Add(this.mainMenuStrip); + this.Controls.Add(this.btnRunJobNow); + this.Controls.Add(this.jobGroupsTreeView); this.Controls.Add(this.button1); this.Controls.Add(this.btnDeleteJob); - this.Controls.Add(this.jobGroupsTreeView); this.MainMenuStrip = this.mainMenuStrip; this.Name = "MainForm"; this.Text = "Quartz Manager"; @@ -463,12 +435,9 @@ private System.Windows.Forms.Button btnDeleteJob; private System.Windows.Forms.Button btnRunJobNow; private System.Windows.Forms.Button btnPause; - private System.Windows.Forms.ToolStripMenuItem configureToolStripMenuItem; private System.Windows.Forms.Panel pnlDetails; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button btnEdit; - private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; - private System.Windows.Forms.ToolStripMenuItem deleteThemAllToolStripMenuItem; private System.Windows.Forms.ContextMenuStrip ctxScheduler; private System.Windows.Forms.ToolStripMenuItem backupToolStripMenuItem; private System.Windows.Forms.Timer timer_Refresh_Running_Jobs; diff --git a/ClickForensics.Quartz.Manager/MainForm.cs b/ClickForensics.Quartz.Manager/MainForm.cs index a97170a..42682c9 100644 --- a/ClickForensics.Quartz.Manager/MainForm.cs +++ b/ClickForensics.Quartz.Manager/MainForm.cs @@ -144,7 +144,7 @@ namespace ClickForensics.Quartz.Manager jobGroupsTreeView.Nodes[0].Expand(); jobGroupsNode.Expand(); - StripStatusLabel_Job_Groups.Text = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm.ss"); + StripStatusLabel_Job_Groups.Text = DateTime.Now.ToString("yyyy.MM.dd HH:mm.ss"); } finally @@ -155,7 +155,7 @@ namespace ClickForensics.Quartz.Manager } - private void jobDetailsToggle(System.Boolean isVisible) + private void jobDetailsToggle(bool isVisible) { if (isVisible == false) { @@ -241,10 +241,10 @@ namespace ClickForensics.Quartz.Manager foreach (DataRow row in table.Rows) { //JobName JobDuration - ListViewItem item = new ListViewItem(new string[] { System.Convert.ToString(row["JobName"]), System.Convert.ToString(row["Runtime"]) }); + ListViewItem item = new ListViewItem(new string[] { Convert.ToString(row["JobName"]), Convert.ToString(row["Runtime"]) }); listView_RunningJobs.Items.Add(item); } - StripStatusLabel_Jobs_Refresh_date.Text = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm.ss"); + StripStatusLabel_Jobs_Refresh_date.Text = DateTime.Now.ToString("yyyy.MM.dd HH:mm.ss"); //reset the timer ( documentation not clear if .stop = restart @ 0 in timing, but changing the interval sure should do that. ) @@ -351,16 +351,6 @@ namespace ClickForensics.Quartz.Manager setPauseButtonText(); } - private void assembliesToolStripMenuItem_Click(object sender, EventArgs e) - { - - } - - private void configureToolStripMenuItem_Click(object sender, EventArgs e) - { - - } - private void btnEdit_Click(object sender, EventArgs e) { TriggerNode node = (TriggerNode)jobGroupsTreeView.SelectedNode; @@ -373,18 +363,6 @@ namespace ClickForensics.Quartz.Manager } } - private void deleteThemAllToolStripMenuItem_Click(object sender, EventArgs e) - { - foreach (var job in Scheduler.GetScheduler().GetJobNames("Cube")) - { - if (job.Contains("CreateCubeFor")) - { - - Scheduler.GetScheduler().DeleteJob(job, "Cube"); - } - } - } - private void backupToolStripMenuItem_Click(object sender, EventArgs e) { QuartzScheduler scheduler = ((SchedulerNode)((TreeView)((ContextMenuStrip)((ToolStripMenuItem)sender).Owner).SourceControl).SelectedNode).Scheduler; @@ -398,15 +376,5 @@ namespace ClickForensics.Quartz.Manager { updateRunningJobs(); } - - private void runningJobsListView_SelectedIndexChanged(object sender, EventArgs e) - { - - } - - private void listView_RunningJobs_SelectedIndexChanged(object sender, EventArgs e) - { - - } } } diff --git a/ClickForensics.Quartz.Manager/QuartzScheduler.cs b/ClickForensics.Quartz.Manager/QuartzScheduler.cs index 51450f1..561e9ca 100644 --- a/ClickForensics.Quartz.Manager/QuartzScheduler.cs +++ b/ClickForensics.Quartz.Manager/QuartzScheduler.cs @@ -123,13 +123,20 @@ namespace ClickForensics.Quartz.Manager DataTable table = new DataTable(); table.Columns.Add("JobName", typeof(string)); table.Columns.Add("RunTime", typeof(int)); - IList jobs = GetScheduler().GetCurrentlyExecutingJobs(); - foreach (JobExecutionContext context in jobs) + try + { + IList jobs = GetScheduler().GetCurrentlyExecutingJobs(); + foreach (JobExecutionContext context in jobs) + { + DataRow row = table.NewRow(); + row["JobName"] = context.JobDetail.Name; + row["RunTime"] = (DateTime.Now.ToUniversalTime() - (DateTime)context.FireTimeUtc).TotalMinutes; + table.Rows.Add(row); + } + } + catch (Exception ex) { - DataRow row = table.NewRow(); - row["JobName"] = context.JobDetail.Name; - row["RunTime"] = (DateTime.Now.ToUniversalTime() - (DateTime)context.FireTimeUtc).TotalMinutes; - table.Rows.Add(row); + //TODO: Let the user know we couldn't load the running jobs. } return table;