public void TestCanAddTask()
 {
     SchedulerManager scheduler = new SchedulerManager(mockServer.Object);
     ScheduleTask task = new ScheduleTask("*", 5, 0);
     scheduler.AddTask(task);
     Console.WriteLine(string.Format("nextTask() is at {0}", scheduler.NextTask.NextRun));
     Assert.That(scheduler.NextTask, Is.EqualTo(task));
 }
Esempio n. 2
0
 private void ExecuteTask(ScheduleTask task)
 {
     task.CalculateNextRunTime();
     if (mServer != null)
     {
         mServer.RaiseServerMessage(string.Format("Running scheduled task '{0}'.  Next run will be {1}.", task.Name, task.NextRun));
         mServer.Execute(task.Command);
     }
 }
Esempio n. 3
0
        public void TestNextRun()
        {
            ScheduleTask task = new ScheduleTask("Monday", 5, 30);

            task.CalculateNextRunTime(mondayMorning);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));
        }
Esempio n. 4
0
        public void TestLegalSpecialDaysAccepted()
        {
            ScheduleTask task = new ScheduleTask(ScheduleTask.AT_STARTUP, 0, 0);

            Assert.That(task.RunDays, Is.EqualTo(ScheduleTask.AT_NEVER));

            task = new ScheduleTask(ScheduleTask.AT_NEVER, 0, 0);
            Assert.That(task.RunDays, Is.EqualTo(ScheduleTask.AT_NEVER));
        }
 public void TestNextTaskSequencing()
 {
     SchedulerManager scheduler = new SchedulerManager(mockServer.Object);
     ScheduleTask taskA = new ScheduleTask("*", 6, 0);
     ScheduleTask taskB = new ScheduleTask("*", 5, 0);
     scheduler.AddTask(taskA);
     scheduler.AddTask(taskB);
     Assert.That(scheduler.NextTask, Is.Not.EqualTo(taskA));
     Assert.That(scheduler.NextTask, Is.EqualTo(taskB));
 }
Esempio n. 6
0
        public void TestUnwantedComponentsAreZero(
            [Range(0, 23, 7)] int h,
            [Range(0, 59, 23)] int m
            )
        {
            ScheduleTask task = new ScheduleTask("*", h, m);

            Assert.That(task.NextRun.Second, Is.EqualTo(0));
            Assert.That(task.NextRun.Millisecond, Is.EqualTo(0));
        }
        public void TestNextTaskSequencing()
        {
            SchedulerManager scheduler = new SchedulerManager(mockServer.Object);
            ScheduleTask     taskA     = new ScheduleTask("*", 6, 0);
            ScheduleTask     taskB     = new ScheduleTask("*", 5, 0);

            scheduler.AddTask(taskA);
            scheduler.AddTask(taskB);
            Assert.That(scheduler.NextTask, Is.Not.EqualTo(taskA));
            Assert.That(scheduler.NextTask, Is.EqualTo(taskB));
        }
Esempio n. 8
0
        public void TestNewTaskSetsNextRun(
            [Values(0, 13, 23)] int h,
            [Values(0, 37, 59)] int m
            )
        {
            ScheduleTask task = new ScheduleTask("Monday", h, m);

            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(h));
            Assert.That(task.NextRun.Minute, Is.EqualTo(m));
            Assert.That(task.NextRun.Second, Is.EqualTo(0));
        }
Esempio n. 9
0
        public void TestIllegalValuesAreRejected()
        {
            ScheduleTask task;

            task = new ScheduleTask("a", 0, 0);    // invalid day
            task = new ScheduleTask("*", -1, 0);   // too low hour
            task = new ScheduleTask("*", 0, -1);   // too low minute
            task = new ScheduleTask("*", 24, 0);   // too high hour
            task = new ScheduleTask("*", 0, 60);   // too high minute
            task = new ScheduleTask("", "*", "*"); //empty day
            task = new ScheduleTask("*", "", "*"); //empty hour
            task = new ScheduleTask("*", "*", ""); //empty minute
        }
Esempio n. 10
0
        public void TestAllDays()
        {
            ScheduleTask task = new ScheduleTask("*", 5, 30);

            task.CalculateNextRunTime(mondayMorning);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Tuesday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Wednesday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Thursday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Friday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Saturday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Sunday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));
        }
