public bool Equals(WeeklyHostedServiceOptions <TScheduledAction> other) { if (other == null || !Schedule.SequenceEqual(other.Schedule)) { return(false); } return(true); }
private async void ReloadOptions(WeeklyHostedServiceOptions <TScheduledAction> options) { if (_options == null || !_options.Equals(options)) { _options = options ?? throw new ArgumentNullException(nameof(options)); if (!_options.Schedule.Any()) { throw new InvalidOperationException($"Weekly HostedService options for {typeof(TScheduledAction).Name} must contain atleast one run time"); } _schedule = options.GetSchedule(); if (_isStarted) { _scheduledActionTokenSource.Cancel(); await StartAsync(_HostedServiceTokenSource.Token); } } }
public static IEnumerable <WeeklySchedulePoint> GetSchedule <TScheduledAction>(this WeeklyHostedServiceOptions <TScheduledAction> options) where TScheduledAction : IScheduledAction { foreach (var schedule in options.Schedule) { foreach (DaysToRun days in schedule.Days.GetFlags(true)) { //bitshift to convert DaysOfWeek flag to DayOfWeek var day = (DayOfWeek)(Math.Log((int)days, 2)); foreach (var time in schedule.Times) { yield return(new WeeklySchedulePoint(day, time)); } } } }