Exemplo n.º 1
0
        public void StoreJob(IScheduledJob job, bool replaceExisting)
        {
            JobWrapper wrapper = new JobWrapper(job);
            bool       flag    = false;

            lock (this._jobLock)
            {
                if (this._jobsDictionary[wrapper.Name] != null)
                {
                    if (!replaceExisting)
                    {
                        throw new ArgumentException("job");
                    }
                    flag = true;
                }
                if (!flag)
                {
                    this._jobsDictionary[wrapper.Name] = wrapper;
                }
                else
                {
                    JobWrapper wrapper2 = this._jobsDictionary[wrapper.Name] as JobWrapper;
                    wrapper2.Job = wrapper.Job;
                }
            }
        }
Exemplo n.º 2
0
        public void StoreJob(IScheduledJob job, bool replaceExisting)
        {
            JobWrapper jobWrapper = new JobWrapper(job);
            bool       replace    = false;

            lock (_jobLock)
            {
                if (_jobsDictionary[jobWrapper.Name] != null)
                {
                    if (!replaceExisting)
                    {
                        throw new ArgumentException("job");
                    }
                    replace = true;
                }
                if (!replace)
                {
                    _jobsDictionary[jobWrapper.Name] = jobWrapper;
                }
                else
                {
                    // update job detail
                    JobWrapper orig = _jobsDictionary[jobWrapper.Name] as JobWrapper;
                    orig.Job = jobWrapper.Job;
                }
            }
        }
Exemplo n.º 3
0
        public bool RemoveTrigger(string triggerName, bool deleteOrphanedJob)
        {
            bool flag;

            lock (this._triggerLock)
            {
                object obj2 = this._triggersDictionary[triggerName];
                this._triggersDictionary.Remove(triggerName);
                flag = obj2 != null;
                if (!flag)
                {
                    return(flag);
                }
                TriggerWrapper wrapper = null;
                for (int i = 0; i < this._triggers.Count; i++)
                {
                    wrapper = this._triggers[i] as TriggerWrapper;
                    if (triggerName.Equals(wrapper.Name))
                    {
                        this._triggers.RemoveAt(i);
                        break;
                    }
                }
                this._timeTriggers.Remove(wrapper);
                JobWrapper wrapper2       = this._jobsDictionary[wrapper.Trigger.JobName] as JobWrapper;
                Trigger[]  triggersForJob = this.GetTriggersForJob(wrapper.Trigger.JobName);
                if (((triggersForJob == null) || (triggersForJob.Length == 0)) && deleteOrphanedJob)
                {
                    this.RemoveJob(wrapper.Trigger.JobName);
                }
            }
            return(flag);
        }
Exemplo n.º 4
0
 public IScheduledJob RetrieveJob(string jobName)
 {
     lock (_jobsDictionary)
     {
         JobWrapper jw = _jobsDictionary[jobName] as JobWrapper;
         return((jw != null) ? jw.Job : null);
     }
 }
Exemplo n.º 5
0
 public IScheduledJob RetrieveJob(string jobName)
 {
     lock (this._jobsDictionary)
     {
         JobWrapper wrapper = this._jobsDictionary[jobName] as JobWrapper;
         return((wrapper != null) ? wrapper.Job : null);
     }
 }
