using System; using System.Collections.Generic; using System.Linq; using Quartz; using Quartz.Listener; using Quartz.Impl; using System.Text; namespace QMTask.Core { public class JobListener : IJobListener { public TaskServer MyTaskServer { get; set; } /// /// Get the name of the . /// public string Name { get; set; } /// /// Called by the when a /// is about to be executed (an associated /// has occured). ///

/// This method will not be invoked if the execution of the Job was vetoed /// by a . ///

///
/// public void JobToBeExecuted(IJobExecutionContext context) { try { if (MyTaskServer.MonitorInfos.ContainsKey(context.JobDetail.Key) == true) { MyTaskServer.MonitorInfos[context.JobDetail.Key].Running = true; } } catch (Exception ex) { QMFrameWork.Log.LogManager.LogHelper.Error( new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "更新监控信息", ErrorInfo = ex }); throw; } } /// /// Called by the when a /// was about to be executed (an associated /// has occured), but a vetoed it's /// execution. /// /// public void JobExecutionVetoed(IJobExecutionContext context) { } /// /// Called by the after a /// has been executed, and be for the associated 's /// method has been called. /// public void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException) { try { if (MyTaskServer.MonitorInfos.ContainsKey(context.JobDetail.Key) == true) { MonitorInfo monitor = MyTaskServer.MonitorInfos[context.JobDetail.Key]; if (jobException != null) { monitor.IsNormal = false; } else { monitor.IsNormal = true; } monitor.LastExecuteResult = context.Result.ToString(); monitor.LastExecuteTime = DateTime.Now; monitor.Running = false; MyTaskServer.MonitorInfos[context.JobDetail.Key] = monitor; //输出 MyTaskServer.OutputMonitor(monitor); } } catch (Exception ex) { //QMFrameWork.Log.LogManager.LogHelper.Error( // new QMFrameWork.Log.LogInfo { ClientIP = "localhost", UserName = "admin", Info = "更新监控信息", ErrorInfo = ex }); //throw; } } } }