mirror of
https://github.com/kevincolyar/CronNET.git
synced 2024-12-21 20:42:38 +01:00
Merge pull request #13 from iminet/master
Added .NET 5.0 support & uploaded to Nuget.org
This commit is contained in:
commit
f1dd5c68ca
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -68,6 +68,8 @@ local.properties
|
||||||
*.vspscc
|
*.vspscc
|
||||||
.builds
|
.builds
|
||||||
*.dotCover
|
*.dotCover
|
||||||
|
.[vV][sS]/
|
||||||
|
.[nN]uget/
|
||||||
|
|
||||||
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
## TODO: If you have NuGet Package Restore enabled, uncomment this
|
||||||
packages/
|
packages/
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<configuration>
|
|
||||||
<solution>
|
|
||||||
<add key="disableSourceControlIntegration" value="true" />
|
|
||||||
</solution>
|
|
||||||
</configuration>
|
|
BIN
.nuget/NuGet.exe
BIN
.nuget/NuGet.exe
Binary file not shown.
|
@ -1,136 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup>
|
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
|
|
||||||
|
|
||||||
<!-- Enable the restore command to run before builds -->
|
|
||||||
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
|
|
||||||
|
|
||||||
<!-- Property that enables building a package from a project -->
|
|
||||||
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
|
|
||||||
|
|
||||||
<!-- Determines if package restore consent is required to restore packages -->
|
|
||||||
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
|
|
||||||
|
|
||||||
<!-- Download NuGet.exe if it does not already exist -->
|
|
||||||
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(PackageSources)' == '' ">
|
|
||||||
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
|
|
||||||
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
|
|
||||||
<!--
|
|
||||||
<PackageSource Include="https://www.nuget.org/api/v2/" />
|
|
||||||
<PackageSource Include="https://my-nuget-source/nuget/" />
|
|
||||||
-->
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
|
|
||||||
<!-- Windows specific commands -->
|
|
||||||
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
|
|
||||||
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
|
|
||||||
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
|
|
||||||
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
|
|
||||||
<PackagesConfig>packages.config</PackagesConfig>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<!-- NuGet command -->
|
|
||||||
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
|
|
||||||
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
|
|
||||||
|
|
||||||
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
|
|
||||||
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
|
|
||||||
|
|
||||||
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
|
|
||||||
|
|
||||||
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
|
|
||||||
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
|
|
||||||
|
|
||||||
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
|
|
||||||
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
|
|
||||||
|
|
||||||
<!-- Commands -->
|
|
||||||
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
|
|
||||||
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>
|
|
||||||
|
|
||||||
<!-- We need to ensure packages are restored prior to assembly resolve -->
|
|
||||||
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
|
|
||||||
RestorePackages;
|
|
||||||
$(BuildDependsOn);
|
|
||||||
</BuildDependsOn>
|
|
||||||
|
|
||||||
<!-- Make the build depend on restore packages -->
|
|
||||||
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
|
|
||||||
$(BuildDependsOn);
|
|
||||||
BuildPackage;
|
|
||||||
</BuildDependsOn>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<Target Name="CheckPrerequisites">
|
|
||||||
<!-- Raise an error if we're unable to locate nuget.exe -->
|
|
||||||
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
|
|
||||||
<!--
|
|
||||||
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
|
|
||||||
This effectively acts as a lock that makes sure that the download operation will only happen once and all
|
|
||||||
parallel builds will have to wait for it to complete.
|
|
||||||
-->
|
|
||||||
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<Target Name="_DownloadNuGet">
|
|
||||||
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
|
|
||||||
<Exec Command="$(RestoreCommand)"
|
|
||||||
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
|
|
||||||
|
|
||||||
<Exec Command="$(RestoreCommand)"
|
|
||||||
LogStandardErrorAsError="true"
|
|
||||||
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
|
|
||||||
<Exec Command="$(BuildCommand)"
|
|
||||||
Condition=" '$(OS)' != 'Windows_NT' " />
|
|
||||||
|
|
||||||
<Exec Command="$(BuildCommand)"
|
|
||||||
LogStandardErrorAsError="true"
|
|
||||||
Condition=" '$(OS)' == 'Windows_NT' " />
|
|
||||||
</Target>
|
|
||||||
|
|
||||||
<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
|
|
||||||
<ParameterGroup>
|
|
||||||
<OutputFilename ParameterType="System.String" Required="true" />
|
|
||||||
</ParameterGroup>
|
|
||||||
<Task>
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Using Namespace="System" />
|
|
||||||
<Using Namespace="System.IO" />
|
|
||||||
<Using Namespace="System.Net" />
|
|
||||||
<Using Namespace="Microsoft.Build.Framework" />
|
|
||||||
<Using Namespace="Microsoft.Build.Utilities" />
|
|
||||||
<Code Type="Fragment" Language="cs">
|
|
||||||
<![CDATA[
|
|
||||||
try {
|
|
||||||
OutputFilename = Path.GetFullPath(OutputFilename);
|
|
||||||
|
|
||||||
Log.LogMessage("Downloading latest version of NuGet.exe...");
|
|
||||||
WebClient webClient = new WebClient();
|
|
||||||
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
Log.LogErrorFromException(ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
]]>
|
|
||||||
</Code>
|
|
||||||
</Task>
|
|
||||||
</UsingTask>
|
|
||||||
</Project>
|
|
66
CronNET.sln
Executable file → Normal file
66
CronNET.sln
Executable file → Normal file
|
@ -1,35 +1,31 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2013
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 12.0.21005.1
|
VisualStudioVersion = 16.0.33027.164
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNET", "CronNET\CronNET.csproj", "{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNET", "CronNET\CronNET.csproj", "{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNETTests", "CronNETTests\CronNETTests.csproj", "{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CronNETTests", "CronNETTests\CronNETTests.csproj", "{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{EA4722C9-7FD3-4D8C-BA24-AAAFC5E52EAC}"
|
Global
|
||||||
ProjectSection(SolutionItems) = preProject
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
.nuget\NuGet.Config = .nuget\NuGet.Config
|
Debug|Any CPU = Debug|Any CPU
|
||||||
.nuget\NuGet.exe = .nuget\NuGet.exe
|
Release|Any CPU = Release|Any CPU
|
||||||
.nuget\NuGet.targets = .nuget\NuGet.targets
|
EndGlobalSection
|
||||||
EndProjectSection
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
EndProject
|
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
Global
|
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
Debug|Any CPU = Debug|Any CPU
|
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
Release|Any CPU = Release|Any CPU
|
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
EndGlobalSection
|
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
EndGlobalSection
|
||||||
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}.Release|Any CPU.Build.0 = Release|Any CPU
|
HideSolutionNode = FALSE
|
||||||
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
EndGlobalSection
|
||||||
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
SolutionGuid = {8A9988C3-D0A6-46C6-832D-F2B609B90B79}
|
||||||
{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}.Release|Any CPU.Build.0 = Release|Any CPU
|
EndGlobalSection
|
||||||
EndGlobalSection
|
EndGlobal
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
|
|
BIN
CronNET.v12.suo
BIN
CronNET.v12.suo
Binary file not shown.
112
CronNET/CronDaemon.cs
Executable file → Normal file
112
CronNET/CronDaemon.cs
Executable file → Normal file
|
@ -1,56 +1,56 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace CronNET
|
namespace CronNET
|
||||||
{
|
{
|
||||||
public interface ICronDaemon
|
public interface ICronDaemon
|
||||||
{
|
{
|
||||||
void AddJob(string schedule, ThreadStart action);
|
void AddJob(string schedule, ThreadStart action);
|
||||||
void Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CronDaemon : ICronDaemon
|
public class CronDaemon : ICronDaemon
|
||||||
{
|
{
|
||||||
private readonly System.Timers.Timer timer = new System.Timers.Timer(30000);
|
private readonly System.Timers.Timer timer = new System.Timers.Timer(30000);
|
||||||
private readonly List<ICronJob> cron_jobs = new List<ICronJob>();
|
private readonly List<ICronJob> cron_jobs = new List<ICronJob>();
|
||||||
private DateTime _last= DateTime.Now;
|
private DateTime _last= DateTime.Now;
|
||||||
|
|
||||||
public CronDaemon()
|
public CronDaemon()
|
||||||
{
|
{
|
||||||
timer.AutoReset = true;
|
timer.AutoReset = true;
|
||||||
timer.Elapsed += timer_elapsed;
|
timer.Elapsed += timer_elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddJob(string schedule, ThreadStart action)
|
public void AddJob(string schedule, ThreadStart action)
|
||||||
{
|
{
|
||||||
var cj = new CronJob(schedule, action);
|
var cj = new CronJob(schedule, action);
|
||||||
cron_jobs.Add(cj);
|
cron_jobs.Add(cj);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
timer.Start();
|
timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
|
|
||||||
foreach (CronJob job in cron_jobs)
|
foreach (CronJob job in cron_jobs)
|
||||||
job.abort();
|
job.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void timer_elapsed(object sender, ElapsedEventArgs e)
|
private void timer_elapsed(object sender, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
if (DateTime.Now.Minute != _last.Minute)
|
if (DateTime.Now.Minute != _last.Minute)
|
||||||
{
|
{
|
||||||
_last = DateTime.Now;
|
_last = DateTime.Now;
|
||||||
foreach (ICronJob job in cron_jobs)
|
foreach (ICronJob job in cron_jobs)
|
||||||
job.execute(DateTime.Now);
|
job.execute(DateTime.Now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
94
CronNET/CronJob.cs
Executable file → Normal file
94
CronNET/CronJob.cs
Executable file → Normal file
|
@ -1,47 +1,47 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace CronNET
|
namespace CronNET
|
||||||
{
|
{
|
||||||
public interface ICronJob
|
public interface ICronJob
|
||||||
{
|
{
|
||||||
void execute(DateTime date_time);
|
void execute(DateTime date_time);
|
||||||
void abort();
|
void abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CronJob : ICronJob
|
public class CronJob : ICronJob
|
||||||
{
|
{
|
||||||
private readonly ICronSchedule _cron_schedule = new CronSchedule();
|
private readonly ICronSchedule _cron_schedule = new CronSchedule();
|
||||||
private readonly ThreadStart _thread_start;
|
private readonly ThreadStart _thread_start;
|
||||||
private Thread _thread;
|
private Thread _thread;
|
||||||
|
|
||||||
public CronJob(string schedule, ThreadStart thread_start)
|
public CronJob(string schedule, ThreadStart thread_start)
|
||||||
{
|
{
|
||||||
_cron_schedule = new CronSchedule(schedule);
|
_cron_schedule = new CronSchedule(schedule);
|
||||||
_thread_start = thread_start;
|
_thread_start = thread_start;
|
||||||
_thread = new Thread(thread_start);
|
_thread = new Thread(thread_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
private object _lock = new object();
|
private object _lock = new object();
|
||||||
public void execute(DateTime date_time)
|
public void execute(DateTime date_time)
|
||||||
{
|
{
|
||||||
lock (_lock)
|
lock (_lock)
|
||||||
{
|
{
|
||||||
if (!_cron_schedule.isTime(date_time))
|
if (!_cron_schedule.isTime(date_time))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_thread.ThreadState == ThreadState.Running)
|
if (_thread.ThreadState == ThreadState.Running)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_thread = new Thread(_thread_start);
|
_thread = new Thread(_thread_start);
|
||||||
_thread.Start();
|
_thread.Start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void abort()
|
public void abort()
|
||||||
{
|
{
|
||||||
_thread.Abort();
|
_thread.Abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
73
CronNET/CronNET.csproj
Executable file → Normal file
73
CronNET/CronNET.csproj
Executable file → Normal file
|
@ -1,56 +1,19 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
<PropertyGroup>
|
||||||
<PropertyGroup>
|
<TargetFrameworks>netstandard2.0;net40;net48;net5.0</TargetFrameworks>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<OutputType>Library</OutputType>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<RootNamespace>CronNET</RootNamespace>
|
||||||
<ProductVersion>8.0.50727</ProductVersion>
|
<AssemblyName>CronNET</AssemblyName>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<PackageReleaseNotes>Migrated from .NET 4.0 to .NET 5.0</PackageReleaseNotes>
|
||||||
<ProjectGuid>{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}</ProjectGuid>
|
<Version>8.0</Version>
|
||||||
<OutputType>Library</OutputType>
|
<Authors>kevinkolyar, iminet</Authors>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<Product>C# library for running cron jobs on .NET</Product>
|
||||||
<RootNamespace>Cron</RootNamespace>
|
<PackageId>Iminetsoft.CronNET</PackageId>
|
||||||
<AssemblyName>Cron</AssemblyName>
|
<PackageProjectUrl>https://github.com/iminet/CronNET</PackageProjectUrl>
|
||||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
<RepositoryUrl>https://github.com/iminet/CronNET</RepositoryUrl>
|
||||||
<FileUpgradeFlags>
|
<PackageTags>dotnet Cron Crondaemon Crontab</PackageTags>
|
||||||
</FileUpgradeFlags>
|
<AssemblyVersion>8.0</AssemblyVersion>
|
||||||
<UpgradeBackupLocation>
|
<FileVersion>8.0</FileVersion>
|
||||||
</UpgradeBackupLocation>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<OldToolsVersion>2.0</OldToolsVersion>
|
</PropertyGroup>
|
||||||
</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>
|
</Project>
|
422
CronNET/CronSchedule.cs
Executable file → Normal file
422
CronNET/CronSchedule.cs
Executable file → Normal file
|
@ -1,211 +1,211 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace CronNET
|
namespace CronNET
|
||||||
{
|
{
|
||||||
public interface ICronSchedule
|
public interface ICronSchedule
|
||||||
{
|
{
|
||||||
bool isValid(string expression);
|
bool isValid(string expression);
|
||||||
bool isTime(DateTime date_time);
|
bool isTime(DateTime date_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CronSchedule : ICronSchedule
|
public class CronSchedule : ICronSchedule
|
||||||
{
|
{
|
||||||
#region Readonly Class Members
|
#region Readonly Class Members
|
||||||
|
|
||||||
readonly static Regex divided_regex = new Regex(@"(\*/\d+)");
|
readonly static Regex divided_regex = new Regex(@"(\*/\d+)");
|
||||||
readonly static Regex range_regex = new Regex(@"(\d+\-\d+)\/?(\d+)?");
|
readonly static Regex range_regex = new Regex(@"(\d+\-\d+)\/?(\d+)?");
|
||||||
readonly static Regex wild_regex = new Regex(@"(\*)");
|
readonly static Regex wild_regex = new Regex(@"(\*)");
|
||||||
readonly static Regex list_regex = new Regex(@"(((\d+,)*\d+)+)");
|
readonly static Regex list_regex = new Regex(@"(((\d+,)*\d+)+)");
|
||||||
readonly static Regex validation_regex = new Regex(divided_regex + "|" + range_regex + "|" + wild_regex + "|" + list_regex);
|
readonly static Regex validation_regex = new Regex(divided_regex + "|" + range_regex + "|" + wild_regex + "|" + list_regex);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private Instance Members
|
#region Private Instance Members
|
||||||
|
|
||||||
private readonly string _expression;
|
private readonly string _expression;
|
||||||
public List<int> minutes;
|
public List<int> minutes;
|
||||||
public List<int> hours;
|
public List<int> hours;
|
||||||
public List<int> days_of_month;
|
public List<int> days_of_month;
|
||||||
public List<int> months;
|
public List<int> months;
|
||||||
public List<int> days_of_week;
|
public List<int> days_of_week;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Constructors
|
#region Public Constructors
|
||||||
|
|
||||||
public CronSchedule()
|
public CronSchedule()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public CronSchedule(string expressions)
|
public CronSchedule(string expressions)
|
||||||
{
|
{
|
||||||
this._expression = expressions;
|
this._expression = expressions;
|
||||||
generate();
|
generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
private bool isValid()
|
private bool isValid()
|
||||||
{
|
{
|
||||||
return isValid(this._expression);
|
return isValid(this._expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isValid(string expression)
|
public bool isValid(string expression)
|
||||||
{
|
{
|
||||||
MatchCollection matches = validation_regex.Matches(expression);
|
MatchCollection matches = validation_regex.Matches(expression);
|
||||||
return matches.Count > 0;//== 5;
|
return matches.Count > 0;//== 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isTime(DateTime date_time)
|
public bool isTime(DateTime date_time)
|
||||||
{
|
{
|
||||||
return minutes.Contains(date_time.Minute) &&
|
return minutes.Contains(date_time.Minute) &&
|
||||||
hours.Contains(date_time.Hour) &&
|
hours.Contains(date_time.Hour) &&
|
||||||
days_of_month.Contains(date_time.Day) &&
|
days_of_month.Contains(date_time.Day) &&
|
||||||
months.Contains(date_time.Month) &&
|
months.Contains(date_time.Month) &&
|
||||||
days_of_week.Contains((int)date_time.DayOfWeek);
|
days_of_week.Contains((int)date_time.DayOfWeek);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate()
|
private void generate()
|
||||||
{
|
{
|
||||||
if (!isValid()) return;
|
if (!isValid()) return;
|
||||||
|
|
||||||
MatchCollection matches = validation_regex.Matches(this._expression);
|
MatchCollection matches = validation_regex.Matches(this._expression);
|
||||||
|
|
||||||
generate_minutes(matches[0].ToString());
|
generate_minutes(matches[0].ToString());
|
||||||
|
|
||||||
if (matches.Count > 1)
|
if (matches.Count > 1)
|
||||||
generate_hours(matches[1].ToString());
|
generate_hours(matches[1].ToString());
|
||||||
else
|
else
|
||||||
generate_hours("*");
|
generate_hours("*");
|
||||||
|
|
||||||
if (matches.Count > 2)
|
if (matches.Count > 2)
|
||||||
generate_days_of_month(matches[2].ToString());
|
generate_days_of_month(matches[2].ToString());
|
||||||
else
|
else
|
||||||
generate_days_of_month("*");
|
generate_days_of_month("*");
|
||||||
|
|
||||||
if (matches.Count > 3)
|
if (matches.Count > 3)
|
||||||
generate_months(matches[3].ToString());
|
generate_months(matches[3].ToString());
|
||||||
else
|
else
|
||||||
generate_months("*");
|
generate_months("*");
|
||||||
|
|
||||||
if (matches.Count > 4)
|
if (matches.Count > 4)
|
||||||
generate_days_of_weeks(matches[4].ToString());
|
generate_days_of_weeks(matches[4].ToString());
|
||||||
else
|
else
|
||||||
generate_days_of_weeks("*");
|
generate_days_of_weeks("*");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate_minutes(string match)
|
private void generate_minutes(string match)
|
||||||
{
|
{
|
||||||
this.minutes = generate_values(match, 0, 60);
|
this.minutes = generate_values(match, 0, 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate_hours(string match)
|
private void generate_hours(string match)
|
||||||
{
|
{
|
||||||
this.hours = generate_values(match, 0, 24);
|
this.hours = generate_values(match, 0, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate_days_of_month(string match)
|
private void generate_days_of_month(string match)
|
||||||
{
|
{
|
||||||
this.days_of_month = generate_values(match, 1, 32);
|
this.days_of_month = generate_values(match, 1, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate_months(string match)
|
private void generate_months(string match)
|
||||||
{
|
{
|
||||||
this.months = generate_values(match, 1, 13);
|
this.months = generate_values(match, 1, 13);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generate_days_of_weeks(string match)
|
private void generate_days_of_weeks(string match)
|
||||||
{
|
{
|
||||||
this.days_of_week = generate_values(match, 0, 7);
|
this.days_of_week = generate_values(match, 0, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> generate_values(string configuration, int start, int max)
|
private List<int> generate_values(string configuration, int start, int max)
|
||||||
{
|
{
|
||||||
if (divided_regex.IsMatch(configuration)) return divided_array(configuration, start, max);
|
if (divided_regex.IsMatch(configuration)) return divided_array(configuration, start, max);
|
||||||
if (range_regex.IsMatch(configuration)) return range_array(configuration);
|
if (range_regex.IsMatch(configuration)) return range_array(configuration);
|
||||||
if (wild_regex.IsMatch(configuration)) return wild_array(configuration, start, max);
|
if (wild_regex.IsMatch(configuration)) return wild_array(configuration, start, max);
|
||||||
if (list_regex.IsMatch(configuration)) return list_array(configuration);
|
if (list_regex.IsMatch(configuration)) return list_array(configuration);
|
||||||
|
|
||||||
return new List<int>();
|
return new List<int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> divided_array(string configuration, int start, int max)
|
private List<int> divided_array(string configuration, int start, int max)
|
||||||
{
|
{
|
||||||
if (!divided_regex.IsMatch(configuration))
|
if (!divided_regex.IsMatch(configuration))
|
||||||
return new List<int>();
|
return new List<int>();
|
||||||
|
|
||||||
List<int> ret = new List<int>();
|
List<int> ret = new List<int>();
|
||||||
string[] split = configuration.Split("/".ToCharArray());
|
string[] split = configuration.Split("/".ToCharArray());
|
||||||
int divisor = int.Parse(split[1]);
|
int divisor = int.Parse(split[1]);
|
||||||
|
|
||||||
for (int i = start; i < max; ++i)
|
for (int i = start; i < max; ++i)
|
||||||
if (i % divisor == 0)
|
if (i % divisor == 0)
|
||||||
ret.Add(i);
|
ret.Add(i);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> range_array(string configuration)
|
private List<int> range_array(string configuration)
|
||||||
{
|
{
|
||||||
if (!range_regex.IsMatch(configuration))
|
if (!range_regex.IsMatch(configuration))
|
||||||
return new List<int>();
|
return new List<int>();
|
||||||
|
|
||||||
List<int> ret = new List<int>();
|
List<int> ret = new List<int>();
|
||||||
string[] split = configuration.Split("-".ToCharArray());
|
string[] split = configuration.Split("-".ToCharArray());
|
||||||
int start = int.Parse(split[0]);
|
int start = int.Parse(split[0]);
|
||||||
int end = 0;
|
int end = 0;
|
||||||
if (split[1].Contains("/"))
|
if (split[1].Contains("/"))
|
||||||
{
|
{
|
||||||
split = split[1].Split("/".ToCharArray());
|
split = split[1].Split("/".ToCharArray());
|
||||||
end = int.Parse(split[0]);
|
end = int.Parse(split[0]);
|
||||||
int divisor = int.Parse(split[1]);
|
int divisor = int.Parse(split[1]);
|
||||||
|
|
||||||
for (int i = start; i < end; ++i)
|
for (int i = start; i < end; ++i)
|
||||||
if (i % divisor == 0)
|
if (i % divisor == 0)
|
||||||
ret.Add(i);
|
ret.Add(i);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
end = int.Parse(split[1]);
|
end = int.Parse(split[1]);
|
||||||
|
|
||||||
for (int i = start; i <= end; ++i)
|
for (int i = start; i <= end; ++i)
|
||||||
ret.Add(i);
|
ret.Add(i);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> wild_array(string configuration, int start, int max)
|
private List<int> wild_array(string configuration, int start, int max)
|
||||||
{
|
{
|
||||||
if (!wild_regex.IsMatch(configuration))
|
if (!wild_regex.IsMatch(configuration))
|
||||||
return new List<int>();
|
return new List<int>();
|
||||||
|
|
||||||
List<int> ret = new List<int>();
|
List<int> ret = new List<int>();
|
||||||
|
|
||||||
for (int i = start; i < max; ++i)
|
for (int i = start; i < max; ++i)
|
||||||
ret.Add(i);
|
ret.Add(i);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<int> list_array(string configuration)
|
private List<int> list_array(string configuration)
|
||||||
{
|
{
|
||||||
if (!list_regex.IsMatch(configuration))
|
if (!list_regex.IsMatch(configuration))
|
||||||
return new List<int>();
|
return new List<int>();
|
||||||
|
|
||||||
List<int> ret = new List<int>();
|
List<int> ret = new List<int>();
|
||||||
|
|
||||||
string[] split = configuration.Split(",".ToCharArray());
|
string[] split = configuration.Split(",".ToCharArray());
|
||||||
|
|
||||||
foreach (string s in split)
|
foreach (string s in split)
|
||||||
ret.Add(int.Parse(s));
|
ret.Add(int.Parse(s));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
70
CronNET/Properties/AssemblyInfo.cs
Executable file → Normal file
70
CronNET/Properties/AssemblyInfo.cs
Executable file → Normal file
|
@ -1,35 +1,35 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("CronNET")]
|
[assembly: AssemblyTitle("CronNET")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("CronNET")]
|
[assembly: AssemblyProduct("CronNET")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2008")]
|
[assembly: AssemblyCopyright("Copyright © 2008")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// 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
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("aac36739-a1a8-433d-88f6-8834bbd6655f")]
|
[assembly: Guid("aac36739-a1a8-433d-88f6-8834bbd6655f")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
//
|
//
|
||||||
// Major Version
|
// Major Version
|
||||||
// Minor Version
|
// Minor Version
|
||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.0.0.1")]
|
[assembly: AssemblyVersion("1.0.0.1")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.1")]
|
[assembly: AssemblyFileVersion("1.0.0.1")]
|
||||||
|
|
210
CronNETTests/CronNETTests.csproj
Executable file → Normal file
210
CronNETTests/CronNETTests.csproj
Executable file → Normal file
|
@ -1,106 +1,106 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProductVersion>8.0.50727</ProductVersion>
|
<ProductVersion>8.0.50727</ProductVersion>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}</ProjectGuid>
|
<ProjectGuid>{6FCFBDF4-ECB7-4FC2-A376-E962B11D487D}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>CronTests</RootNamespace>
|
<RootNamespace>CronTests</RootNamespace>
|
||||||
<AssemblyName>CronTests</AssemblyName>
|
<AssemblyName>CronTests</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<FileUpgradeFlags>
|
<FileUpgradeFlags>
|
||||||
</FileUpgradeFlags>
|
</FileUpgradeFlags>
|
||||||
<UpgradeBackupLocation>
|
<UpgradeBackupLocation>
|
||||||
</UpgradeBackupLocation>
|
</UpgradeBackupLocation>
|
||||||
<OldToolsVersion>2.0</OldToolsVersion>
|
<OldToolsVersion>2.0</OldToolsVersion>
|
||||||
<PublishUrl>publish\</PublishUrl>
|
<PublishUrl>publish\</PublishUrl>
|
||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
<InstallFrom>Disk</InstallFrom>
|
<InstallFrom>Disk</InstallFrom>
|
||||||
<UpdateEnabled>false</UpdateEnabled>
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
<UpdateMode>Foreground</UpdateMode>
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
<UpdateInterval>7</UpdateInterval>
|
<UpdateInterval>7</UpdateInterval>
|
||||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
<UpdatePeriodically>false</UpdatePeriodically>
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
<UpdateRequired>false</UpdateRequired>
|
<UpdateRequired>false</UpdateRequired>
|
||||||
<MapFileExtensions>true</MapFileExtensions>
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
<ApplicationRevision>0</ApplicationRevision>
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
<UseApplicationTrust>false</UseApplicationTrust>
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||||
<RestorePackages>true</RestorePackages>
|
<RestorePackages>true</RestorePackages>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="nunit.framework">
|
<Reference Include="nunit.framework">
|
||||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CronScheduleTests.cs" />
|
<Compile Include="CronScheduleTests.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\CronNET\CronNET.csproj">
|
<ProjectReference Include="..\CronNET\CronNET.csproj">
|
||||||
<Project>{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}</Project>
|
<Project>{F31D7AF3-FDFA-44F1-9C63-305BAF11D002}</Project>
|
||||||
<Name>CronNET</Name>
|
<Name>CronNET</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
<BootstrapperPackage Include=".NETFramework,Version=v4.0">
|
||||||
<Visible>False</Visible>
|
<Visible>False</Visible>
|
||||||
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
|
<ProductName>Microsoft .NET Framework 4 %28x86 and x64%29</ProductName>
|
||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||||
<Visible>False</Visible>
|
<Visible>False</Visible>
|
||||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||||
<Install>false</Install>
|
<Install>false</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
<Visible>False</Visible>
|
<Visible>False</Visible>
|
||||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
<Install>false</Install>
|
<Install>false</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||||
<Visible>False</Visible>
|
<Visible>False</Visible>
|
||||||
<ProductName>Windows Installer 3.1</ProductName>
|
<ProductName>Windows Installer 3.1</ProductName>
|
||||||
<Install>true</Install>
|
<Install>true</Install>
|
||||||
</BootstrapperPackage>
|
</BootstrapperPackage>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- 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.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
<Target Name="BeforeBuild">
|
<Target Name="BeforeBuild">
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="AfterBuild">
|
<Target Name="AfterBuild">
|
||||||
</Target>
|
</Target>
|
||||||
-->
|
-->
|
||||||
</Project>
|
</Project>
|
384
CronNETTests/CronScheduleTests.cs
Executable file → Normal file
384
CronNETTests/CronScheduleTests.cs
Executable file → Normal file
|
@ -1,192 +1,192 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using CronNET;
|
using CronNET;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
|
|
||||||
namespace CronTests
|
namespace CronTests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class CronScheduleTests
|
public class CronScheduleTests
|
||||||
{
|
{
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_valid_test()
|
public void is_valid_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule();
|
var cron_schedule = new CronSchedule();
|
||||||
Assert.IsTrue(cron_schedule.isValid("*/2"));
|
Assert.IsTrue(cron_schedule.isValid("*/2"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("* * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("* * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("0 * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("0 * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("0,1,2 * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("0,1,2 * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("*/2 * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("*/2 * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("1-4 * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("1-4 * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("1-55/3 * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("1-55/3 * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("1,10,20 * * * *"));
|
Assert.IsTrue(cron_schedule.isValid("1,10,20 * * * *"));
|
||||||
Assert.IsTrue(cron_schedule.isValid("* 1,10,20 * * *"));
|
Assert.IsTrue(cron_schedule.isValid("* 1,10,20 * * *"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void divided_array_test()
|
public static void divided_array_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("*/2");
|
var cron_schedule = new CronSchedule("*/2");
|
||||||
List<int> results = cron_schedule.minutes.GetRange(0,5);//("*/2", 0, 10);
|
List<int> results = cron_schedule.minutes.GetRange(0,5);//("*/2", 0, 10);
|
||||||
Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 });
|
Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void range_array_test()
|
public static void range_array_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("1-10");
|
var cron_schedule = new CronSchedule("1-10");
|
||||||
List<int> results = cron_schedule.minutes.GetRange(0,10);//();
|
List<int> results = cron_schedule.minutes.GetRange(0,10);//();
|
||||||
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 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 * * *");
|
var cs = new CronSchedule("1-10/3 20-45/4 * * *");
|
||||||
results = cs.minutes;
|
results = cs.minutes;
|
||||||
Assert.AreEqual(results.ToArray(), new int[] { 3, 6, 9 });
|
Assert.AreEqual(results.ToArray(), new int[] { 3, 6, 9 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void wild_array_test()
|
public void wild_array_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("*");
|
var cron_schedule = new CronSchedule("*");
|
||||||
List<int> results = cron_schedule.minutes.GetRange(0,10);//("*", 0, 10);
|
List<int> 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 });
|
Assert.AreEqual(results.ToArray(), new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void list_array_test()
|
public void list_array_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("1,2,3,4,5,6,7,8,9,10");
|
var cron_schedule = new CronSchedule("1,2,3,4,5,6,7,8,9,10");
|
||||||
List<int> results = cron_schedule.minutes;
|
List<int> results = cron_schedule.minutes;
|
||||||
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_values_divided_test()
|
public void generate_values_divided_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("*/2");
|
var cron_schedule = new CronSchedule("*/2");
|
||||||
List<int> results = cron_schedule.minutes.GetRange(0,5);//(, 0, 10);
|
List<int> results = cron_schedule.minutes.GetRange(0,5);//(, 0, 10);
|
||||||
Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 });
|
Assert.AreEqual(results.ToArray(), new int[] { 0, 2, 4, 6, 8 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_values_range_test()
|
public void generate_values_range_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("1-10");
|
var cron_schedule = new CronSchedule("1-10");
|
||||||
List<int> results = cron_schedule.minutes.GetRange(0,10);//(, 0, 10);
|
List<int> 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 });
|
Assert.AreEqual(results.ToArray(), new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_minutes_test()
|
public void generate_minutes_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("1,2,3 * * * *");
|
var cron_schedule = new CronSchedule("1,2,3 * * * *");
|
||||||
Assert.AreEqual(cron_schedule.minutes.ToArray(), new int[] { 1, 2, 3 });
|
Assert.AreEqual(cron_schedule.minutes.ToArray(), new int[] { 1, 2, 3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_hours_test()
|
public void generate_hours_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* 1,2,3 * * *");
|
var cron_schedule = new CronSchedule("* 1,2,3 * * *");
|
||||||
Assert.AreEqual(cron_schedule.hours.ToArray(), new int[] { 1, 2, 3 });
|
Assert.AreEqual(cron_schedule.hours.ToArray(), new int[] { 1, 2, 3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_days_of_month_test()
|
public void generate_days_of_month_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* * 1,2,3 * *");
|
var cron_schedule = new CronSchedule("* * 1,2,3 * *");
|
||||||
Assert.AreEqual(cron_schedule.days_of_month.ToArray(), new int[] { 1, 2, 3 });
|
Assert.AreEqual(cron_schedule.days_of_month.ToArray(), new int[] { 1, 2, 3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_months_test()
|
public void generate_months_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* * * 1,2,3 *");
|
var cron_schedule = new CronSchedule("* * * 1,2,3 *");
|
||||||
Assert.AreEqual(cron_schedule.months.ToArray(), new int[] { 1, 2, 3 });
|
Assert.AreEqual(cron_schedule.months.ToArray(), new int[] { 1, 2, 3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void generate_days_of_weeks()
|
public void generate_days_of_weeks()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* * * * 1,2,3 ");
|
var cron_schedule = new CronSchedule("* * * * 1,2,3 ");
|
||||||
Assert.AreEqual(cron_schedule.days_of_week.ToArray(), new int[] { 1, 2, 3 });
|
Assert.AreEqual(cron_schedule.days_of_week.ToArray(), new int[] { 1, 2, 3 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_time_minute_test()
|
public void is_time_minute_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("0 * * * *");
|
var cron_schedule = new CronSchedule("0 * * * *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
||||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:01 am")));
|
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:01 am")));
|
||||||
|
|
||||||
cron_schedule = new CronSchedule("0-10 * * * *");
|
cron_schedule = new CronSchedule("0-10 * * * *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:03 am")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:03 am")));
|
||||||
|
|
||||||
cron_schedule = new CronSchedule("*/2 * * * *");
|
cron_schedule = new CronSchedule("*/2 * * * *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:00 am")));
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:02 am")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("8:02 am")));
|
||||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:03 am")));
|
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("8:03 am")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_time_hour_test()
|
public void is_time_hour_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* 0 * * *");
|
var cron_schedule = new CronSchedule("* 0 * * *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 am")));
|
||||||
|
|
||||||
cron_schedule = new CronSchedule("* 0,12 * * *");
|
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 am")));
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 pm")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00 pm")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_time_day_of_month_test()
|
public void is_time_day_of_month_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* * 1 * *");
|
var cron_schedule = new CronSchedule("* * 1 * *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("2010/08/01")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("2010/08/01")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_time_month_test()
|
public void is_time_month_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* * * 1 *");
|
var cron_schedule = new CronSchedule("* * * 1 *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
|
||||||
|
|
||||||
cron_schedule = new CronSchedule("* * * 12 *");
|
cron_schedule = new CronSchedule("* * * 12 *");
|
||||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
|
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("1/1/2008")));
|
||||||
|
|
||||||
cron_schedule = new CronSchedule("* * * */3 *");
|
cron_schedule = new CronSchedule("* * * */3 *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("3/1/2008")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("3/1/2008")));
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("6/1/2008")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("6/1/2008")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_time_day_of_week_test()
|
public void is_time_day_of_week_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("* * * * 0");
|
var cron_schedule = new CronSchedule("* * * * 0");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/12/2008")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/12/2008")));
|
||||||
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("10/13/2008")));
|
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("10/13/2008")));
|
||||||
|
|
||||||
cron_schedule = new CronSchedule("* * * * */2");
|
cron_schedule = new CronSchedule("* * * * */2");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/14/2008")));
|
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("10/14/2008")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void is_time_test()
|
public void is_time_test()
|
||||||
{
|
{
|
||||||
var cron_schedule = new CronSchedule("0 0 12 10 *");
|
var cron_schedule = new CronSchedule("0 0 12 10 *");
|
||||||
Assert.IsTrue(cron_schedule.isTime(DateTime.Parse("12:00:00 am 10/12/2008")));
|
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")));
|
Assert.IsFalse(cron_schedule.isTime(DateTime.Parse("12:01:00 am 10/12/2008")));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void ppp()
|
public static void ppp()
|
||||||
{
|
{
|
||||||
var d = new CronDaemon();
|
var d = new CronDaemon();
|
||||||
d.AddJob("*/1 * * * *", () => { Console.WriteLine(DateTime.Now.ToString()); });
|
d.AddJob("*/1 * * * *", () => { Console.WriteLine(DateTime.Now.ToString()); });
|
||||||
d.Start();
|
d.Start();
|
||||||
//Thread.Sleep(60 * 1000);
|
//Thread.Sleep(60 * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
70
CronNETTests/Properties/AssemblyInfo.cs
Executable file → Normal file
70
CronNETTests/Properties/AssemblyInfo.cs
Executable file → Normal file
|
@ -1,35 +1,35 @@
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
// associated with an assembly.
|
// associated with an assembly.
|
||||||
[assembly: AssemblyTitle("CronNETTests")]
|
[assembly: AssemblyTitle("CronNETTests")]
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("CronNETTests")]
|
[assembly: AssemblyProduct("CronNETTests")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2008")]
|
[assembly: AssemblyCopyright("Copyright © 2008")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
// 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
|
// to COM components. If you need to access a type in this assembly from
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
[assembly: ComVisible(false)]
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
[assembly: Guid("6a430089-ab18-4d72-9d7a-5a4ee0883153")]
|
[assembly: Guid("6a430089-ab18-4d72-9d7a-5a4ee0883153")]
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
// Version information for an assembly consists of the following four values:
|
||||||
//
|
//
|
||||||
// Major Version
|
// Major Version
|
||||||
// Minor Version
|
// Minor Version
|
||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
|
|
10
CronTests.nunit
Executable file → Normal file
10
CronTests.nunit
Executable file → Normal file
|
@ -1,6 +1,6 @@
|
||||||
<NUnitProject>
|
<NUnitProject>
|
||||||
<Settings activeconfig="Default" />
|
<Settings activeconfig="Default" />
|
||||||
<Config name="Default" binpathtype="Auto">
|
<Config name="Default" binpathtype="Auto">
|
||||||
<assembly path="CronNETTests\bin\Debug\CronTests.dll" />
|
<assembly path="CronNETTests\bin\Debug\CronTests.dll" />
|
||||||
</Config>
|
</Config>
|
||||||
</NUnitProject>
|
</NUnitProject>
|
|
@ -29,6 +29,11 @@ CronNET supports most cron scheduling. See tests for supported formats.
|
||||||
`* 1,10,20 * * *` Every 1st, 10th, and 20th hours.
|
`* 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
|
Console Example
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user