Exemplo n.º 6
0
        public void TriggeredJobComplete(Trigger trigger, IScheduledJob job, SchedulerInstruction triggerInstCode)
        {
            lock (_triggerLock)
            {
                JobWrapper     jw = _jobsDictionary[job.Name] as JobWrapper;
                TriggerWrapper tw = _triggersDictionary[trigger.Name] as TriggerWrapper;

                // even if it was deleted, there may be cleanup to do
                _blockedJobs.Remove(job.Name);

                // check for trigger deleted during execution...
                if (tw != null)
                {
                    if (triggerInstCode == SchedulerInstruction.DeleteTrigger)
                    {
                        //log.Debug("Deleting trigger");
                        NullableDateTime d = trigger.GetNextFireTimeUtc();
                        if (!d.HasValue)
                        {
                            // double check for possible reschedule within job
                            // execution, which would cancel the need to delete...
                            d = tw.Trigger.GetNextFireTimeUtc();
                            if (!d.HasValue)
                            {
                                RemoveTrigger(trigger.Name);
                            }
                            else
                            {
                                log.Debug("Deleting cancelled - trigger still active");
                            }
                        }
                        else
                        {
                            RemoveTrigger(trigger.Name);
                        }
                    }
                    else if (triggerInstCode == SchedulerInstruction.SetTriggerComplete)
                    {
                        tw.State = InternalTriggerState.Complete;
                        _timeTriggers.Remove(tw);
                    }
                    else if (triggerInstCode == SchedulerInstruction.SetTriggerError)
                    {
                        log.Info(string.Format(CultureInfo.InvariantCulture, "Trigger {0} set to ERROR state.", trigger.Name));
                        tw.State = InternalTriggerState.Error;
                    }
                    else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersError)
                    {
                        log.Info(string.Format(CultureInfo.InvariantCulture, "All triggers of Job {0} set to ERROR state.", trigger.Name));
                        SetAllTriggersOfJobToState(trigger.Name, InternalTriggerState.Error);
                    }
                    else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersComplete)
                    {
                        SetAllTriggersOfJobToState(trigger.Name, InternalTriggerState.Complete);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public override bool Equals(object obj)
 {
     if (obj is JobWrapper)
     {
         JobWrapper jw = (JobWrapper)obj;
         if (jw._job.Equals(_job))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 8
0
 public override bool Equals(object obj)
 {
     if (obj is JobWrapper)
     {
         JobWrapper wrapper = (JobWrapper)obj;
         if (wrapper._job.Equals(this._job))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 9
0
 public void TriggeredJobComplete(Trigger trigger, IScheduledJob job, SchedulerInstruction triggerInstCode)
 {
     lock (this._triggerLock)
     {
         JobWrapper     wrapper  = this._jobsDictionary[job.Name] as JobWrapper;
         TriggerWrapper wrapper2 = this._triggersDictionary[trigger.Name] as TriggerWrapper;
         this._blockedJobs.Remove(job.Name);
         if (wrapper2 != null)
         {
             if (triggerInstCode == SchedulerInstruction.DeleteTrigger)
             {
                 if (!trigger.GetNextFireTimeUtc().HasValue)
                 {
                     if (!wrapper2.Trigger.GetNextFireTimeUtc().HasValue)
                     {
                         this.RemoveTrigger(trigger.Name);
                     }
                     else
                     {
                         log.Debug("Deleting cancelled - trigger still active");
                     }
                 }
                 else
                 {
                     this.RemoveTrigger(trigger.Name);
                 }
             }
             else if (triggerInstCode == SchedulerInstruction.SetTriggerComplete)
             {
                 wrapper2.State = InternalTriggerState.Complete;
                 this._timeTriggers.Remove(wrapper2);
             }
             else if (triggerInstCode == SchedulerInstruction.SetTriggerError)
             {
                 log.Info(string.Format(CultureInfo.InvariantCulture, "Trigger {0} set to ERROR state.", new object[] { trigger.Name }));
                 wrapper2.State = InternalTriggerState.Error;
             }
             else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersError)
             {
                 log.Info(string.Format(CultureInfo.InvariantCulture, "All triggers of Job {0} set to ERROR state.", new object[] { trigger.Name }));
                 this.SetAllTriggersOfJobToState(trigger.Name, InternalTriggerState.Error);
             }
             else if (triggerInstCode == SchedulerInstruction.SetAllJobTriggersComplete)
             {
                 this.SetAllTriggersOfJobToState(trigger.Name, InternalTriggerState.Complete);
             }
         }
     }
 }
Exemplo n.º 10
0
        public bool RemoveTrigger(string triggerName, bool deleteOrphanedJob)
        {
            bool found;

            lock (_triggerLock)
            {
                // remove from triggers
                object tempObject;
                tempObject = _triggersDictionary[triggerName];
                _triggersDictionary.Remove(triggerName);
                found = (tempObject == null) ? false : true;
                if (found)
                {
                    TriggerWrapper tw = null;
                    // remove from triggers array
                    for (int i = 0; i < _triggers.Count; ++i)
                    {
                        tw = _triggers[i] as TriggerWrapper;
                        if (triggerName.Equals(tw.Name))
                        {
                            _triggers.RemoveAt(i);
                            break;
                        }
                    }
                    _timeTriggers.Remove(tw);

                    JobWrapper jw       = _jobsDictionary[tw.Trigger.JobName] as JobWrapper;
                    Trigger[]  triggers = GetTriggersForJob(tw.Trigger.JobName);
                    if ((triggers == null || triggers.Length == 0) && deleteOrphanedJob)
                    {
                        RemoveJob(tw.Trigger.JobName);
                    }
                }
            }
            return(found);
        }
Exemplo n.º 11
0
 public void StoreJob(IScheduledJob job, bool replaceExisting)
 {
     JobWrapper jobWrapper = new JobWrapper(job);
     bool replace = false;
     lock (_jobLock)
     {
         if (_jobsDictionary[jobWrapper.Name] != null)
         {
             if (!replaceExisting)
             {
                 throw new ArgumentException("job");
             }
             replace = true;
         }
         if (!replace)
         {
             _jobsDictionary[jobWrapper.Name] = jobWrapper;
         }
         else
         {
             // update job detail
             JobWrapper orig = _jobsDictionary[jobWrapper.Name] as JobWrapper;
             orig.Job = jobWrapper.Job;
         }
     }
 }