Esempio n. 11
0
        public void TestAllDays()
        {
            ScheduleTask task = new ScheduleTask("*", 5, 30);

            task.CalculateNextRunTime(mondayMorning);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Tuesday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Wednesday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Thursday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Friday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Saturday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Sunday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));

            task.CalculateNextRunTime(task.NextRun);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));
        }
Esempio n. 12
0
        public void TestEveryHour()
        {
            ScheduleTask task = new ScheduleTask("*", "*", 0);

            task.CalculateNextRunTime(mondayMorning);
            for (int i = 5; i < 24; i++)
            {
                Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
                Assert.That(task.NextRun.Hour, Is.EqualTo(i));
                Assert.That(task.NextRun.Minute, Is.EqualTo(0));
                task.CalculateNextRunTime(task.NextRun);
            }
            for (int i = 0; i < 24; i++)
            {
                Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Tuesday));
                Assert.That(task.NextRun.Hour, Is.EqualTo(i));
                Assert.That(task.NextRun.Minute, Is.EqualTo(0));
                task.CalculateNextRunTime(task.NextRun);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Parses the file specified by <c>file</c> for tasks, and adds them
        /// to the execution queue.
        /// </summary>
        /// <param name="file">Full path to the schedule file.</param>
        public void LoadSchedule(string file)
        {
            mTasks = new List <ScheduleTask>();
            if ((file.Length == 0) || (!File.Exists(file)))
            {
                return;
            }
            XmlDocument xml = new XmlDocument();

            xml.Load(file);
            XmlNodeList nodeList = xml.DocumentElement.SelectNodes("/schedule/task");

            foreach (XmlNode taskNode in nodeList)
            {
                ScheduleTask task = new ScheduleTask();
                task.Name       = taskNode.SelectSingleNode("name").InnerText;
                task.Command    = taskNode.SelectSingleNode("command").InnerText;
                task.RunDays    = taskNode.SelectSingleNode("days").InnerText;
                task.RunHours   = taskNode.SelectSingleNode("hours").InnerText;
                task.RunMinutes = taskNode.SelectSingleNode("minutes").InnerText;
                AddTask(task);
            }
        }
Esempio n. 14
0
 public void TestStartupNextRunIsSoon()
 {
     ScheduleTask task = new ScheduleTask(ScheduleTask.AT_STARTUP, 0, 0);
     Assert.That(task.NextRun, Is.AtMost(DateTime.Now.AddMinutes(1)));
 }
Esempio n. 15
0
        public void TestStartupNextRunIsSoon()
        {
            ScheduleTask task = new ScheduleTask(ScheduleTask.AT_STARTUP, 0, 0);

            Assert.That(task.NextRun, Is.AtMost(DateTime.Now.AddMinutes(1)));
        }
Esempio n. 16
0
 public void TestIllegalValuesAreRejected()
 {
     ScheduleTask task;
     task = new ScheduleTask("a", 0, 0); // invalid day
     task = new ScheduleTask("*", -1, 0); // too low hour
     task = new ScheduleTask("*", 0, -1); // too low minute
     task = new ScheduleTask("*", 24, 0); // too high hour
     task = new ScheduleTask("*", 0, 60); // too high minute
     task = new ScheduleTask("", "*", "*"); //empty day
     task = new ScheduleTask("*", "", "*"); //empty hour
     task = new ScheduleTask("*", "*", ""); //empty minute
 }
Esempio n. 17
0
 /// <summary>
 /// Adds the specified <see cref="IScheduleTask"/> to the task list.
 /// </summary>
 /// <param name="task">The task to add.</param>
 public void AddTask(ScheduleTask task)
 {
     task.CalculateNextRunTime();
     mTasks.Add(task);
 }
