static void Main(string[] args) { Console.WriteLine("Hellow from Delegate__Chain__Demo project!"); var wSystem = new ReactorSensorsSystem(); var isWeekend = DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday; var warningHandler = new ReactorSensorsSystem.NuclearReactorWarningHandler(SendWarningEmail); var smsWarning = new ReactorSensorsSystem.NuclearReactorWarningHandler(new Program().SendWarningSMS); while (true) { Thread.Sleep(1000); int temp = ReactorSensorsSystem.GetTempFromSensor(); if (isWeekend) { if (!warningHandler.GetInvocationList().Contains(smsWarning)) { warningHandler += smsWarning; } } else { if (warningHandler.GetInvocationList().Contains(smsWarning)) { warningHandler -= smsWarning; } } wSystem.CheckReactorTemperature(temp, warningHandler); } }
static void Main(string[] args) { Console.WriteLine("Hellow from DelegateDemo project!"); var wSystem = new ReactorSensorsSystem(); var isWeekend = DateTime.Now.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.DayOfWeek == DayOfWeek.Sunday; while (true) { Thread.Sleep(1000); int temp = ReactorSensorsSystem.GetTempFromSensor(); if (isWeekend) { wSystem.CheckReactorTemperature(temp, (new Program()).SendWarningSMS); } else { wSystem.CheckReactorTemperature(temp, SendWarningEmail); } } }