Ejemplo n.º 1
0
        public async Task <JsonResult> GetAllJobs()
        {
            IList <QuartzOutput> models = new List <QuartzOutput>();
            var jobGroups = await StdSchedulerManager.GetJobGroupNames();

            foreach (string group in jobGroups)
            {
                var groupMatcher = GroupMatcher <JobKey> .GroupContains(group);

                var jobKeys = await StdSchedulerManager.GetJobKeys(groupMatcher);

                foreach (var jobKey in jobKeys)
                {
                    var detail = await StdSchedulerManager.GetJobDetail(jobKey);

                    var triggers = await StdSchedulerManager.GetTriggersOfJob(jobKey);

                    foreach (ITrigger trigger in triggers)
                    {
                        var model = new QuartzOutput
                        {
                            JobGroup       = group,
                            JobName        = jobKey.Name,
                            JobDescription = detail.Description,
                            TriggerState   = "Complete",
                            NamespaceName  = detail.JobType.Namespace,
                            ClassName      = detail.JobType.FullName
                        };
                        model.TriggerName  = trigger.Key.Name;
                        model.TriggerGroup = trigger.Key.Group;
                        model.TriggerType  = trigger.GetType().Name;
                        model.TriggerState = (await StdSchedulerManager.GetTriggerState(trigger.Key)).ToString();
                        var nextFireTime = trigger.GetNextFireTimeUtc();
                        if (nextFireTime.HasValue)
                        {
                            model.NextFireTime = TimeZone.CurrentTimeZone.ToLocalTime(nextFireTime.Value.DateTime);
                        }

                        var previousFireTime = trigger.GetPreviousFireTimeUtc();
                        if (previousFireTime.HasValue)
                        {
                            model.PreviousFireTime =
                                TimeZone.CurrentTimeZone.ToLocalTime(previousFireTime.Value.DateTime);
                        }
                        models.Add(model);
                    }
                }
            }
            return(JsonForGridLoadOnce(models.OrderBy(o => o.NextFireTime)));
        }