示例#1
0
        private void ProcessTriggerListeners(quartz data)
        {
            if (data.triggerlistener != null)
            {
                // go through listeners
                foreach (triggerlistenerType lt in data.triggerlistener)
                {
                    Type listenerType = Type.GetType(lt.type);
                    if (listenerType == null)
                    {
                        throw new SchedulerConfigException("Unknown trigger listener type " + lt.type);
                    }
                    ITriggerListener listener = (ITriggerListener)ObjectUtils.InstantiateType(listenerType);
                    // set name of trigger with reflection, this might throw errors
                    NameValueCollection properties = new NameValueCollection();
                    properties.Add("Name", lt.name);

                    try
                    {
                        ObjectUtils.SetObjectProperties(listener, properties);
                    }
                    catch (Exception)
                    {
                        throw new SchedulerConfigException(string.Format("Could not set name for job listener of type '{0}', do you have public set method defined for property 'Name'?", lt.type));
                    }
                    AddTriggerListenerToSchedule(listener);
                }
            }
        }
示例#2
0
        protected internal virtual void ProcessInternal(string xml)
        {
            ClearValidationExceptions();

            scheduledJobs.Clear();
            jobsToSchedule.Clear();
            calsToSchedule.Clear();

            ValidateXmlIfNeeded(xml);

            // deserialize as object model
            XmlSerializer xs   = new XmlSerializer(typeof(quartz));
            quartz        data = (quartz)xs.Deserialize(new StringReader(xml));

            // process data

            // add calendars
            if (data.calendar != null)
            {
                foreach (calendarType ct in data.calendar)
                {
                    CalendarBundle c = CreateCalendarFromXmlObject(ct);
                    AddCalendarToSchedule(c);
                }
            }

            // add job scheduling bundles
            ProcessJobs(data);

            if (data.joblistener != null)
            {
                // go through listeners
                foreach (joblistenerType jt in data.joblistener)
                {
                    Type listenerType = Type.GetType(jt.type);
                    if (listenerType == null)
                    {
                        throw new SchedulerConfigException("Unknown job listener type " + jt.type);
                    }
                    IJobListener listener = (IJobListener)ObjectUtils.InstantiateType(listenerType);
                    // set name of trigger with reflection, this might throw errors
                    NameValueCollection properties = new NameValueCollection();
                    properties.Add("Name", jt.name);

                    try
                    {
                        ObjectUtils.SetObjectProperties(listener, properties);
                    }
                    catch (Exception)
                    {
                        throw new SchedulerConfigException(string.Format("Could not set name for job listener of type '{0}', do you have public set method defined for property 'Name'?", jt.type));
                    }
                    AddListenerToSchedule(listener);
                }
            }
            MaybeThrowValidationException();
        }
		private void ProcessTriggerListeners(quartz data)
		{
			if (data.triggerlistener != null)
			{
				// go through listeners
				foreach (triggerlistenerType lt in data.triggerlistener)
				{
					Type listenerType = Type.GetType(lt.type);
					if (listenerType == null)
					{
						throw new SchedulerConfigException("Unknown trigger listener type " + lt.type);
					}
					ITriggerListener listener = (ITriggerListener) ObjectUtils.InstantiateType(listenerType);
					// set name of trigger with reflection, this might throw errors
					NameValueCollection properties = new NameValueCollection();
					properties.Add("Name", lt.name);

					try
					{
						ObjectUtils.SetObjectProperties(listener, properties);
					}
					catch (Exception)
					{
						throw new SchedulerConfigException(string.Format("Could not set name for job listener of type '{0}', do you have public set method defined for property 'Name'?", lt.type));
					}
					AddTriggerListenerToSchedule(listener);
				}
			}
		}
	    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);
	        }
	    }
示例#5
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);
            }
        }