using System; using System.Linq.Expressions; using Hangfire.Annotations; using Hangfire.Common; using Hangfire.States; namespace Hangfire { public static class RecurringJobManagerExtensions { public static void AddOrUpdate( [NotNull] this RecurringJobManager manager, [NotNull] string recurringJobId, [NotNull] Expression methodCall, [NotNull] Func cronExpression, TimeZoneInfo timeZone = null, string queue = EnqueuedState.DefaultQueue) { if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); } public static void AddOrUpdate( [NotNull] this RecurringJobManager manager, [NotNull] string recurringJobId, [NotNull] Expression> methodCall, [NotNull] Func cronExpression, TimeZoneInfo timeZone = null, string queue = EnqueuedState.DefaultQueue) { if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); AddOrUpdate(manager, recurringJobId, methodCall, cronExpression(), timeZone, queue); } public static void AddOrUpdate( [NotNull] this RecurringJobManager manager, [NotNull] string recurringJobId, [NotNull] Expression methodCall, [NotNull] string cronExpression, TimeZoneInfo timeZone = null, string queue = EnqueuedState.DefaultQueue) { if (manager == null) throw new ArgumentNullException(nameof(manager)); if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); var job = Job.FromExpression(methodCall); manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); } public static void AddOrUpdate( [NotNull] this RecurringJobManager manager, [NotNull] string recurringJobId, [NotNull] Expression> methodCall, [NotNull] string cronExpression, TimeZoneInfo timeZone = null, string queue = EnqueuedState.DefaultQueue) { if (manager == null) throw new ArgumentNullException(nameof(manager)); if (recurringJobId == null) throw new ArgumentNullException(nameof(recurringJobId)); if (methodCall == null) throw new ArgumentNullException(nameof(methodCall)); if (cronExpression == null) throw new ArgumentNullException(nameof(cronExpression)); var job = Job.FromExpression(methodCall); manager.AddOrUpdate(recurringJobId, job, cronExpression, timeZone ?? TimeZoneInfo.Utc, queue); } } }