diff --git a/samples/EasyCron.Sample/Jobs/ConsoleCronJob.cs b/samples/EasyCron.Sample/Jobs/ConsoleCronJob.cs index 68274b0..64f8e0f 100644 --- a/samples/EasyCron.Sample/Jobs/ConsoleCronJob.cs +++ b/samples/EasyCron.Sample/Jobs/ConsoleCronJob.cs @@ -13,7 +13,7 @@ public class ConsoleCronJob : CronJobService private readonly ILogger logger; public ConsoleCronJob(ICronConfiguration cronConfiguration, ILogger logger) - : base(cronConfiguration.CronExpression,cronConfiguration.TimeZoneInfo) + : base(cronConfiguration.CronExpression,cronConfiguration.TimeZoneInfo, cronConfiguration.CronFormat) { this.logger = logger; } diff --git a/samples/EasyCron.Sample/Startup.cs b/samples/EasyCron.Sample/Startup.cs index 1f54cf2..032363b 100644 --- a/samples/EasyCron.Sample/Startup.cs +++ b/samples/EasyCron.Sample/Startup.cs @@ -38,13 +38,15 @@ public void ConfigureServices(IServiceCollection services) services.ApplyResulation(options => { - options.CronExpression = "* * * * *"; + options.CronExpression = "*/10 * * * * *"; options.TimeZoneInfo = TimeZoneInfo.Local; + options.CronFormat = Cronos.CronFormat.IncludeSeconds; }); services.ApplyResulation(options => { options.CronExpression = "* * * * *"; options.TimeZoneInfo = TimeZoneInfo.Local; + options.CronFormat = Cronos.CronFormat.Standard; }); diff --git a/samples/EasyCron.Sample/appsettings.json b/samples/EasyCron.Sample/appsettings.json index 1ecbe97..a7aa618 100644 --- a/samples/EasyCron.Sample/appsettings.json +++ b/samples/EasyCron.Sample/appsettings.json @@ -9,12 +9,14 @@ "AllowedHosts": "*", "CronJobs": { "ConsoleCronJob": { - "CronExpression": "* * * * *", - "TimeZoneInfo": "Local" + "CronExpression": "*/10 * * * * *", + "TimeZoneInfo": "Local", + "CronFormat": "IncludeSeconds" }, "MyJob": { "CronExpression": "*/2 * * * *", - "TimeZoneInfo": "Local" + "TimeZoneInfo": "Local", + "CronFormat": "Standard" } } } diff --git a/src/EasyCronJob.Abstractions/CronConfiguration.cs b/src/EasyCronJob.Abstractions/CronConfiguration.cs index 8a4efc0..c07098a 100644 --- a/src/EasyCronJob.Abstractions/CronConfiguration.cs +++ b/src/EasyCronJob.Abstractions/CronConfiguration.cs @@ -1,4 +1,5 @@ -using System; +using Cronos; +using System; namespace EasyCronJob.Abstractions { @@ -17,5 +18,11 @@ public class CronConfiguration : ICronConfiguration /// Represents any time zone in the world. /// public TimeZoneInfo TimeZoneInfo { get; set; } + + /// + /// Cron Format + /// Default + /// + public CronFormat CronFormat { get; set; } = CronFormat.Standard; } } diff --git a/src/EasyCronJob.Abstractions/CronJobService.cs b/src/EasyCronJob.Abstractions/CronJobService.cs index 9feab5a..77cbfdb 100644 --- a/src/EasyCronJob.Abstractions/CronJobService.cs +++ b/src/EasyCronJob.Abstractions/CronJobService.cs @@ -16,11 +16,13 @@ public abstract class CronJobService : IHostedService, IDisposable { private System.Timers.Timer timer; private readonly TimeZoneInfo timeZoneInfo; + private readonly CronFormat cronFormat; private readonly CronExpression cronExpression; - protected CronJobService(string cronExpression, TimeZoneInfo timeZoneInfo) + protected CronJobService(string cronExpression, TimeZoneInfo timeZoneInfo, CronFormat cronFormat = CronFormat.Standard) { this.timeZoneInfo = timeZoneInfo; - this.cronExpression = CronExpression.Parse(cronExpression); + this.cronFormat = cronFormat; + this.cronExpression = CronExpression.Parse(cronExpression, this.cronFormat); } protected virtual async Task ScheduleJob(CancellationToken cancellationToken) diff --git a/src/EasyCronJob.Abstractions/EasyCronJob.Abstractions.csproj b/src/EasyCronJob.Abstractions/EasyCronJob.Abstractions.csproj index c82e79a..a2e483d 100644 --- a/src/EasyCronJob.Abstractions/EasyCronJob.Abstractions.csproj +++ b/src/EasyCronJob.Abstractions/EasyCronJob.Abstractions.csproj @@ -4,7 +4,7 @@ net5.0 furkandeveloper furkandeveloper - 2.0.0 + 2.1.0 This library provides abstraction layer for EasyCronJob.Core library. easyCronJob.png https://github.com/furkandeveloper/EasyCronJob diff --git a/src/EasyCronJob.Abstractions/ICronConfiguration.cs b/src/EasyCronJob.Abstractions/ICronConfiguration.cs index 6dc9e3b..95b6f93 100644 --- a/src/EasyCronJob.Abstractions/ICronConfiguration.cs +++ b/src/EasyCronJob.Abstractions/ICronConfiguration.cs @@ -1,4 +1,5 @@ -using System; +using Cronos; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -23,5 +24,11 @@ public interface ICronConfiguration /// TimeZone Information /// public TimeZoneInfo TimeZoneInfo { get; set; } + + /// + /// Cron Format + /// Default + /// + public CronFormat CronFormat { get; set; } } } diff --git a/src/EasyCronJob.AutoConfigurer/EasyCronJob.AutoConfigurer.csproj b/src/EasyCronJob.AutoConfigurer/EasyCronJob.AutoConfigurer.csproj index f12948b..0552f95 100644 --- a/src/EasyCronJob.AutoConfigurer/EasyCronJob.AutoConfigurer.csproj +++ b/src/EasyCronJob.AutoConfigurer/EasyCronJob.AutoConfigurer.csproj @@ -4,7 +4,7 @@ net5.0 furkandeveloper furkandeveloper - 2.0.0 + 2.1.0 This repository provides easy cron job to your application on IHostedService. easyCronJob.png https://github.com/furkandeveloper/EasyCronJob diff --git a/src/EasyCronJob.AutoConfigurer/Startup.cs b/src/EasyCronJob.AutoConfigurer/Startup.cs index d074c4c..00aec12 100644 --- a/src/EasyCronJob.AutoConfigurer/Startup.cs +++ b/src/EasyCronJob.AutoConfigurer/Startup.cs @@ -1,4 +1,5 @@ -using EasyCronJob.Abstractions; +using Cronos; +using EasyCronJob.Abstractions; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; @@ -43,12 +44,13 @@ private static List FindCronJobServices() /// /// Returns /// - private static Tuple FindServiceParameter(IServiceCollection services, string serviceName) + private static Tuple FindServiceParameter(IServiceCollection services, string serviceName) { var serviceProvider = services.BuildServiceProvider(); var configurationObject = serviceProvider.GetRequiredService(); string cronExpression = configurationObject.GetValue("CronJobs:" + serviceName + ":CronExpression"); string info = configurationObject.GetValue("CronJobs:" + serviceName + ":TimeZoneInfo"); + string cronFormat = configurationObject.GetValue("CronJobs:" + serviceName + ":CronFormat"); TimeZoneInfo timeZoneInfo; switch (info) { @@ -62,7 +64,21 @@ private static Tuple FindServiceParameter(IServiceCollecti timeZoneInfo = TimeZoneInfo.Local; break; } - return new Tuple(cronExpression, timeZoneInfo); + CronFormat format = CronFormat.Standard; + switch (cronFormat) + { + case "Standard": + format = CronFormat.Standard; + break; + case "IncludeSeconds": + format = CronFormat.IncludeSeconds; + break; + default: + format = CronFormat.Standard; + break; + } + + return new Tuple(cronExpression, timeZoneInfo, format); } /// @@ -136,6 +152,7 @@ private static IServiceCollection ConfigureCronServices(IServiceCollection servi { findedService.GetType().GetProperty("CronExpression").SetValue(findedService, cronParameters.Item1); findedService.GetType().GetProperty("TimeZoneInfo").SetValue(findedService, cronParameters.Item2); + findedService.GetType().GetProperty("CronFormat").SetValue(findedService, cronParameters.Item3); } ctorServices.Add(findedService); } diff --git a/src/EasyCronJob.Core/EasyCronJob.Core.csproj b/src/EasyCronJob.Core/EasyCronJob.Core.csproj index 952949f..91f8064 100644 --- a/src/EasyCronJob.Core/EasyCronJob.Core.csproj +++ b/src/EasyCronJob.Core/EasyCronJob.Core.csproj @@ -4,7 +4,7 @@ net5.0 furkandeveloper furkandeveloper - 2.0.0 + 2.1.0 This repository provides easy cron job to your application on IHostedService. easyCronJob.png https://github.com/furkandeveloper/EasyCronJob