コード例 #1
0
 internal CronTaskWrapper(IAsyncWork asyncWork, CronExpression cron, CancellationToken innerCancellation, int execCount)
 {
     _asyncWork                = asyncWork;
     _work                     = null;
     _cron                     = cron;
     _innerCancellation        = innerCancellation;
     _execCount                = execCount;
     _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false);
 }
コード例 #2
0
 internal RepeatedTaskWrapper(IAsyncWork asyncWork, DateTime startTime, TimeSpan repeatDelay, CancellationToken innerCancellation,
                              int execCount)
 {
     _asyncWork         = asyncWork;
     _work              = null;
     _innerCancellation = innerCancellation;
     _nextScheduledTime = startTime.ToLocalTime();
     _repeatDelay       = repeatDelay;
     while (_nextScheduledTime < DateTime.Now)
     {
         _nextScheduledTime += _repeatDelay;
     }
     _execCount = execCount;
     _cancellationRegistration = _innerCancellation.Register(() => _subject.OnCompleted(), false);
 }
コード例 #3
0
 internal StartupWorkWrapper(IAsyncWork asyncWork)
 {
     _work      = null;
     _asyncWork = asyncWork;
 }
コード例 #4
0
        /// <summary> Create <see cref="IScheduledTaskWrapper" /> for given <paramref name="asyncWork" /> scheduled to <paramref name="startTime" /> </summary>
        /// <param name="asyncWork"> Work instance </param>
        /// <param name="startTime"> Work first execution time </param>
        /// <param name="repeatDelay"> Work repeat delay </param>
        /// <param name="cancellation"> Work cancellation token </param>
        /// <param name="execCount"> Max work execution count (-1 for unlimited) </param>
        /// <exception cref="ArgumentNullException"> Thrown if <paramref name="asyncWork" /> is NULL </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     Thrown if <paramref name="repeatDelay" /> isn't greater then 00:00:00.000 or
        ///     <paramref name="execCount" /> is 0 or less then -1
        /// </exception>
        /// <returns> Wrapper and work result observable </returns>
        public static (IScheduledTaskWrapper, IObservable <Maybe <Exception> >) CreateRepeatedWorkWrapper(IAsyncWork asyncWork, DateTime startTime,
                                                                                                          TimeSpan repeatDelay, CancellationToken cancellation = default, int execCount = -1)
        {
            startTime = startTime.ToLocalTime();
            var wrapper = new RepeatedTaskWrapper(asyncWork ?? throw new ArgumentNullException(nameof(asyncWork)),
                                                  startTime,
                                                  repeatDelay <= TimeSpan.Zero
                ? throw new ArgumentOutOfRangeException(nameof(repeatDelay), repeatDelay, "Must be greater then 00:00:00.000")
                : repeatDelay,
                                                  cancellation,
                                                  execCount is > 0 or - 1
                ? execCount
                : throw new ArgumentOutOfRangeException(nameof(execCount), execCount, "Must be greater then 0 or -1 for unlimited repeat"));

            return(wrapper, wrapper.WorkObservable);
        }