Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            IStatusWriter consoleWriter = new ConsoleStatusWriter();

            Device salonLamp = new Lamp("Salon");

            salonLamp.StatusChanged += consoleWriter.DeviceStatusChanged;

            //salonLamp.AddSubscriber(consoleWriter);
            //salonLamp.AddSubscriber(new ConsoleStatusWriter());

            salonLamp.TurnOn();
            salonLamp.TurnOff();

            Device kitchenFan = new Fan("Kitchen");

            kitchenFan.AddSubscriber(consoleWriter);
            kitchenFan.TurnOn();

            salonLamp.TurnOff();

            Device ledBathroomLamp = new LedLamp("Bathroom");

            ledBathroomLamp.AddSubscriber(consoleWriter);
            ledBathroomLamp.TurnOn();

            Device halogenBathroomLamp = new HalogenLamp("Bathroom");

            halogenBathroomLamp.AddSubscriber(consoleWriter);
            halogenBathroomLamp.TurnOn();

            Console.ReadLine();
        }
Ejemplo n.º 2
0
 // Constructors
 public Oven(string name, double volume, Lamp lamp)
     : base(name)
 {
     this.backlight = lamp;
     if (volume < 10)
     {
         this.volume = 10;
     }
     else
     {
         this.volume = volume;
     }
     timer.AutoReset = false;
     timer.Elapsed += (sourse, eventArgs) =>
     {
         if (OperationDone != null && this.IsOn)
         {
             OperationDone.Invoke(this);
             isRunning = false;
             if (!isOpen)
             {
                 lamp.TurnOff();
             }
         }
     };
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //observer for console
            // creates a concrete console object observer
            IStatusWriter consoleWriter = new ConsoleStatusWriter();

            Device salonLamp = new Lamp("Salon");


            // event DeviceStatusChangedEventHandler StatusChanged
            //x += y  => x = x + y  (add list of delegate)
            // _MyEvent += new MyDelegate(this.WelcomeUser);
            //salonLamp.Event è anche un delegate
            //notify status changed a Consolewriter (list of observers)
            salonLamp.StatusChanged += consoleWriter.DeviceStatusChanged;

            //salonLamp.AddSubscriber(consoleWriter);
            //salonLamp.AddSubscriber(new ConsoleStatusWriter());

            salonLamp.TurnOn();
            salonLamp.TurnOff();

            Device kitchenFan = new Fan("Kitchen");

            //Observable ... add subscriber
            kitchenFan.AddSubscriber(consoleWriter);

            kitchenFan.TurnOn();
            salonLamp.TurnOff();

            Device ledBathroomLamp = new LedLamp("Bathroom");

            //Observable ... add subscriber
            ledBathroomLamp.AddSubscriber(consoleWriter);

            ledBathroomLamp.TurnOn();

            Device halogenBathroomLamp = new HalogenLamp("Bathroom");

            halogenBathroomLamp.AddSubscriber(consoleWriter);
            //Observable ... add subscriber
            halogenBathroomLamp.TurnOn();

            Console.ReadLine();
        }