private void ProcessJobs(quartz data)
	    {
            if (data.job == null)
            {
                // no jobs to process, file is empty
                return;
            }

	        foreach (jobType jt in data.job)
	        {
	            JobSchedulingBundle jsb = new JobSchedulingBundle();
	            jobdetailType j = jt.jobdetail;
	            Type jobType = Type.GetType(j.jobtype);
                if (jobType == null)
                {
                    throw new SchedulerConfigException("Unknown job type " + j.jobtype);
                }

	            JobDetail jd = new JobDetail(j.name, j.group, jobType, j.@volatile, j.durable, j.recover);
	            jd.Description = j.description;

                if (j.joblistenerref != null && j.joblistenerref.Trim().Length > 0)
                {
                    jd.AddJobListener(j.joblistenerref);
                }
                
                jsb.JobDetail = jd;

                // read job data map
                if (j.jobdatamap != null && j.jobdatamap.entry != null)
                {
                    foreach (entryType entry in j.jobdatamap.entry)
                    {
                        jd.JobDataMap.Put(entry.key, entry.value);
                    }
                }

	            triggerType[] tArr = jt.trigger;
                if (tArr == null)
                {
                    // set to empty
                    tArr = new triggerType[0];
                }
	            foreach (triggerType t in tArr)
	            {
	                Trigger trigger;
	                if (t.Item is cronType)
	                {
	                    cronType c = (cronType) t.Item;

                        DateTime startTime = (c.starttime == DateTime.MinValue ? DateTime.UtcNow : c.starttime);
                        NullableDateTime endTime = (c.endtime == DateTime.MinValue ? null : (NullableDateTime)c.endtime);

	                    string jobName = c.jobname != null ? c.jobname : j.name;
	                    string jobGroup = c.jobgroup != null ? c.jobgroup : j.group;

                        CronTrigger ct = new CronTrigger(
                            c.name,
                            c.group,
                            jobName,
                            jobGroup,
                            startTime,
                            endTime,
                            c.cronexpression);

	                    if (c.timezone != null && c.timezone.Trim().Length > 0)
	                    {
#if NET_35
                            ct.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(c.timezone);
#else
	                        throw new ArgumentException(
	                            "Specifying time zone for cron trigger is only supported in .NET 3.5 builds");
#endif
	                    }
	                    trigger = ct;
	                }
	                else if (t.Item is simpleType)
	                {
	                    simpleType s = (simpleType) t.Item;
	                    
	                    DateTime startTime = (s.starttime == DateTime.MinValue ? DateTime.UtcNow : s.starttime);
                        NullableDateTime endTime = (s.endtime == DateTime.MinValue ? null : (NullableDateTime)s.endtime);

                        string jobName = s.jobname != null ? s.jobname : j.name;
                        string jobGroup = s.jobgroup != null ? s.jobgroup : j.group;

                        SimpleTrigger st = new SimpleTrigger(
                            s.name, 
                            s.group, 
                            jobName, 
                            jobGroup,
                            startTime, 
                            endTime, 
                            ParseSimpleTriggerRepeatCount(s.repeatcount), 
                            TimeSpan.FromMilliseconds(Convert.ToInt64(s.repeatinterval, CultureInfo.InvariantCulture)));

	                    trigger = st;
	                }
	                else
	                {
	                    throw new ArgumentException("Unknown trigger type in XML");
	                }

                    trigger.Description = t.Item.description;
	                trigger.CalendarName = t.Item.calendarname;
                    
                    if (t.Item.misfireinstruction != null)
                    {
                        trigger.MisfireInstruction = ReadMisfireInstructionFromString(t.Item.misfireinstruction);
                    }
                    if (t.Item.jobdatamap != null && t.Item.jobdatamap.entry != null)
                    {
                        foreach (entryType entry in t.Item.jobdatamap.entry)
                        {
                            if (trigger.JobDataMap.Contains(entry.key))
                            {
                                Log.Warn("Overriding key '" + entry.key + "' with another value in same trigger job data map");
                            }
                            trigger.JobDataMap[entry.key] = entry.value;
                        }
                    }
					if (t.Item.triggerlistenerref != null && t.Item.triggerlistenerref.Trim().Length > 0)
					{
						trigger.AddTriggerListener(t.Item.triggerlistenerref);
					}
					
	                jsb.Triggers.Add(trigger);
	            }

	            AddJobToSchedule(jsb);
	        }
	    }
