public void IsValidTimePeriod_IsValid_InRange()
        {
            var dateTime   = new DateTime(2020, 1, 22, 9, 5, 0);
            var timePeriod = "08:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
        public void IsValidTimePeriod_IsValid_OnPoint()
        {
            var dateTime   = new DateTime(2020, 1, 22, 22, 0, 0);
            var timePeriod = "10:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
        public void IsValidTimePeriod_IsInValid()
        {
            var dateTime   = new DateTime(2020, 1, 22, 23, 51, 0);
            var timePeriod = "00:00-23:50";

            Assert.False(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
예제 #4
0
        private static async Task Run(ILogger logger, TimeSpan interval, string timePeriod, Executor executor,
                                      CancellationToken cancel)
        {
            try
            {
                while (!cancel.IsCancellationRequested)
                {
                    // In valid time period?
                    var currentState = Interlocked.CompareExchange(ref _lockState, SqlConfig.Locked, SqlConfig.Available);
                    if (TimePeriodHelper.IsValidTimePeriod(DateTime.Now, timePeriod) &&
                        currentState == SqlConfig.Available)
                    {
                        await executor.Start();
                    }

                    // ReSharper disable once RedundantAssignment
                    currentState = Interlocked.CompareExchange(ref _lockState, SqlConfig.Available, SqlConfig.Locked);
                    await Task.Delay(interval, cancel);
                }
            }
            catch (OperationCanceledException)
            {
                logger.Information("The executor task was canceled.");
            }
            catch (Exception ex)
            {
                logger.Fatal(ex, "The executor task threw an unhandled exception.");
            }
        }
예제 #5
0
        public void IsValidTimePeriod_IsValid_InRange()
        {
            var          dateTime   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 9, 5, 0);
            const string timePeriod = "08:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
예제 #6
0
        public void IsValidTimePeriod_IsInValid()
        {
            var          dateTime   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 51, 0);
            const string timePeriod = "00:00-23:50";

            Assert.False(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
예제 #7
0
        public void IsValidTimePeriod_IsValid_OnPoint()
        {
            var          dateTime   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 22, 0, 0);
            const string timePeriod = "10:00-22:00";

            Assert.True(TimePeriodHelper.IsValidTimePeriod(dateTime, timePeriod));
        }
예제 #8
0
 private static async Task Run(ILogger logger, TimeSpan interval, string timePeriod, Executor executor, CancellationToken cancel)
 {
     try
     {
         while (!cancel.IsCancellationRequested)
         {
             // In valid time period?
             if (TimePeriodHelper.IsValidTimePeriod(DateTime.Now, timePeriod))
             {
                 await executor.Start();
             }
             await Task.Delay(interval, cancel);
         }
     }
     catch (OperationCanceledException)
     {
         logger.Information("The executor task was canceled.");
     }
     catch (Exception ex)
     {
         logger.Fatal(ex, "The executor task threw an unhandled exception.");
     }
 }