Beispiel #1
0
        //2.  Define the method that takes the delegate(s) and calls them.
        // This is a new PowerUp method that takes two delegates, one
        // to call the real PowerUp method and one for the callback
        // method.
        internal void PowerUp(ToggleSystemPower powerUpProcess, 
            PowerUpComplete callbackMethod)
        {
            // Call the PowerUp process using the Invoke method of the Delegate class.
            powerUpProcess();

            // Now call the callback method, using the Invoke method of the
            // delegate class, to notify the client code
            // that the reading process is done.
            callbackMethod();
        }
Beispiel #2
0
        //private void DisplayMenu()
        //{
        //    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: ");
        //}
        private bool RunOperation(string operation)
        {
            bool success = false;
            string systemOperation = operation.ToUpper();
            systemOperation = systemOperation.Substring(0, 1);

            switch (systemOperation)
            {
                case "1":   // Turn on the system.
                    if (HWTSystem != null)
                    {
            //4. Create instance of delegate in the client code.
                        // The delegate used for the callback when powerup
                        // completes.
                        PowerUpComplete puc =
                            new PowerUpComplete(PowerUpProcessComplete);

            //4.  Create instance of delegate in the client code.
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerUp);

            //5.  Pass the instances of delegates to a method that will call them.
                        // Call the PowerUp method that takes the two
                        // delegates.
                        HWTSystem.PowerUp(togglePower, puc);
                        success = true;
                    }

                    break;

                case "2":   // Turn off the system.
                    if (HWTSystem != null)
                    {
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerDown);
                        togglePower();
                        success = false;
                    }

                    break;

                case "3":   // Purge hot water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferHotWaterOut);
                        if (manager())
                        {
                            success = true;
                        }
                    }

                    break;

                case "4":   // Fill cold water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferColdWaterIn);
                        if (manager())
                        {
                            success = true;
                        }
                    }

                    break;

                case "X":   // Exit the control program.
                    ExitSystem = true;
                    success = true;
                    break;

                default:
                    Console.WriteLine("Menu option {0} is not valid.",
                        operation);
                    break;
            }

            return success;
        }
Beispiel #3
0
        private bool RunOperation(string operation, string controlOperator)
        {
            bool   success         = false;
            string systemOperation = operation.ToUpper();

            systemOperation = systemOperation.Substring(0, 1);

            switch (systemOperation)
            {
            case "1":       // Turn on the system.
                if (HWTSystem != null)
                {
                    ToggleSystemPower togglePower =
                        new ToggleSystemPower(HWTSystem.PowerUp);
                    togglePower(controlOperator);
                    success = true;
                }

                break;

            case "2":       // Turn off the system.
                if (HWTSystem != null)
                {
                    // Traditional approach to creating an instance of a delegate.
                    ToggleSystemPower togglePower =
                        new ToggleSystemPower(HWTSystem.PowerDown);
                    // Use delegate inference for creating an instance of a delegate
                    //      to simplify code.
                    //ToggleSystemPower togglePower = HWTSystem.PowerDown;
                    togglePower(controlOperator);
                    success = false;
                }

                break;

            case "3":       // Purge hot water.
                if (HWTSystem != null)
                {
                    ManageWater manager =
                        new ManageWater(HWTSystem.TransferHotWaterOut);
                    if (manager(controlOperator))
                    {
                        success = true;
                    }
                }

                break;

            case "4":       // Fill cold water.
                if (HWTSystem != null)
                {
                    ManageWater manager =
                        new ManageWater(HWTSystem.TransferColdWaterIn);
                    if (manager(controlOperator))
                    {
                        success = true;
                    }
                }

                break;

            case "X":       // Exit the control program.
                ExitSystem = true;
                success    = true;
                break;

            default:
                Console.WriteLine("Menu option {0} is not valid.",
                                  operation);
                break;
            }

            return(success);
        }