Ejemplo n.º 2
0
        private void ProcessJobs(quartz data)
        {
            if (data.job == null)
            {
                // no jobs to process, file is empty
                return;
            }

            foreach (jobType jt in data.job)
            {
                JobSchedulingBundle jsb = new JobSchedulingBundle();
                jobdetailType       j   = jt.jobdetail;
                Type jobType            = Type.GetType(j.jobtype);
                if (jobType == null)
                {
                    throw new SchedulerConfigException("Unknown job type " + j.jobtype);
                }

                JobDetail jd = new JobDetail(j.name, j.group, jobType, j.@volatile, j.durable, j.recover);
                jd.Description = j.description;

                if (j.joblistenerref != null && j.joblistenerref.Trim().Length > 0)
                {
                    jd.AddJobListener(j.joblistenerref);
                }

                jsb.JobDetail = jd;

                // read job data map
                if (j.jobdatamap != null && j.jobdatamap.entry != null)
                {
                    foreach (entryType entry in j.jobdatamap.entry)
                    {
                        jd.JobDataMap.Put(entry.key, entry.value);
                    }
                }

                triggerType[] tArr = jt.trigger;
                if (tArr == null)
                {
                    // set to empty
                    tArr = new triggerType[0];
                }
                foreach (triggerType t in tArr)
                {
                    Trigger trigger;
                    if (t.Item is cronType)
                    {
                        cronType c = (cronType)t.Item;

                        DateTime         startTime = (c.starttime == DateTime.MinValue ? DateTime.UtcNow : c.starttime);
                        NullableDateTime endTime   = (c.endtime == DateTime.MinValue ? null : (NullableDateTime)c.endtime);

                        string jobName  = c.jobname != null ? c.jobname : j.name;
                        string jobGroup = c.jobgroup != null ? c.jobgroup : j.group;

                        CronTrigger ct = new CronTrigger(
                            c.name,
                            c.group,
                            jobName,
                            jobGroup,
                            startTime,
                            endTime,
                            c.cronexpression);

                        if (c.timezone != null && c.timezone.Trim().Length > 0)
                        {
#if NET_35
                            ct.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(c.timezone);
#else
                            throw new ArgumentException(
                                      "Specifying time zone for cron trigger is only supported in .NET 3.5 builds");
#endif
                        }
                        trigger = ct;
                    }
                    else if (t.Item is simpleType)
                    {
                        simpleType s = (simpleType)t.Item;

                        DateTime         startTime = (s.starttime == DateTime.MinValue ? DateTime.UtcNow : s.starttime);
                        NullableDateTime endTime   = (s.endtime == DateTime.MinValue ? null : (NullableDateTime)s.endtime);

                        string jobName  = s.jobname != null ? s.jobname : j.name;
                        string jobGroup = s.jobgroup != null ? s.jobgroup : j.group;

                        SimpleTrigger st = new SimpleTrigger(
                            s.name,
                            s.group,
                            jobName,
                            jobGroup,
                            startTime,
                            endTime,
                            ParseSimpleTriggerRepeatCount(s.repeatcount),
                            TimeSpan.FromMilliseconds(Convert.ToInt64(s.repeatinterval, CultureInfo.InvariantCulture)));

                        trigger = st;
                    }
                    else
                    {
                        throw new ArgumentException("Unknown trigger type in XML");
                    }

                    trigger.Description  = t.Item.description;
                    trigger.CalendarName = t.Item.calendarname;

                    if (t.Item.misfireinstruction != null)
                    {
                        trigger.MisfireInstruction = ReadMisfireInstructionFromString(t.Item.misfireinstruction);
                    }
                    if (t.Item.jobdatamap != null && t.Item.jobdatamap.entry != null)
                    {
                        foreach (entryType entry in t.Item.jobdatamap.entry)
                        {
                            if (trigger.JobDataMap.Contains(entry.key))
                            {
                                Log.Warn("Overriding key '" + entry.key + "' with another value in same trigger job data map");
                            }
                            trigger.JobDataMap[entry.key] = entry.value;
                        }
                    }
                    if (t.Item.triggerlistenerref != null && t.Item.triggerlistenerref.Trim().Length > 0)
                    {
                        trigger.AddTriggerListener(t.Item.triggerlistenerref);
                    }

                    jsb.Triggers.Add(trigger);
                }

                AddJobToSchedule(jsb);
            }
        }