private void UpdateTrigger(Trigger tobeFiredTrigger)
        {
            try
            {
                tobeFiredTrigger.TimesTriggered++;
                tobeFiredTrigger.PreviousFireTime = tobeFiredTrigger.NextFireTime;
                if (tobeFiredTrigger.RepeatCount != 0 && tobeFiredTrigger.TimesTriggered >= tobeFiredTrigger.RepeatCount)
                {
                    //关闭Trigger
                    log.Debug("Close Trigger:" + tobeFiredTrigger.Name);
                    tobeFiredTrigger.Status = CodeMaster.TriggerStatus.Close;
                    tobeFiredTrigger.NextFireTime = null;
                }
                else
                {
                    //设置下次运行时间
                    log.Debug("Set Trigger Next Start Time, Add:" + tobeFiredTrigger.Interval.ToString() + " " + tobeFiredTrigger.IntervalType);
                    DateTime dateTimeNow = DateTime.Now;
                    if (!tobeFiredTrigger.NextFireTime.HasValue)
                    {
                        tobeFiredTrigger.NextFireTime = dateTimeNow;
                    }
                    else
                    {
                        while (tobeFiredTrigger.NextFireTime.Value <= dateTimeNow)
                        {
                            double hoursInterval = Utility.DateTimeHelper.TimeTranfer(tobeFiredTrigger.Interval, tobeFiredTrigger.IntervalType, CodeMaster.TimeUnit.Hour);
                            tobeFiredTrigger.NextFireTime = tobeFiredTrigger.NextFireTime.Value.AddHours(hoursInterval);
                        }
                    }
                    log.Debug("Trigger Next Start Time is set as:" + tobeFiredTrigger.NextFireTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
                }

                genericMgr.ExecuteUpdateWithCustomQuery("update from Trigger set TimesTriggered = ?, PreviousFireTime = ?, NextFireTime = ?, Status = ? where Name = ?",
                        new object[] { tobeFiredTrigger.TimesTriggered, tobeFiredTrigger.PreviousFireTime, tobeFiredTrigger.NextFireTime, tobeFiredTrigger.Status, tobeFiredTrigger.Name });
            }
            catch (Exception ex)
            {
                log.Error("Error occur when update batch trigger.", ex);
            }
        }
 private void AfterJobRunSuccess(RunLog runLog, Trigger tobeFiredTrigger)
 {
     log.Info("Job run successful. JobCode:" + tobeFiredTrigger.JobDetail.Code + ", JobName:" + tobeFiredTrigger.JobDetail.Description);
     genericMgr.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ? where Id = ?",
         new object[] { DateTime.Now, CodeMaster.JobRunStatus.Success, runLog.Id });
     genericMgr.FlushSession();
 }
 private void AfterJobRunFail(RunLog runLog, Trigger tobeFiredTrigger, Exception ex)
 {
     try
     {
         log.Error("Job run failure. JobCode:" + tobeFiredTrigger.JobDetail.Code + ", JobName:" + tobeFiredTrigger.JobDetail.Description, ex);
         if (ex.Message != null && ex.Message.Length > 1000)
         {
             genericMgr.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ?, Message = ? where Id = ?",
                 new object[] { DateTime.Now, CodeMaster.JobRunStatus.Failure, ex.Message.Substring(0, 1000), runLog.Id });
         }
         else
         {
             genericMgr.ExecuteUpdateWithCustomQuery("update from RunLog set EndTime = ?, Status = ?, Message = ? where Id = ?",
                 new object[] { DateTime.Now, CodeMaster.JobRunStatus.Failure, ex.Message, runLog.Id });
         }
     }
     catch (Exception ex1)
     {
         log.Error(ex1.Message, ex1);
     }
 }
 private void BeforeJobRun(RunLog runLog, Trigger tobeFiredTrigger)
 {
     log.Info("Start run job. JobCode:" + tobeFiredTrigger.JobDetail.Code + ", JobName:" + tobeFiredTrigger.JobDetail.Description);
     runLog.JobCode = tobeFiredTrigger.JobDetail.Code;
     runLog.TriggerName = tobeFiredTrigger.Name;
     runLog.StartTime = DateTime.Now;
     runLog.Status = CodeMaster.JobRunStatus.InProcess;
     genericMgr.Create(runLog);
     genericMgr.FlushSession();
 }