diff --git a/.gitignore b/.gitignore index d13c477..6dbfbab 100644 --- a/.gitignore +++ b/.gitignore @@ -68,6 +68,8 @@ local.properties *.vspscc .builds *.dotCover +.[vV][sS]/ +.[nN]uget/ ## TODO: If you have NuGet Package Restore enabled, uncomment this packages/ diff --git a/.nuget/NuGet.Config b/.nuget/NuGet.Config deleted file mode 100644 index 67f8ea0..0000000 --- a/.nuget/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.nuget/NuGet.exe b/.nuget/NuGet.exe deleted file mode 100644 index 8f61340..0000000 Binary files a/.nuget/NuGet.exe and /dev/null differ diff --git a/.nuget/NuGet.targets b/.nuget/NuGet.targets deleted file mode 100644 index 83fe906..0000000 --- a/.nuget/NuGet.targets +++ /dev/null @@ -1,136 +0,0 @@ - - - - $(MSBuildProjectDirectory)\..\ - - - false - - - false - - - true - - - false - - - - - - - - - - - $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) - $([System.IO.Path]::Combine($(ProjectDir), "packages.config")) - - - - - $(SolutionDir).nuget - packages.config - - - - - $(NuGetToolsPath)\NuGet.exe - @(PackageSource) - - "$(NuGetExePath)" - mono --runtime=v4.0.30319 $(NuGetExePath) - - $(TargetDir.Trim('\\')) - - -RequireConsent - -NonInteractive - - "$(SolutionDir) " - "$(SolutionDir)" - - - $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) - $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols - - - - RestorePackages; - $(BuildDependsOn); - - - - - $(BuildDependsOn); - BuildPackage; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/CronNET.sln b/CronNET.sln old mode 100755 new mode 100644 index c421a8b..08998ff --- a/CronNET.sln +++ b/CronNET.sln @@ -1,35 +1,31 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNET", "CronNET\CronNET.csproj", "{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNETTests", "CronNETTests\CronNETTests.csproj", "{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{EA4722C9-7FD3-4D8C-BA24-AAAFC5E52EAC}" - ProjectSection(SolutionItems) = preProject - .nuget\NuGet.Config = .nuget\NuGet.Config - .nuget\NuGet.exe = .nuget\NuGet.exe - .nuget\NuGet.targets = .nuget\NuGet.targets - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.Build.0 = Release|Any CPU - {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33027.164 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNET", "CronNET\CronNET.csproj", "{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNETTests", "CronNETTests\CronNETTests.csproj", "{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.Build.0 = Release|Any CPU + {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {8A9988C3-D0A6-46C6-832D-F2B609B90B79} + EndGlobalSection +EndGlobal diff --git a/CronNET.v12.suo b/CronNET.v12.suo deleted file mode 100644 index 48ab0dd..0000000 Binary files a/CronNET.v12.suo and /dev/null differ diff --git a/CronNET/CronDaemon.cs b/CronNET/CronDaemon.cs old mode 100755 new mode 100644 index ae612fd..7b91d94 --- a/CronNET/CronDaemon.cs +++ b/CronNET/CronDaemon.cs @@ -1,56 +1,56 @@ -using System; -using System.Collections.Generic; -using System.Timers; -using System.Threading; - -namespace CronNET -{ - public interface ICronDaemon - { - void AddJob(string schedule, ThreadStart action); - void Start(); - void Stop(); - } - - public class CronDaemon : ICronDaemon - { - private readonly System.Timers.Timer timer = new System.Timers.Timer(30000); - private readonly List cron_jobs = new List(); - private DateTime _last= DateTime.Now; - - public CronDaemon() - { - timer.AutoReset = true; - timer.Elapsed += timer_elapsed; - } - - public void AddJob(string schedule, ThreadStart action) - { - var cj = new CronJob(schedule, action); - cron_jobs.Add(cj); - } - - public void Start() - { - timer.Start(); - } - - public void Stop() - { - timer.Stop(); - - foreach (CronJob job in cron_jobs) - job.abort(); - } - - private void timer_elapsed(object sender, ElapsedEventArgs e) - { - if (DateTime.Now.Minute != _last.Minute) - { - _last = DateTime.Now; - foreach (ICronJob job in cron_jobs) - job.execute(DateTime.Now); - } - } - } -} +using System; +using System.Collections.Generic; +using System.Timers; +using System.Threading; + +namespace CronNET +{ + public interface ICronDaemon + { + void AddJob(string schedule, ThreadStart action); + void Start(); + void Stop(); + } + + public class CronDaemon : ICronDaemon + { + private readonly System.Timers.Timer timer = new System.Timers.Timer(30000); + private readonly List cron_jobs = new List(); + private DateTime _last= DateTime.Now; + + public CronDaemon() + { + timer.AutoReset = true; + timer.Elapsed += timer_elapsed; + } + + public void AddJob(string schedule, ThreadStart action) + { + var cj = new CronJob(schedule, action); + cron_jobs.Add(cj); + } + + public void Start() + { + timer.Start(); + } + + public void Stop() + { + timer.Stop(); + + foreach (CronJob job in cron_jobs) + job.abort(); + } + + private void timer_elapsed(object sender, ElapsedEventArgs e) + { + if (DateTime.Now.Minute != _last.Minute) + { + _last = DateTime.Now; + foreach (ICronJob job in cron_jobs) + job.execute(DateTime.Now); + } + } + } +} diff --git a/CronNET/CronJob.cs b/CronNET/CronJob.cs old mode 100755 new mode 100644 index 97f2b05..bfdbaf5 --- a/CronNET/CronJob.cs +++ b/CronNET/CronJob.cs @@ -1,47 +1,47 @@ -using System; -using System.Threading; - -namespace CronNET -{ - public interface ICronJob - { - void execute(DateTime date_time); - void abort(); - } - - public class CronJob : ICronJob - { - private readonly ICronSchedule _cron_schedule = new CronSchedule(); - private readonly ThreadStart _thread_start; - private Thread _thread; - - public CronJob(string schedule, ThreadStart thread_start) - { - _cron_schedule = new CronSchedule(schedule); - _thread_start = thread_start; - _thread = new Thread(thread_start); - } - - private object _lock = new object(); - public void execute(DateTime date_time) - { - lock (_lock) - { - if (!_cron_schedule.isTime(date_time)) - return; - - if (_thread.ThreadState == ThreadState.Running) - return; - - _thread = new Thread(_thread_start); - _thread.Start(); - } - } - - public void abort() - { - _thread.Abort(); - } - - } -} +using System; +using System.Threading; + +namespace CronNET +{ + public interface ICronJob + { + void execute(DateTime date_time); + void abort(); + } + + public class CronJob : ICronJob + { + private readonly ICronSchedule _cron_schedule = new CronSchedule(); + private readonly ThreadStart _thread_start; + private Thread _thread; + + public CronJob(string schedule, ThreadStart thread_start) + { + _cron_schedule = new CronSchedule(schedule); + _thread_start = thread_start; + _thread = new Thread(thread_start); + } + + private object _lock = new object(); + public void execute(DateTime date_time) + { + lock (_lock) + { + if (!_cron_schedule.isTime(date_time)) + return; + + if (_thread.ThreadState == ThreadState.Running) + return; + + _thread = new Thread(_thread_start); + _thread.Start(); + } + } + + public void abort() + { + _thread.Abort(); + } + + } +} diff --git a/CronNET/CronNET.csproj b/CronNET/CronNET.csproj old mode 100755 new mode 100644 index 62d75b3..4e4871a --- a/CronNET/CronNET.csproj +++ b/CronNET/CronNET.csproj @@ -1,56 +1,19 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {F31D7AF3-FDFA-44F1-9C63-305BAF11D002} - Library - Properties - Cron - Cron - v4.0 - - - - - 2.0 - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - + + + netstandard2.0;net40;net48;net5.0 + Library + CronNET + CronNET + Migrated from .NET 4.0 to .NET 5.0 + 8.0 + kevinkolyar, iminet + C# library for running cron jobs on .NET + Iminetsoft.CronNET + https://github.com/iminet/CronNET + https://github.com/iminet/CronNET + dotnet Cron Crondaemon Crontab + 8.0 + 8.0 + false + \ No newline at end of file diff --git a/CronNET/CronSchedule.cs b/CronNET/CronSchedule.cs old mode 100755 new mode 100644 index 5b6dfb6..3d1f8c8 --- a/CronNET/CronSchedule.cs +++ b/CronNET/CronSchedule.cs @@ -1,211 +1,211 @@ -using System; -using System.Collections.Generic; -using System.Text.RegularExpressions; - -namespace CronNET -{ - public interface ICronSchedule - { - bool isValid(string expression); - bool isTime(DateTime date_time); - } - - public class CronSchedule : ICronSchedule - { - #region Readonly Class Members - - readonly static Regex divided_regex = new Regex(@"(\*/\d+)"); - readonly static Regex range_regex = new Regex(@"(\d+\-\d+)\/?(\d+)?"); - readonly static Regex wild_regex = new Regex(@"(\*)"); - readonly static Regex list_regex = new Regex(@"(((\d+,)*\d+)+)"); - readonly static Regex validation_regex = new Regex(divided_regex + "|" + range_regex + "|" + wild_regex + "|" + list_regex); - - #endregion - - #region Private Instance Members - - private readonly string _expression; - public List minutes; - public List hours; - public List days_of_month; - public List months; - public List days_of_week; - - #endregion - - #region Public Constructors - - public CronSchedule() - { - } - - public CronSchedule(string expressions) - { - this._expression = expressions; - generate(); - } - - #endregion - - #region Public Methods - - private bool isValid() - { - return isValid(this._expression); - } - - public bool isValid(string expression) - { - MatchCollection matches = validation_regex.Matches(expression); - return matches.Count > 0;//== 5; - } - - public bool isTime(DateTime date_time) - { - return minutes.Contains(date_time.Minute) && - hours.Contains(date_time.Hour) && - days_of_month.Contains(date_time.Day) && - months.Contains(date_time.Month) && - days_of_week.Contains((int)date_time.DayOfWeek); - } - - private void generate() - { - if (!isValid()) return; - - MatchCollection matches = validation_regex.Matches(this._expression); - - generate_minutes(matches[0].ToString()); - - if (matches.Count > 1) - generate_hours(matches[1].ToString()); - else - generate_hours("*"); - - if (matches.Count > 2) - generate_days_of_month(matches[2].ToString()); - else - generate_days_of_month("*"); - - if (matches.Count > 3) - generate_months(matches[3].ToString()); - else - generate_months("*"); - - if (matches.Count > 4) - generate_days_of_weeks(matches[4].ToString()); - else - generate_days_of_weeks("*"); - } - - private void generate_minutes(string match) - { - this.minutes = generate_values(match, 0, 60); - } - - private void generate_hours(string match) - { - this.hours = generate_values(match, 0, 24); - } - - private void generate_days_of_month(string match) - { - this.days_of_month = generate_values(match, 1, 32); - } - - private void generate_months(string match) - { - this.months = generate_values(match, 1, 13); - } - - private void generate_days_of_weeks(string match) - { - this.days_of_week = generate_values(match, 0, 7); - } - - private List generate_values(string configuration, int start, int max) - { - if (divided_regex.IsMatch(configuration)) return divided_array(configuration, start, max); - if (range_regex.IsMatch(configuration)) return range_array(configuration); - if (wild_regex.IsMatch(configuration)) return wild_array(configuration, start, max); - if (list_regex.IsMatch(configuration)) return list_array(configuration); - - return new List(); - } - - private List divided_array(string configuration, int start, int max) - { - if (!divided_regex.IsMatch(configuration)) - return new List(); - - List ret = new List(); - string[] split = configuration.Split("/".ToCharArray()); - int divisor = int.Parse(split[1]); - - for (int i = start; i < max; ++i) - if (i % divisor == 0) - ret.Add(i); - - return ret; - } - - private List range_array(string configuration) - { - if (!range_regex.IsMatch(configuration)) - return new List(); - - List ret = new List(); - string[] split = configuration.Split("-".ToCharArray()); - int start = int.Parse(split[0]); - int end = 0; - if (split[1].Contains("/")) - { - split = split[1].Split("/".ToCharArray()); - end = int.Parse(split[0]); - int divisor = int.Parse(split[1]); - - for (int i = start; i < end; ++i) - if (i % divisor == 0) - ret.Add(i); - return ret; - } - else - end = int.Parse(split[1]); - - for (int i = start; i <= end; ++i) - ret.Add(i); - - return ret; - } - - private List wild_array(string configuration, int start, int max) - { - if (!wild_regex.IsMatch(configuration)) - return new List(); - - List ret = new List(); - - for (int i = start; i < max; ++i) - ret.Add(i); - - return ret; - } - - private List list_array(string configuration) - { - if (!list_regex.IsMatch(configuration)) - return new List(); - - List ret = new List(); - - string[] split = configuration.Split(",".ToCharArray()); - - foreach (string s in split) - ret.Add(int.Parse(s)); - - return ret; - } - - #endregion - } -} +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace CronNET +{ + public interface ICronSchedule + { + bool isValid(string expression); + bool isTime(DateTime date_time); + } + + public class CronSchedule : ICronSchedule + { + #region Readonly Class Members + + readonly static Regex divided_regex = new Regex(@"(\*/\d+)"); + readonly static Regex range_regex = new Regex(@"(\d+\-\d+)\/?(\d+)?"); + readonly static Regex wild_regex = new Regex(@"(\*)"); + readonly static Regex list_regex = new Regex(@"(((\d+,)*\d+)+)"); + readonly static Regex validation_regex = new Regex(divided_regex + "|" + range_regex + "|" + wild_regex + "|" + list_regex); + + #endregion + + #region Private Instance Members + + private readonly string _expression; + public List minutes; + public List hours; + public List days_of_month; + public List months; + public List days_of_week; + + #endregion + + #region Public Constructors + + public CronSchedule() + { + } + + public CronSchedule(string expressions) + { + this._expression = expressions; + generate(); + } + + #endregion + + #region Public Methods + + private bool isValid() + { + return isValid(this._expression); + } + + public bool isValid(string expression) + { + MatchCollection matches = validation_regex.Matches(expression); + return matches.Count > 0;//== 5; + } + + public bool isTime(DateTime date_time) + { + return minutes.Contains(date_time.Minute) && + hours.Contains(date_time.Hour) && + days_of_month.Contains(date_time.Day) && + months.Contains(date_time.Month) && + days_of_week.Contains((int)date_time.DayOfWeek); + } + + private void generate() + { + if (!isValid()) return; + + MatchCollection matches = validation_regex.Matches(this._expression); + + generate_minutes(matches[0].ToString()); + + if (matches.Count > 1) + generate_hours(matches[1].ToString()); + else + generate_hours("*"); + + if (matches.Count > 2) + generate_days_of_month(matches[2].ToString()); + else + generate_days_of_month("*"); + + if (matches.Count > 3) + generate_months(matches[3].ToString()); + else + generate_months("*"); + + if (matches.Count > 4) + generate_days_of_weeks(matches[4].ToString()); + else + generate_days_of_weeks("*"); + } + + private void generate_minutes(string match) + { + this.minutes = generate_values(match, 0, 60); + } + + private void generate_hours(string match) + { + this.hours = generate_values(match, 0, 24); + } + + private void generate_days_of_month(string match) + { + this.days_of_month = generate_values(match, 1, 32); + } + + private void generate_months(string match) + { + this.months = generate_values(match, 1, 13); + } + + private void generate_days_of_weeks(string match) + { + this.days_of_week = generate_values(match, 0, 7); + } + + private List generate_values(string configuration, int start, int max) + { + if (divided_regex.IsMatch(configuration)) return divided_array(configuration, start, max); + if (range_regex.IsMatch(configuration)) return range_array(configuration); + if (wild_regex.IsMatch(configuration)) return wild_array(configuration, start, max); + if (list_regex.IsMatch(configuration)) return list_array(configuration); + + return new List(); + } + + private List divided_array(string configuration, int start, int max) + { + if (!divided_regex.IsMatch(configuration)) + return new List(); + + List ret = new List(); + string[] split = configuration.Split("/".ToCharArray()); + int divisor = int.Parse(split[1]); + + for (int i = start; i < max; ++i) + if (i % divisor == 0) + ret.Add(i); + + return ret; + } + + private List range_array(string configuration) + { + if (!range_regex.IsMatch(configuration)) + return new List(); + + List ret = new List(); + string[] split = configuration.Split("-".ToCharArray()); + int start = int.Parse(split[0]); + int end = 0; + if (split[1].Contains("/")) + { + split = split[1].Split("/".ToCharArray()); + end = int.Parse(split[0]); + int divisor = int.Parse(split[1]); + + for (int i = start; i < end; ++i) + if (i % divisor == 0) + ret.Add(i); + return ret; + } + else + end = int.Parse(split[1]); + + for (int i = start; i <= end; ++i) + ret.Add(i); + + return ret; + } + + private List wild_array(string configuration, int start, int max) + { + if (!wild_regex.IsMatch(configuration)) + return new List(); + + List ret = new List(); + + for (int i = start; i < max; ++i) + ret.Add(i); + + return ret; + } + + private List list_array(string configuration) + { + if (!list_regex.IsMatch(configuration)) + return new List(); + + List ret = new List(); + + string[] split = configuration.Split(",".ToCharArray()); + + foreach (string s in split) + ret.Add(int.Parse(s)); + + return ret; + } + + #endregion + } +} diff --git a/CronNET/Properties/AssemblyInfo.cs b/CronNET/Properties/AssemblyInfo.cs old mode 100755 new mode 100644 index 5154305..6574035 --- a/CronNET/Properties/AssemblyInfo.cs +++ b/CronNET/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("CronNET")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CronNET")] -[assembly: AssemblyCopyright("Copyright © 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("aac36739-a1a8-433d-88f6-8834bbd6655f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.1")] -[assembly: AssemblyFileVersion("1.0.0.1")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CronNET")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CronNET")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("aac36739-a1a8-433d-88f6-8834bbd6655f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.1")] +[assembly: AssemblyFileVersion("1.0.0.1")] diff --git a/CronNETTests/CronNETTests.csproj b/CronNETTests/CronNETTests.csproj old mode 100755 new mode 100644 index c4c8dd0..46f99b5 --- a/CronNETTests/CronNETTests.csproj +++ b/CronNETTests/CronNETTests.csproj @@ -1,106 +1,106 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D} - Library - Properties - CronTests - CronTests - v4.0 - - - - - 2.0 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\NUnit.2.6.3\lib\nunit.framework.dll - - - - - - - - - - - - {F31D7AF3-FDFA-44F1-9C63-305BAF11D002} - CronNET - - - - - False - Microsoft .NET Framework 4 %28x86 and x64%29 - true - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - false - - - False - Windows Installer 3.1 - true - - - - - - - - + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {6FCFBDF4-ECB7-4FC2-A376-E962B11D487D} + Library + Properties + CronTests + CronTests + v4.0 + + + + + 2.0 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + ..\ + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NUnit.2.6.3\lib\nunit.framework.dll + + + + + + + + + + + + {F31D7AF3-FDFA-44F1-9C63-305BAF11D002} + CronNET + + + + + False + Microsoft .NET Framework 4 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 3.1 + true + + + + + + + + \ No newline at end of file diff --git a/CronNETTests/CronScheduleTests.cs b/CronNETTests/CronScheduleTests.cs old mode 100755 new mode 100644 index 58255ab..8fa0090 --- a/CronNETTests/CronScheduleTests.cs +++ b/CronNETTests/CronScheduleTests.cs @@ -1,192 +1,192 @@ -using System; -using System.Collections.Generic; -using CronNET; -using NUnit.Framework; -using System.Threading; - - -namespace CronTests -{ - [TestFixture] - public class CronScheduleTests - { - - [Test] - public void is_valid_test() - { - var cron_schedule = new CronSchedule(); - Assert.IsTrue(cron_schedule.isValid("*/2")); - Assert.IsTrue(cron_schedule.isValid("* * * * *")); - Assert.IsTrue(cron_schedule.isValid("0 * * * *")); - Assert.IsTrue(cron_schedule.isValid("0,1,2 * * * *")); - Assert.IsTrue(cron_schedule.isValid("*/2 * * * *")); - Assert.IsTrue(cron_schedule.isValid("1-4 * * * *")); - Assert.IsTrue(cron_schedule.isValid("1-55/3 * * * *")); - Assert.IsTrue(cron_schedule.isValid("1,10,20 * * * *")); - Assert.IsTrue(cron_schedule.isValid("* 1,10,20 * * *")); - } - - [Test] - public static void divided_array_test() - { - var cron_schedule = new CronSchedule("*/2"); - List results = cron_schedule.minutes.GetRange(0,5);//("*/2", 0, 10); - Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 }); - } - - [Test] - public static void range_array_test() - { - var cron_schedule = new CronSchedule("1-10"); - List results = cron_schedule.minutes.GetRange(0,10);//(); - Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); - var cs = new CronSchedule("1-10/3 20-45/4 * * *"); - results = cs.minutes; - Assert.AreEqual(results.ToArray(), new int[] { 3, 6, 9 }); - } - - [Test] - public void wild_array_test() - { - var cron_schedule = new CronSchedule("*"); - List results = cron_schedule.minutes.GetRange(0,10);//("*", 0, 10); - Assert.AreEqual(results.ToArray(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); - } - - [Test] - public void list_array_test() - { - var cron_schedule = new CronSchedule("1,2,3,4,5,6,7,8,9,10"); - List results = cron_schedule.minutes; - Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); - } - - [Test] - public void generate_values_divided_test() - { - var cron_schedule = new CronSchedule("*/2"); - List results = cron_schedule.minutes.GetRange(0,5);//(, 0, 10); - Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 }); - } - - [Test] - public void generate_values_range_test() - { - var cron_schedule = new CronSchedule("1-10"); - List results = cron_schedule.minutes.GetRange(0,10);//(, 0, 10); - Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); - } - - [Test] - public void generate_minutes_test() - { - var cron_schedule = new CronSchedule("1,2,3 * * * *"); - Assert.AreEqual(cron_schedule.minutes.ToArray(), new int[] { 1, 2, 3 }); - } - - [Test] - public void generate_hours_test() - { - var cron_schedule = new CronSchedule("* 1,2,3 * * *"); - Assert.AreEqual(cron_schedule.hours.ToArray(), new int[] { 1, 2, 3 }); - } - - [Test] - public void generate_days_of_month_test() - { - var cron_schedule = new CronSchedule("* * 1,2,3 * *"); - Assert.AreEqual(cron_schedule.days_of_month.ToArray(), new int[] { 1, 2, 3 }); - } - - [Test] - public void generate_months_test() - { - var cron_schedule = new CronSchedule("* * * 1,2,3 *"); - Assert.AreEqual(cron_schedule.months.ToArray(), new int[] { 1, 2, 3 }); - } - - [Test] - public void generate_days_of_weeks() - { - var cron_schedule = new CronSchedule("* * * * 1,2,3 "); - Assert.AreEqual(cron_schedule.days_of_week.ToArray(), new int[] { 1, 2, 3 }); - } - - [Test] - public void is_time_minute_test() - { - var cron_schedule = new CronSchedule("0 * * * *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am"))); - Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:01 am"))); - - cron_schedule = new CronSchedule("0-10 * * * *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am"))); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:03 am"))); - - cron_schedule = new CronSchedule("*/2 * * * *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am"))); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:02 am"))); - Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:03 am"))); - } - - [Test] - public void is_time_hour_test() - { - var cron_schedule = new CronSchedule("* 0 * * *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am"))); - - cron_schedule = new CronSchedule("* 0,12 * * *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am"))); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 pm"))); - } - - [Test] - public void is_time_day_of_month_test() - { - var cron_schedule = new CronSchedule("* * 1 * *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("2010/08/01"))); - } - - [Test] - public void is_time_month_test() - { - var cron_schedule = new CronSchedule("* * * 1 *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("1/1/2008"))); - - cron_schedule = new CronSchedule("* * * 12 *"); - Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("1/1/2008"))); - - cron_schedule = new CronSchedule("* * * */3 *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("3/1/2008"))); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("6/1/2008"))); - } - - [Test] - public void is_time_day_of_week_test() - { - var cron_schedule = new CronSchedule("* * * * 0"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/12/2008"))); - Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("10/13/2008"))); - - cron_schedule = new CronSchedule("* * * * */2"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/14/2008"))); - } - - [Test] - public void is_time_test() - { - var cron_schedule = new CronSchedule("0 0 12 10 *"); - Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00:00 am 10/12/2008"))); - Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("12:01:00 am 10/12/2008"))); - } - - [Test] - public static void ppp() - { - var d = new CronDaemon(); - d.AddJob("*/1 * * * *", () => { Console.WriteLine(DateTime.Now.ToString()); }); - d.Start(); - //Thread.Sleep(60 * 1000); - } - } -} +using System; +using System.Collections.Generic; +using CronNET; +using NUnit.Framework; +using System.Threading; + + +namespace CronTests +{ + [TestFixture] + public class CronScheduleTests + { + + [Test] + public void is_valid_test() + { + var cron_schedule = new CronSchedule(); + Assert.IsTrue(cron_schedule.isValid("*/2")); + Assert.IsTrue(cron_schedule.isValid("* * * * *")); + Assert.IsTrue(cron_schedule.isValid("0 * * * *")); + Assert.IsTrue(cron_schedule.isValid("0,1,2 * * * *")); + Assert.IsTrue(cron_schedule.isValid("*/2 * * * *")); + Assert.IsTrue(cron_schedule.isValid("1-4 * * * *")); + Assert.IsTrue(cron_schedule.isValid("1-55/3 * * * *")); + Assert.IsTrue(cron_schedule.isValid("1,10,20 * * * *")); + Assert.IsTrue(cron_schedule.isValid("* 1,10,20 * * *")); + } + + [Test] + public static void divided_array_test() + { + var cron_schedule = new CronSchedule("*/2"); + List results = cron_schedule.minutes.GetRange(0,5);//("*/2", 0, 10); + Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 }); + } + + [Test] + public static void range_array_test() + { + var cron_schedule = new CronSchedule("1-10"); + List results = cron_schedule.minutes.GetRange(0,10);//(); + Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + var cs = new CronSchedule("1-10/3 20-45/4 * * *"); + results = cs.minutes; + Assert.AreEqual(results.ToArray(), new int[] { 3, 6, 9 }); + } + + [Test] + public void wild_array_test() + { + var cron_schedule = new CronSchedule("*"); + List results = cron_schedule.minutes.GetRange(0,10);//("*", 0, 10); + Assert.AreEqual(results.ToArray(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }); + } + + [Test] + public void list_array_test() + { + var cron_schedule = new CronSchedule("1,2,3,4,5,6,7,8,9,10"); + List results = cron_schedule.minutes; + Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + } + + [Test] + public void generate_values_divided_test() + { + var cron_schedule = new CronSchedule("*/2"); + List results = cron_schedule.minutes.GetRange(0,5);//(, 0, 10); + Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 }); + } + + [Test] + public void generate_values_range_test() + { + var cron_schedule = new CronSchedule("1-10"); + List results = cron_schedule.minutes.GetRange(0,10);//(, 0, 10); + Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); + } + + [Test] + public void generate_minutes_test() + { + var cron_schedule = new CronSchedule("1,2,3 * * * *"); + Assert.AreEqual(cron_schedule.minutes.ToArray(), new int[] { 1, 2, 3 }); + } + + [Test] + public void generate_hours_test() + { + var cron_schedule = new CronSchedule("* 1,2,3 * * *"); + Assert.AreEqual(cron_schedule.hours.ToArray(), new int[] { 1, 2, 3 }); + } + + [Test] + public void generate_days_of_month_test() + { + var cron_schedule = new CronSchedule("* * 1,2,3 * *"); + Assert.AreEqual(cron_schedule.days_of_month.ToArray(), new int[] { 1, 2, 3 }); + } + + [Test] + public void generate_months_test() + { + var cron_schedule = new CronSchedule("* * * 1,2,3 *"); + Assert.AreEqual(cron_schedule.months.ToArray(), new int[] { 1, 2, 3 }); + } + + [Test] + public void generate_days_of_weeks() + { + var cron_schedule = new CronSchedule("* * * * 1,2,3 "); + Assert.AreEqual(cron_schedule.days_of_week.ToArray(), new int[] { 1, 2, 3 }); + } + + [Test] + public void is_time_minute_test() + { + var cron_schedule = new CronSchedule("0 * * * *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am"))); + Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:01 am"))); + + cron_schedule = new CronSchedule("0-10 * * * *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am"))); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:03 am"))); + + cron_schedule = new CronSchedule("*/2 * * * *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am"))); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:02 am"))); + Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:03 am"))); + } + + [Test] + public void is_time_hour_test() + { + var cron_schedule = new CronSchedule("* 0 * * *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am"))); + + cron_schedule = new CronSchedule("* 0,12 * * *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am"))); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 pm"))); + } + + [Test] + public void is_time_day_of_month_test() + { + var cron_schedule = new CronSchedule("* * 1 * *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("2010/08/01"))); + } + + [Test] + public void is_time_month_test() + { + var cron_schedule = new CronSchedule("* * * 1 *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("1/1/2008"))); + + cron_schedule = new CronSchedule("* * * 12 *"); + Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("1/1/2008"))); + + cron_schedule = new CronSchedule("* * * */3 *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("3/1/2008"))); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("6/1/2008"))); + } + + [Test] + public void is_time_day_of_week_test() + { + var cron_schedule = new CronSchedule("* * * * 0"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/12/2008"))); + Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("10/13/2008"))); + + cron_schedule = new CronSchedule("* * * * */2"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/14/2008"))); + } + + [Test] + public void is_time_test() + { + var cron_schedule = new CronSchedule("0 0 12 10 *"); + Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00:00 am 10/12/2008"))); + Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("12:01:00 am 10/12/2008"))); + } + + [Test] + public static void ppp() + { + var d = new CronDaemon(); + d.AddJob("*/1 * * * *", () => { Console.WriteLine(DateTime.Now.ToString()); }); + d.Start(); + //Thread.Sleep(60 * 1000); + } + } +} diff --git a/CronNETTests/Properties/AssemblyInfo.cs b/CronNETTests/Properties/AssemblyInfo.cs old mode 100755 new mode 100644 index dafa720..9d77dc5 --- a/CronNETTests/Properties/AssemblyInfo.cs +++ b/CronNETTests/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("CronNETTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("CronNETTests")] -[assembly: AssemblyCopyright("Copyright © 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("6a430089-ab18-4d72-9d7a-5a4ee0883153")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CronNETTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CronNETTests")] +[assembly: AssemblyCopyright("Copyright © 2008")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6a430089-ab18-4d72-9d7a-5a4ee0883153")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CronTests.nunit b/CronTests.nunit old mode 100755 new mode 100644 index 891baaa..b24270a --- a/CronTests.nunit +++ b/CronTests.nunit @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/Readme.md b/Readme.md index a33991f..200dd4d 100644 --- a/Readme.md +++ b/Readme.md @@ -29,6 +29,11 @@ CronNET supports most cron scheduling. See tests for supported formats. `* 1,10,20 * * *` Every 1st, 10th, and 20th hours. ``` +How to install? +=============== + +You can install this [NuGet package](https://www.nuget.org/packages/Iminetsoft.CronNET) + Console Example ===============