//set runImmediate to true to run right away //set scheduleTime and runPeriod (seconds). //If scheduleTime is in the future the schedule will start at the schedule time //Otherwise, shedule time will start at next cycle calculating from scheduletime and period static void Main() { bool runImmediate = true; DateTime scheduledTime = DateTime.Parse("06/18/2020 11:14:05"); Console.WriteLine("{0:MM/d/yyyy h:mm:ss.fff} Start Date.\n", scheduledTime); var statusChecker = new StatusChecker(10); if (runImmediate) { statusChecker.CheckStatus(null); } int runPeriod = 10; //seconds int period = runPeriod * 1000; //milliseconds DateTime nowTime = DateTime.Now; int delay = (int)(((scheduledTime - nowTime).TotalMilliseconds) % period + period) % period; Console.WriteLine("delay {0} ms", delay); //while (nowTime > scheduledTime) //{ // //scheduledTime = scheduledTime.AddDays(1); // scheduledTime = scheduledTime.AddSeconds(runPeriod); //} //Console.WriteLine("{0:MM/d/yyyy h:mm:ss.fff} Start Date.\n", scheduledTime); //int tickTime = (int)(scheduledTime - DateTime.Now).TotalMilliseconds; //Console.WriteLine("tickTime {0} ms", tickTime); var stateTimer = new Timer(statusChecker.CheckStatus, null, delay, period); Console.ReadKey(); }
public void CheckStatus_HasNan_CreatesSingleAlert() { // Arrange var s = new FileStream(fileWithBadNAN, FileMode.Open); string contents = convertStreamToString(s); var e = new TOA5Extractor( "CookEastEcTower_Flux_Raw_2017_11_03_1300_badNAN.dat", contents, -8); var a = new MockTweeter(); StatusChecker sut = new StatusChecker(e, a); // Act var alerts = sut.CheckStatus(); // Assert Assert.Single(alerts); }
public void CheckStatus_HasNanAtOkLocations_NoAlert() { // Arrange var s = new FileStream(fileWithNANOkLocations, FileMode.Open); string contents = convertStreamToString(s); var e = new TOA5Extractor( "CookEastEcTower_Flux_Raw_2017_11_03_1300_okNAN.dat", contents, -8); var a = new MockTweeter(); StatusChecker sut = new StatusChecker(e, a); // Act var alerts = sut.CheckStatus(); // Assert Assert.Empty(alerts); }
public void CheckStatus_HasBadValueAtSecondRowAndNAN_CreatesExpectedAlertString() { // Arrange var s = new FileStream(fileWithBadDataAtSecondRowAndNAN, FileMode.Open); string contents = convertStreamToString(s); var e = new TOA5Extractor( "CookEastEcTower_Flux_Raw_2017_11_03_1300_2linesBadCO2BadNAN.dat", contents, -8); var a = new MockTweeter(); StatusChecker sut = new StatusChecker(e, a); string expected = "[E] CookEastEcTower_Flux_Raw_2017_11_03_1300_2linesBadCO2BadNAN.dat: Null values > 3.\r\n[W] CookEastEcTower_Flux_Raw_2017_11_03_1300_2linesBadCO2BadNAN.dat: CO2_sig_strgth_Min < 0.8 (0.7)."; // Act var alerts = sut.CheckStatus(); // Assert Assert.Equal(2, alerts.Count); Assert.Equal( expected, string.Join("\r\n", alerts)); }