Gitignore updates

This commit is contained in:
Imre Kincses
2023-03-17 11:18:11 +01:00
parent d2b6759998
commit fbb28e4fe4
15 changed files with 778 additions and 918 deletions

112
CronNET/CronDaemon.cs Executable file → Normal file
View File

@@ -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<ICronJob> cron_jobs = new List<ICronJob>();
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<ICronJob> cron_jobs = new List<ICronJob>();
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);
}
}
}
}

94
CronNET/CronJob.cs Executable file → Normal file
View File

@@ -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();
}
}
}

110
CronNET/CronNET.csproj Executable file → Normal file
View File

@@ -1,56 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cron</RootNamespace>
<AssemblyName>Cron</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CronDaemon.cs" />
<Compile Include="CronJob.cs" />
<Compile Include="CronSchedule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cron</RootNamespace>
<AssemblyName>Cron</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>2.0</OldToolsVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CronDaemon.cs" />
<Compile Include="CronJob.cs" />
<Compile Include="CronSchedule.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

422
CronNET/CronSchedule.cs Executable file → Normal file
View File

@@ -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<int> minutes;
public List<int> hours;
public List<int> days_of_month;
public List<int> months;
public List<int> 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<int> 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<int>();
}
private List<int> divided_array(string configuration, int start, int max)
{
if (!divided_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
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<int> range_array(string configuration)
{
if (!range_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
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<int> wild_array(string configuration, int start, int max)
{
if (!wild_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
for (int i = start; i < max; ++i)
ret.Add(i);
return ret;
}
private List<int> list_array(string configuration)
{
if (!list_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
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<int> minutes;
public List<int> hours;
public List<int> days_of_month;
public List<int> months;
public List<int> 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<int> 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<int>();
}
private List<int> divided_array(string configuration, int start, int max)
{
if (!divided_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
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<int> range_array(string configuration)
{
if (!range_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
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<int> wild_array(string configuration, int start, int max)
{
if (!wild_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
for (int i = start; i < max; ++i)
ret.Add(i);
return ret;
}
private List<int> list_array(string configuration)
{
if (!list_regex.IsMatch(configuration))
return new List<int>();
List<int> ret = new List<int>();
string[] split = configuration.Split(",".ToCharArray());
foreach (string s in split)
ret.Add(int.Parse(s));
return ret;
}
#endregion
}
}

70
CronNET/Properties/AssemblyInfo.cs Executable file → Normal file
View File

@@ -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")]