Ejemplo n.º 1
0
 public bool Equals(WeeklyHostedServiceOptions <TScheduledAction> other)
 {
     if (other == null || !Schedule.SequenceEqual(other.Schedule))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
        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));
                    }
                }
            }
        }