Esempio n. 18
0
 /// <summary>
 /// Parses the file specified by <c>file</c> for tasks, and adds them
 /// to the execution queue.
 /// </summary>
 /// <param name="file">Full path to the schedule file.</param>
 public void LoadSchedule(string file)
 {
     mTasks = new List<ScheduleTask>();
     if ( (file.Length == 0) || (!File.Exists(file)) )
     {
         return;
     }
     XmlDocument xml = new XmlDocument();
     xml.Load(file);
     XmlNodeList nodeList = xml.DocumentElement.SelectNodes("/schedule/task");
     foreach (XmlNode taskNode in nodeList)
     {
         ScheduleTask task = new ScheduleTask();
         task.Name = taskNode.SelectSingleNode("name").InnerText;
         task.Command = taskNode.SelectSingleNode("command").InnerText;
         task.RunDays = taskNode.SelectSingleNode("days").InnerText;
         task.RunHours = taskNode.SelectSingleNode("hours").InnerText;
         task.RunMinutes = taskNode.SelectSingleNode("minutes").InnerText;
         AddTask(task);
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Adds the specified <see cref="IScheduleTask"/> to the task list.
 /// </summary>
 /// <param name="task">The task to add.</param>
 public void AddTask(ScheduleTask task)
 {
     task.CalculateNextRunTime();
     mTasks.Add(task);
 }
Esempio n. 20
0
 private void ExecuteTask(ScheduleTask task)
 {
     task.CalculateNextRunTime();
     if (mServer != null)
     {
         mServer.RaiseServerMessage(string.Format("Running scheduled task '{0}'.  Next run will be {1}.", task.Name, task.NextRun));
         mServer.Execute(task.Command);
     }
 }
Esempio n. 21
0
        public void TestEveryHour()
        {
            ScheduleTask task = new ScheduleTask("*", "*", 0);

            task.CalculateNextRunTime(mondayMorning);
            for (int i = 5; i < 24; i++)
            {
                Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
                Assert.That(task.NextRun.Hour, Is.EqualTo(i));
                Assert.That(task.NextRun.Minute, Is.EqualTo(0));
                task.CalculateNextRunTime(task.NextRun);
            }
            for (int i = 0; i < 24; i++)
            {
                Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Tuesday));
                Assert.That(task.NextRun.Hour, Is.EqualTo(i));
                Assert.That(task.NextRun.Minute, Is.EqualTo(0));
                task.CalculateNextRunTime(task.NextRun);
            }
        }
Esempio n. 22
0
 public void TestUnwantedComponentsAreZero(
     [Range(0, 23, 7)] int h,
     [Range(0, 59, 23)] int m
     )
 {
     ScheduleTask task = new ScheduleTask("*", h, m);
     Assert.That(task.NextRun.Second, Is.EqualTo(0));
     Assert.That(task.NextRun.Millisecond, Is.EqualTo(0));
 }
Esempio n. 23
0
 public void TestLegalSingleDaysAccepted(
     [Values("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")] string day
     )
 {
     ScheduleTask task = new ScheduleTask(day, 0, 0);
     Assert.That(task.RunDays, Is.EqualTo(day));
 }
Esempio n. 24
0
        public void TestNextRun()
        {
            ScheduleTask task = new ScheduleTask("Monday", 5, 30);

            task.CalculateNextRunTime(mondayMorning);
            Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
            Assert.That(task.NextRun.Hour, Is.EqualTo(5));
            Assert.That(task.NextRun.Minute, Is.EqualTo(30));
        }
Esempio n. 25
0
 public void TestNewTaskSetsNextRun(
     [Values(0, 13, 23)] int h,
     [Values(0, 37, 59)] int m
     )
 {
     ScheduleTask task = new ScheduleTask("Monday", h, m);
     Assert.That(task.NextRun.DayOfWeek, Is.EqualTo(DayOfWeek.Monday));
     Assert.That(task.NextRun.Hour, Is.EqualTo(h));
     Assert.That(task.NextRun.Minute, Is.EqualTo(m));
     Assert.That(task.NextRun.Second, Is.EqualTo(0));
 }
Esempio n. 26
0
        public void TestLegalSpecialDaysAccepted()
        {
            ScheduleTask task = new ScheduleTask(ScheduleTask.AT_STARTUP, 0, 0);
            Assert.That(task.RunDays, Is.EqualTo(ScheduleTask.AT_NEVER));

            task = new ScheduleTask(ScheduleTask.AT_NEVER, 0, 0);
            Assert.That(task.RunDays, Is.EqualTo(ScheduleTask.AT_NEVER));
        }