static void Main(string[] args) { bool status = true; // Create the control room object. ControlRoom cr = new ControlRoom(); // Continue to run until the user exits the application. while (!cr.ExitSystem) { // Display the control menu. cr.DisplayMenu(); // Get the option from the user. string option = Console.ReadLine(); Console.WriteLine(); // Process the option. status = cr.RunOperation(option); if (!status) { Console.WriteLine ("WARNING: Is there a problem in the system?"); } } }
static void Main(string[] args) { bool status = true; // Create the DisplayMenu delegate and use an anonymous method // to contain the code. DisplayMenu menu = delegate() { Console.WriteLine(); Console.WriteLine("Hot Water Transfer System Control Menu"); Console.WriteLine(); Console.WriteLine("\t1. Turn on system"); Console.WriteLine("\t2. Turn off system"); Console.WriteLine("\t3. Purge hot water from system"); Console.WriteLine("\t4. Fill system with cold water"); Console.WriteLine("\tX. Exit HWTS control program"); Console.WriteLine(); Console.Write("Enter option: "); }; // Create the control room object. ControlRoom cr = new ControlRoom(); // Continue to run until the user exits the application. while (!cr.ExitSystem) { // Display the control menu. //cr.DisplayMenu(); menu(); // Get the option from the user. string option = Console.ReadLine(); Console.WriteLine(); // Process the option. status = cr.RunOperation(option); if (!status) { Console.WriteLine ("WARNING: Is there a problem in the system?"); } } }
static void Main(string[] args) { RaiseWarning warning = null; bool status = true; bool emergencyOccured = false; bool controlRoomWarningAdded = false; bool managementWarningAdded = false; // Create the DisplayMenu delegate and use an anonymous method // to contain the code. DisplayMenu menu = delegate() { Console.WriteLine(); Console.WriteLine("Hot Water Transfer System Control Menu"); Console.WriteLine(); Console.WriteLine("\t1. Turn on system"); Console.WriteLine("\t2. Turn off system"); Console.WriteLine("\t3. Purge hot water from system"); Console.WriteLine("\t4. Fill system with cold water"); Console.WriteLine("\t5. Correct system errors"); Console.WriteLine("\tX. Exit HWTS control program"); Console.WriteLine(); Console.Write("Enter option: "); }; // Create the control room object. ControlRoom cr = new ControlRoom(); // Continue to run until the user exits the application. while (!cr.ExitSystem) { // Display the control menu. menu(); // Get the option from the user. string option = Console.ReadLine(); Console.WriteLine(); // Process the option. status = cr.RunOperation(option); if (!status) { Console.WriteLine ("WARNING: Is there a problem in the system?"); // If this is the first emergency, create the warning // delegate and point it to the alert mechanism that // will notify the people working on the floor with // the system hardware. if (!emergencyOccured) { emergencyOccured = true; warning = new RaiseWarning (cr.HWTSystem.AlertTransferStationFloor); } else { // If the first warning was already posted, add in // another warning to the control room. Now both // the floor and the control room will be notified. if (!controlRoomWarningAdded) { controlRoomWarningAdded = true; warning += new RaiseWarning (cr.HWTSystem.AlertControlRoom); } else if (controlRoomWarningAdded && !managementWarningAdded) { // At this point, management needs to be notified // because the warnings have not been cleared // yet. Add another method to the delegate's list // of methods to call. managementWarningAdded = true; warning += new RaiseWarning (cr.HWTSystem.AlertManagement); } } // If there are any methods in this delegate's // list, call them now if (warning != null) { //warning(); int alertStatus = 0; foreach (RaiseWarning w in warning.GetInvocationList()) { alertStatus = w(); Console.WriteLine("ALERT STATUS: {0}", alertStatus); } } } else { // All warnings have been corrected, or none have // occured. Clear out the various flags and unload // the multicast delegate by setting it to null. emergencyOccured = false; controlRoomWarningAdded = false; managementWarningAdded = false; warning = null; } } }