Beispiel #4
0
        private bool RunOperation(string operation)
        {
            bool success = false;
            string systemOperation = operation.ToUpper();
            systemOperation = systemOperation.Substring(0, 1);

            switch (systemOperation)
            {
                case "1":   // Turn on the system.
                    if (HWTSystem != null)
                    {
                        // The delegate used for the callback when powerup
                        // completes.
                        PowerUpComplete puc =
                            new PowerUpComplete(PowerUpProcessComplete);

                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerUp);

                        // Call the PowerUp method that takes the two
                        // delegates.
                        HWTSystem.PowerUp(togglePower, puc);
                        success = true;
                    }

                    break;

                case "2":   // Turn off the system.
                    if (HWTSystem != null)
                    {
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerDown);
                        togglePower();
                        success = false;
                    }

                    break;

                case "3":   // Purge hot water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferHotWaterOut);
                        if (manager())
                        {
                            success = true;
                        }
                    }

                    break;

                case "4":   // Fill cold water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferColdWaterIn);
                        if (manager())
                        {
                            success = true;
                        }
                    }

                    break;

                case "5":   // Correct system errors.
                    if (HWTSystem != null)
                    {
                        // See if the system is on. If not, turn it on!
                        if (!HWTSystem.PowerOn)
                        {
                            HWTSystem.PowerUp();
                        }

                        // Purge the hot water and then fill with cold water.
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferHotWaterOut);
                        if (manager())
                        {
                            manager = new
                                ManageWater(HWTSystem.TransferColdWaterIn);
                            if (manager())
                            {
                                success = true;
                            }
                        }

                        // Turn the system off.
                        if (HWTSystem.PowerOn)
                        {
                            HWTSystem.PowerDown();
                        }

                        Console.WriteLine("System errors have been fixed " +
                            "and the system was shutdown successfully.");
                    }

                    break;

                case "X":   // Exit the control program.
                    ExitSystem = true;
                    success = true;
                    break;

                default:
                    Console.WriteLine("Menu option {0} is not valid.",
                        operation);
                    break;
            }

            return success;
        }
Beispiel #5
0
        // This is a new PowerUp method that takes two delegates, one
        // to call the real PowerUp method and one for the callback
        // method.
        internal void PowerUp(ToggleSystemPower powerUpProcess, 
            PowerUpComplete callbackMethod)
        {
            // Call the PowerUp process.
            powerUpProcess();

            // Now call the callback method to notify the client code
            // that the reading process is done.
            callbackMethod();
        }
Beispiel #6
0
        private bool RunOperation(string operation, string controlOperator)
        {
            bool success = false;
            string systemOperation = operation.ToUpper();
            systemOperation = systemOperation.Substring(0, 1);

            switch (systemOperation)
            {
                case "1":   // Turn on the system.
                    if (HWTSystem != null)
                    {
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerUp);
                        togglePower(controlOperator);
                        success = true;
                    }

                    break;

                case "2":   // Turn off the system.
                    if (HWTSystem != null)
                    {
                        // Traditional approach to creating an instance of a delegate.
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerDown);
                        // Use delegate inference for creating an instance of a delegate
                        //      to simplify code.
                        //ToggleSystemPower togglePower = HWTSystem.PowerDown;
                        togglePower(controlOperator);
                        success = false;
                    }

                    break;

                case "3":   // Purge hot water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferHotWaterOut);
                        if (manager(controlOperator))
                        {
                            success = true;
                        }
                    }

                    break;

                case "4":   // Fill cold water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferColdWaterIn);
                        if (manager(controlOperator))
                        {
                            success = true;
                        }
                    }

                    break;

                case "X":   // Exit the control program.
                    ExitSystem = true;
                    success = true;
                    break;

                default:
                    Console.WriteLine("Menu option {0} is not valid.",
                        operation);
                    break;
            }

            return success;
        }
Beispiel #7
0
        //private void DisplayMenu()
        //{
        //    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: ");
        //}
        private bool RunOperation(string operation)
        {
            bool success = false;
            string systemOperation = operation.ToUpper();
            systemOperation = systemOperation.Substring(0, 1);

            switch (systemOperation)
            {
                case "1":   // Turn on the system.
                    if (HWTSystem != null)
                    {
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerUp);
                        togglePower();
                        success = true;
                    }

                    break;

                case "2":   // Turn off the system.
                    if (HWTSystem != null)
                    {
                        ToggleSystemPower togglePower =
                            new ToggleSystemPower(HWTSystem.PowerDown);
                        togglePower();
                        success = false;
                    }

                    break;

                case "3":   // Purge hot water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferHotWaterOut);
                        if (manager())
                        {
                            success = true;
                        }
                    }

                    break;

                case "4":   // Fill cold water.
                    if (HWTSystem != null)
                    {
                        ManageWater manager =
                            new ManageWater(HWTSystem.TransferColdWaterIn);
                        if (manager())
                        {
                            success = true;
                        }
                    }

                    break;

                case "X":   // Exit the control program.
                    ExitSystem = true;
                    success = true;
                    break;

                default:
                    Console.WriteLine("Menu option {0} is not valid.",
                        operation);
                    break;
            }

            return success;
        }