コード例 #1
0
ファイル: CronJobTest.cs プロジェクト: yakkobr/Cronical
 public void TestStripComments()
 {
     Assert.IsNull(CronJob.Parse(ConfigReader.DoParseJobLine(null)));
     Assert.IsNull(CronJob.Parse(ConfigReader.DoParseJobLine("")));
     Assert.IsNull(CronJob.Parse(ConfigReader.DoParseJobLine("       ")));
     Assert.IsNull(CronJob.Parse(ConfigReader.DoParseJobLine("   # This is some whitespace")));
 }
コード例 #2
0
ファイル: CronJobTest.cs プロジェクト: yakkobr/Cronical
        public void TestSpecials()
        {
            CronJob job;

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@reboot      Reboot"));
            Assert.AreEqual("Reboot", job.Command);
            Assert.IsTrue(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@yearly yearly"));
            Assert.AreEqual("yearly", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(1, job.Hours.Val());
            Assert.AreEqual(1, job.Days.Val());
            Assert.AreEqual(1, job.Months.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@annually annually"));
            Assert.AreEqual("annually", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(1, job.Hours.Val());
            Assert.AreEqual(1, job.Days.Val());
            Assert.AreEqual(1, job.Months.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@monthly monthly"));
            Assert.AreEqual("monthly", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(1, job.Hours.Val());
            Assert.AreEqual(1, job.Days.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@weekly weekly"));
            Assert.AreEqual("weekly", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(1, job.Hours.Val());
            Assert.AreEqual(1, job.Weekdays.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@daily daily"));
            Assert.AreEqual("daily", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(1, job.Hours.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("@hourly hourly"));
            Assert.AreEqual("hourly", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.IsFalse(job.Reboot);
        }
コード例 #3
0
        private void ConfigReaderOnJobRead(object sender, ConfigReader.JobArgs jobArgs)
        {
            var job = jobArgs.Service ? (Job)ServiceJob.Parse(jobArgs, Settings) : CronJob.Parse(jobArgs, Settings);

            if (job == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(job.Settings.Home))
            {
                job.Settings.Home = Path.FullName;
            }

            job.VerifyExecutableExists();
            Jobs.Add(job);
        }
コード例 #4
0
ファイル: CronJobTest.cs プロジェクト: yakkobr/Cronical
        public void TestNormal()
        {
            CronJob job;

            job = CronJob.Parse(ConfigReader.DoParseJobLine(" * * * * *    xx"));
            Assert.AreEqual("xx", job.Command);
            Assert.AreEqual(MakeAllBits(24), job.Hours.Val());
            Assert.AreEqual(MakeAllBits(31), job.Days.Val());
            Assert.AreEqual(MakeAllBits(12), job.Months.Val());
            Assert.AreEqual(MakeAllBits(60), job.Minutes.Val());
            // Assert.AreEqual(MakeAllBits(7), job.Weekdays.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("* 12 3 5 *    xx"));
            Assert.AreEqual("xx", job.Command);
            Assert.AreEqual(MakeBits(0, 12), job.Hours.Val());
            Assert.AreEqual(MakeBits(1, 3), job.Days.Val());
            Assert.AreEqual(MakeBits(1, 5), job.Months.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("0-2,7-9 * * * *    x x"));
            Assert.AreEqual("x x", job.Command);
            Assert.AreEqual(MakeBits(0, 0, 1, 2, 7, 8, 9), job.Minutes.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("0 */2 * * *       Every other hour"));
            Assert.AreEqual("Every other hour", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(MakeBits(0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22), job.Hours.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("0 9-17/3 * * *    From 09:00 - 17:00, every third hour"));
            Assert.AreEqual("From 09:00 - 17:00, every third hour", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(MakeBits(0, 9, 12, 15), job.Hours.Val());
            Assert.IsFalse(job.Reboot);

            job = CronJob.Parse(ConfigReader.DoParseJobLine("0 8,12,17 * * *   At 08:00, 12:00, 17:00"));
            Assert.AreEqual("At 08:00, 12:00, 17:00", job.Command);
            Assert.AreEqual(1, job.Minutes.Val());
            Assert.AreEqual(MakeBits(0, 8, 12, 17), job.Hours.Val());
            Assert.IsFalse(job.Reboot);
        }
コード例 #5
0
ファイル: CronJobTest.cs プロジェクト: yakkobr/Cronical
        public void TestGetCode()
        {
            var args = new ConfigReader.JobArgs
            {
                Command = "process.exe",
                Day     = "*",
                Hour    = "*",
                Minute  = "0,15,30,45",
                Month   = "*/2",
                Weekday = "*",
            };

            var job = CronJob.Parse(args, new Settings
            {
                Home    = "c:\\windows",
                Timeout = 86400
            });

            Assert.AreEqual("CronJob,process.exe,c:\\windows,False,,,,,,,False,,,127,1365,2147483647,16777215,35185445863425", job.GetJobCode());
        }
コード例 #6
0
ファイル: CronJobTest.cs プロジェクト: yakkobr/Cronical
        public void TestSpacing()
        {
            var job = CronJob.Parse(ConfigReader.DoParseJobLine(" * * * * *    xx\t1\t2"));

            Assert.AreEqual("xx 1 2", job.Command);
        }