public ActionResult Schedule(PowerShellSchedule schedule)
 {
     var jobServices = new JobServices(_scriptRepository);
     var psMetadata = _scriptRepository.GetScriptById(schedule.Id);
     if (psMetadata == null) return HttpNotFound();
     jobServices.Schedule(psMetadata, schedule, User.Identity.Name);
     return RedirectToAction("Details", new { id = schedule.Id });
 }
Example #2
0
        public void Schedule(Script script, PowerShellSchedule schedule, string username)
        {
            var job = new Job()
            {
                UserName = username,
                ScriptId = schedule.Id,
                Date = schedule.Date,
                JobId =
                    Int32.Parse(BackgroundJob.Schedule(() => Run(script.Name, schedule.PSparams),
                        new DateTime(schedule.Date.Ticks))),
                Status = Status.Scheduled,
                JobType = JobType.Scheduled
            };

            _scriptRepository.InsertJob(job);
            _scriptRepository.Save();

            if (schedule.SelectedRecurring != null)
            {
                // Change Job Type and Set Recurring Job
                // This is important to ensure CancelJob cancels associated recurring jobs
                // TODO: Review Logic
                job.JobType = JobType.ScheduledWithRecurring;
                _scriptRepository.UpdateJob(job);
                var recurringJob = new Job()
                {
                    UserName = username,
                    ScriptId = script.Id,
                    Date = schedule.Date,
                    JobId =
                        Int32.Parse(
                            BackgroundJob.Schedule(
                                () => RunOnSchedule(job.Id, script.Name,
                                    schedule.SelectedRecurring, schedule.PSparams),
                                new DateTime(schedule.Date.Ticks))),
                    RecurringId = job.Id,
                    Status =  Status.Scheduled,
                    JobType = JobType.Recurring,
                    Outcome = schedule.SelectedRecurring
                };
                _scriptRepository.InsertJob(recurringJob);
                _scriptRepository.Save();
            }

        }
        //GET: PowerShell/Schedule/1
        public ActionResult Schedule(int id)
        {
            var script = _scriptRepository.GetScriptById(id);
            if (script == null) return HttpNotFound();

            var scriptParams = ScriptIO.ScriptParams(script.Name) ??
                               new Dictionary<string, string>();

            var scheduleView = new PowerShellSchedule()
            {
                Id = script.Id,
                Date = DateTime.Now,
                Recurring = JobServices.RecurringOptions(),
                PSparams = scriptParams
            };

            return PartialView(scheduleView);
        }