示例#1
0
 private static void OnCronTrigger(CronObject cronobject)
 {
     using (var workspace = WorkspaceFactory.Create())
     {
         var trigger = workspace.Single<Trigger>(x => x.Id == ((Trigger)cronobject.Object).Id);
         if (trigger != null)
         {
             trigger.LastTrigger = DateTime.Now;
             workspace.CommitChanges();
             if (AppServices.ActiveAppScreen != AppScreens.Dashboard)
                 RuleExecutor.NotifyEvent(RuleEventNames.TriggerExecuted, new { TriggerName = trigger.Name });
         }
         else cronobject.Stop();
     }
 }
示例#2
0
        public void UpdateCronObjects()
        {
            CloseTriggers();

            var triggers = Dao.Query<Trigger>();
            foreach (var trigger in triggers)
            {
                var dataContext = new CronObjectDataContext(new List<CronSchedule> { CronSchedule.Parse(trigger.Expression) })
                    {
                        Object = trigger,
                        LastTrigger = trigger.LastTrigger
                    };

                var cronObject = new CronObject(dataContext);
                cronObject.OnCronTrigger += OnCronTrigger;
                _cronObjects.Add(cronObject);
            }
            _cronObjects.ForEach(x => x.Start());
        }