private bool isittime(ScheduleItem sched)
 {
     bool rtn = false;
     if (DateTime.Now.ToString("HH:mm") == sched.ScheduledTime.StartTime.ToString("HH:mm"))
     {
         rtn = true;
     }
     return rtn;
 }
 private void RunScheduleScript(ScheduleItem sched)
 {
     sched.LastRunTime = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");
     Save();
     OnItemUpdated(new ScheduleEventArgs(sched));
     OnScriptInvoked(new ScheduleEventArgs(sched));
 }
 private bool isthedate(ScheduleItem sched)
 {
     bool rtn = false;
     if (sched.ScheduledTime.Dates.Count > 0)
     {
         int didx = -1;
         do
         {
             didx++;
             if (sched.ScheduledTime.Dates[didx] == DateTime.Now.Day)
             {
                 rtn = true;
             }
             else if ((sched.ScheduledTime.Dates[didx] == 32) && DateTime.Now.Day == DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month))
             {
                 //Last day of month
                 rtn = true;
             }
         } while (didx < sched.ScheduledTime.Dates.Count - 1 && !rtn);
     }
     return rtn;
 }
 private bool isthemonth(ScheduleItem sched)
 {
     bool rtn = false;
     if (sched.ScheduledTime.Months.Count > 0)
     {
         int midx = -1;
         do
         {
             midx++;
             if (sched.ScheduledTime.Months[midx] == DateTime.Now.Month)
             {
                 rtn = true;
             }
         } while (midx < sched.ScheduledTime.Months.Count - 1 && !rtn);
     }
     return rtn;
 }
 private bool IsScheduledTime(ScheduleItem sched)
 {
     bool rtn = false;
     if (DateTime.Now >= sched.ScheduledTime.StartDate)
     {
         switch (sched.ScheduledTime.Frequency)
         {
             case Enums.EnumValues.TimeFrequency.Once:
                 if (DateTime.Now >= sched.ScheduledTime.StartDate)
                 {
                     rtn = true;
                 }
                 break;
             case Enums.EnumValues.TimeFrequency.Daily:
                 //Only compare the time ignoring the seconds.
                 rtn = isittime(sched);
                 break;
             case Enums.EnumValues.TimeFrequency.Weekly:
                 //Check Day(s) then check time.
                 int didx = -1;
                 int today = (int)DateTime.Now.DayOfWeek;
                 if (sched.ScheduledTime.DaysofWeek.Count > 0)
                 {
                     bool found = false;
                     do
                     {
                         didx++;
                         if (sched.ScheduledTime.DaysofWeek[didx] == today)
                         {
                             found = true;
                         }
                     } while (didx < sched.ScheduledTime.DaysofWeek.Count - 1 && !found);
                     if (found)
                     {
                         rtn = isittime(sched);
                     }
                 }
                 break;
             case Enums.EnumValues.TimeFrequency.Monthly:
                 //Check Month, then dates, then time.
                 if (isthemonth(sched) && isthedate(sched))
                 {
                     rtn = isittime(sched);
                 }
                 break;
         }
     }            
     return rtn;
 }
 public ScheduleEventArgs(ScheduleItem schedule)
 {
     sched = schedule;
 }
Beispiel #7
0
        private void ScheduleScript()
        {
            try
            {
                List<PShell.psparameter> scriptparams;
                ListViewItem lvw = lvwScripts.SelectedItems[0];
                scriptparams = psf.CheckForParams(lvw.Tag.ToString());

                if (!psf.ParamSelectionCancelled)
                {
                    Utility.ScheduleItem sitm = new Utility.ScheduleItem();
                    sitm.ScriptName = lvw.Text;
                    sitm.ScriptPath = lvw.Tag.ToString();
                    sitm.RunAs = Enums.EnumValues.RunAs.CurrentUser;
                    if (scriptparams != null && scriptparams.Count > 0)
                    {
                        foreach (PShell.psparameter prm in scriptparams)
                        {
                            sitm.Parameters.Properties.Add(prm);
                        }
                    }
                    Interface.frmSchedule sched = new Interface.frmSchedule();
                    if (sched.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        sitm.ScheduledTime = sched.ScheduledTime;
                        sitm.Index = GetScheduleIndex();
                        schedule.ScheduleItems.Add(sitm);
                        if (schedule.Save())
                        {
                            LoadSchedule();
                        }
                        else
                        {
                            MessageBox.Show("Error saving schedule: " + schedule.LastException.Message);
                        }
                    }
                    sched = null;
                }                
            }
            catch (Exception e)
            {
                DisplayError(e);
            }
        }