public void ConsumeElectricity(double electricity)
 {
     if (electricity <= MaxElectricityAllowed)
     {
         _electricalDevice.ConsumeElectricity(electricity);
     }
 }
Пример #2
0
        static void Main(string[] args)
        {
            IKernel kernel = new StandardKernel(new BuildingManagerModule());

            IElectricalDevice consumer = kernel.Get <IElectricalDevice>(BuildingManagerModule.HighElectricityDefenderName);

            consumer.ConsumeElectricity(5);

            Console.WriteLine("-------------");
            Console.WriteLine(consumer);
            Console.WriteLine("-------------");

            consumer.ConsumeElectricity(200);

            Console.WriteLine("-------------");
            Console.WriteLine(consumer);
            Console.WriteLine("-------------");
        }
Пример #3
0
        public void ConsumeElectricity(double electricity)
        {
            double electricityToPass = electricity;

            if (electricityToPass > 0)
            {
                ReservedCapacity = Math.Min(ReservedCapacity + electricityToPass, MaxReservedCapacity);
            }
            else if (ReservedCapacity > 0)
            {
                electricityToPass = Math.Min(PassedElectricity, ReservedCapacity);
                ReservedCapacity -= electricityToPass;
            }

            _electricalDevice.ConsumeElectricity(electricityToPass);
        }