Example #1
0
        public void TestIntervals(long delay, long expectedDelayTicks, long interval, long expectedIntervalTicks, int count)
        {
            var timerTicks = new TimerTicks();

            void action()
            {
                timerTicks.ExpectedTicks += timerTicks.ExecutedCount++ == 0 ? expectedDelayTicks : expectedIntervalTicks;
                Assert.Equal(timerTicks.ExpectedTicks, timerTicks.Ticks);
            }

            Timer.Init(timerTicks.Ticks);

            Timer.StartTimer(TimeSpan.FromMilliseconds(delay), TimeSpan.FromMilliseconds(interval), count, action);

            var tickCount = (expectedDelayTicks + (expectedIntervalTicks * count - 1)) / 8;

            for (int i = 1; i <= tickCount; i++)
            {
                timerTicks.Ticks = i * 8;

                Timer.Slice(timerTicks.Ticks);
            }

            Assert.Equal(count, timerTicks.ExecutedCount);
        }
Example #2
0
        public void TestVariousTimes(long ticks, long expectedTicks)
        {
            var timerTicks = new TimerTicks();

            void action()
            {
                Assert.Equal(expectedTicks, timerTicks.Ticks);
                timerTicks.ExecutedCount++;
            }

            Timer.Init(timerTicks.Ticks);

            Timer.StartTimer(TimeSpan.FromMilliseconds(ticks), action);

            var tickCount = expectedTicks / 8;

            for (int i = 1; i <= tickCount; i++)
            {
                timerTicks.Ticks = i * 8;

                Timer.Slice(timerTicks.Ticks);
            }

            Assert.Equal(1, timerTicks.ExecutedCount);
        }
 public TimerTicks GetTimerTick(int DaemonId)
 {
     using (MySqlConnection connection = WebApiConfig.Connection())
         using (MySqlCommand command = new MySqlCommand("SELECT * FROM `tbDaemons` WHERE `Id` = " + DaemonId, connection))
         {
             TimerTicks timers = new TimerTicks();
             connection.Open();
             using (MySqlDataReader reader = command.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     timers.TimerTick   = (int)reader["TimerTick"];
                     timers.AfterStart  = (int)reader["TimerOnStart"];
                     timers.AfterFailed = (int)reader["TimerAfterFail"];
                     return(timers);
                 }
                 return(null);
             }
         }
 }