/// <summary>
		/// Adds a scheduled job.
		/// </summary>
		/// <param name="job">The job.</param>
		protected virtual void AddScheduledJob(JobSchedulingBundle job)
		{
			scheduledJobs[job.FullName] = job;
		}
		public virtual void AddJobToSchedule(JobSchedulingBundle job)
		{
			jobsToSchedule.Add(job);
		}
		/// <summary>
		/// Schedules a given job and trigger (both wrapped by a <see cref="JobSchedulingBundle" />).
		/// </summary>
		/// <param name="job">The job.</param>
		/// <param name="sched">The sched.</param>
		/// <param name="localOverWriteExistingJobs">if set to <c>true</c> [local over write existing jobs].</param>
		/// <exception cref="SchedulerException"> 
		/// if the Job or Trigger cannot be added to the Scheduler, or
		/// there is an internal Scheduler error.
		/// </exception>
		public virtual void ScheduleJob(JobSchedulingBundle job, IScheduler sched, bool localOverWriteExistingJobs)
		{
			if ((job != null) && job.Valid)
			{
				JobDetail detail = job.JobDetail;

				JobDetail dupeJ = sched.GetJobDetail(detail.Name, detail.Group);

				if ((dupeJ != null) && !localOverWriteExistingJobs)
				{
					Log.Info("Not overwriting existing job: " + dupeJ.FullName);
					return;
				}

				if (dupeJ != null)
				{
					Log.Info(string.Format(CultureInfo.InvariantCulture, "Replacing job: {0}", detail.FullName));
				}
				else
				{
					Log.Info(string.Format(CultureInfo.InvariantCulture, "Adding job: {0}", detail.FullName));
				}

				if (job.Triggers.Count == 0 && !job.JobDetail.Durable)
				{
					throw new SchedulerException("A Job defined without any triggers must be durable");
				}
				
				sched.AddJob(detail, true);

					
				foreach(Trigger trigger in job.Triggers)
				{
					Trigger dupeT = sched.GetTrigger(trigger.Name, trigger.Group);

					trigger.JobName = detail.Name;
					trigger.JobGroup = detail.Group;

					if (trigger.StartTimeUtc == DateTime.MinValue)
					{
						trigger.StartTimeUtc = DateTime.UtcNow;
					}

					if (dupeT != null)
					{
						Log.Debug(string.Format(CultureInfo.InvariantCulture, "Rescheduling job: {0} with updated trigger: {1}", detail.FullName, trigger.FullName));
						if (!dupeT.JobGroup.Equals(trigger.JobGroup) || !dupeT.JobName.Equals(trigger.JobName))
						{
							Log.Warn("Possibly duplicately named triggers in jobs xml file!");
						}
						sched.RescheduleJob(trigger.Name, trigger.Group, trigger);
					}
					else
					{
						Log.Debug(string.Format(CultureInfo.InvariantCulture, "Scheduling job: {0} with trigger: {1}", detail.FullName, trigger.FullName));
						sched.ScheduleJob(trigger);
					}
				}

				AddScheduledJob(job);
			}
		}
	    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);
	        }
	    }
		/// <summary>
		/// Schedules a given job and trigger (both wrapped by a <see cref="JobSchedulingBundle" />).
		/// </summary>
		/// <param name="job">job wrapper.</param>
		/// <exception cref="SchedulerException">
		/// if the Job or Trigger cannot be added to the Scheduler, or
		/// there is an internal Scheduler error.
		/// </exception>
		public virtual void ScheduleJob(JobSchedulingBundle job)
		{
			ScheduleJob(job, (IScheduler) LogicalThreadContext.GetData(ThreadLocalKeyScheduler), OverwriteExistingJobs);
		}
Ejemplo n.º 6
0
 /// <summary>
 /// Adds a scheduled job.
 /// </summary>
 /// <param name="job">The job.</param>
 protected virtual void AddScheduledJob(JobSchedulingBundle job)
 {
     scheduledJobs[job.FullName] = job;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Schedules a given job and trigger (both wrapped by a <see cref="JobSchedulingBundle" />).
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="sched">The sched.</param>
        /// <param name="localOverWriteExistingJobs">if set to <c>true</c> [local over write existing jobs].</param>
        /// <exception cref="SchedulerException">
        /// if the Job or Trigger cannot be added to the Scheduler, or
        /// there is an internal Scheduler error.
        /// </exception>
        public virtual void ScheduleJob(JobSchedulingBundle job, IScheduler sched, bool localOverWriteExistingJobs)
        {
            if ((job != null) && job.Valid)
            {
                JobDetail detail = job.JobDetail;

                JobDetail dupeJ = sched.GetJobDetail(detail.Name, detail.Group);

                if ((dupeJ != null) && !localOverWriteExistingJobs)
                {
                    Log.Info("Not overwriting existing job: " + dupeJ.FullName);
                    return;
                }

                if (dupeJ != null)
                {
                    Log.Info(string.Format(CultureInfo.InvariantCulture, "Replacing job: {0}", detail.FullName));
                }
                else
                {
                    Log.Info(string.Format(CultureInfo.InvariantCulture, "Adding job: {0}", detail.FullName));
                }

                if (job.Triggers.Count == 0 && !job.JobDetail.Durable)
                {
                    throw new SchedulerException("A Job defined without any triggers must be durable");
                }

                sched.AddJob(detail, true);


                foreach (Trigger trigger in job.Triggers)
                {
                    Trigger dupeT = sched.GetTrigger(trigger.Name, trigger.Group);

                    trigger.JobName  = detail.Name;
                    trigger.JobGroup = detail.Group;

                    if (trigger.StartTimeUtc == DateTime.MinValue)
                    {
                        trigger.StartTimeUtc = DateTime.UtcNow;
                    }

                    if (dupeT != null)
                    {
                        Log.Debug(string.Format(CultureInfo.InvariantCulture, "Rescheduling job: {0} with updated trigger: {1}", detail.FullName, trigger.FullName));
                        if (!dupeT.JobGroup.Equals(trigger.JobGroup) || !dupeT.JobName.Equals(trigger.JobName))
                        {
                            Log.Warn("Possibly duplicately named triggers in jobs xml file!");
                        }
                        sched.RescheduleJob(trigger.Name, trigger.Group, trigger);
                    }
                    else
                    {
                        Log.Debug(string.Format(CultureInfo.InvariantCulture, "Scheduling job: {0} with trigger: {1}", detail.FullName, trigger.FullName));
                        sched.ScheduleJob(trigger);
                    }
                }

                AddScheduledJob(job);
            }
        }
Ejemplo n.º 8
0
 public virtual void AddJobToSchedule(JobSchedulingBundle job)
 {
     jobsToSchedule.Add(job);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Schedules a given job and trigger (both wrapped by a <see cref="JobSchedulingBundle" />).
 /// </summary>
 /// <param name="job">job wrapper.</param>
 /// <exception cref="SchedulerException">
 /// if the Job or Trigger cannot be added to the Scheduler, or
 /// there is an internal Scheduler error.
 /// </exception>
 public virtual void ScheduleJob(JobSchedulingBundle job)
 {
     ScheduleJob(job, (IScheduler)LogicalThreadContext.GetData(ThreadLocalKeyScheduler), OverwriteExistingJobs);
 }
Ejemplo n.º 10
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);
            }
        }