public void RemoveSchedule(Schedule schedule)
 {
     var triggerKey = new TriggerKey(schedule.Id.ToString(), schedule.CommandId.ToString());
     var jobKey = new JobKey(schedule.Id.ToString(), schedule.CommandId.ToString());
     scheduler.UnscheduleJob(triggerKey);
     scheduler.DeleteJob(jobKey);
 }
 public void Schedule(Schedule schedule)
 {
     switch (schedule.PeriodicityType)
     {
         case PeriodicityType.EVERY_X_MINUTES:
             {
                 ScheduleEveryXMinutes(schedule);
                 break;
             }
         case PeriodicityType.EVERY_X_HOURS:
             {
                 ScheduleEveryXHours(schedule);
                 break;
             }
         case PeriodicityType.ONCE_AT_SPECIFIC_TIME:
             {
                 ScheduleOnceAtSpecificTime(schedule);
                 break;
             }
         default: { throw new NotImplementedException("Periodicity Type not implemented."); }
     }
 }
        private void ScheduleEveryXHours(Schedule schedule)
        {
            IJobDetail job = JobBuilder.Create<Quartz.CommandJob>()
              .WithIdentity(schedule.Id.ToString(), schedule.CommandId.ToString())
              .UsingJobData("CommandId", schedule.CommandId.ToString())
              .UsingJobData("Command", schedule.Command.Name)
              .UsingJobData("Host", schedule.Command.Host)
              .UsingJobData("Parameters", GetParametersAsString(schedule.Command.Parameter))
              .Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity(schedule.Id.ToString(), schedule.CommandId.ToString())
                .StartAt(new DateTimeOffset(schedule.StartDateTime))
                .WithSimpleSchedule(x =>
                    x.WithIntervalInHours(schedule.PeriodicityValue).RepeatForever())
                .Build();

            if (!scheduler.CheckExists(job.Key))
            {
                scheduler.ScheduleJob(job, trigger);
            }
            else
            {
                scheduler.RescheduleJob(trigger.Key, trigger);
            }
        }
        private void ScheduleOnceAtSpecificTime(Schedule schedule)
        {
            IJobDetail job = JobBuilder.Create<Quartz.CommandJob>()
              .WithIdentity(schedule.Id.ToString(), schedule.CommandId.ToString())
              .UsingJobData("CommandId", schedule.CommandId.ToString())
              .UsingJobData("Command", schedule.Command.Name)
              .UsingJobData("Host", schedule.Command.Host)
              .UsingJobData("Parameters", GetParametersAsString(schedule.Command.Parameter))
              .Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity(schedule.Id.ToString(), schedule.CommandId.ToString())
                .StartAt(new DateTimeOffset(schedule.StartDateTime))
                .WithSimpleSchedule()
                .Build();

            if (!scheduler.CheckExists(job.Key))
            {
                scheduler.ScheduleJob(job, trigger);
            }
            else
            {
                scheduler.RescheduleJob(trigger.Key, trigger);
            }
        }