Esempio n. 1
0
        static void Main()
        {
            TimedDoor _td = new TimedDoor();
            WoodenDoor _woodenDoor = new WoodenDoor();

            Timer _timer = new Timer();
            _timer.Register(1000, _td);
            _timer.Register(1000, _woodenDoor);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Provide Timeout for how long can the door be kept open (in secs)");
            var timeoutInSec = Console.ReadLine();

            var timedDoor = new TimedDoor();
            var timer     = new Timer();

            Console.WriteLine("Press O for opening the door and C for closing the door (and any other key to exit the app)");

            // Infinite Loop (For Testing purpose only)
            for (; ;)
            {
                timer.Register(Convert.ToInt32(timeoutInSec), timedDoor);

                var input = Console.ReadLine();

                if (input == "O")
                {
                    if (!timedDoor.DoorOpen)
                    {
                        timedDoor.Unlock();
                        timer.stopwatch.Start();
                        timedDoor.DoorOpen = true;
                    }
                    else
                    {
                        Console.WriteLine("Door Already Open");
                    }
                }
                else if (input == "C")
                {
                    timer.Register(Convert.ToInt32(timeoutInSec), timedDoor);

                    if (timedDoor.DoorOpen)
                    {
                        timedDoor.Lock();
                        timer.stopwatch.Reset();
                        timedDoor.DoorOpen = false;
                    }
                    else
                    {
                        Console.WriteLine("Door Already Closed");
                    }
                }
                else
                {
                    break;
                }
            }
        }
        private void CriarPortaComTemporizador()
        {
            TimedDoor timedDoor = new TimedDoor();

            timedDoor.IsDoorOpen();

            timedDoor.Unlock();

            Console.WriteLine("------------------------");
            Console.WriteLine("Pressione OK para fechar a porta...");
            Console.ReadKey();

            timedDoor.Lock();
        }
Esempio n. 4
0
 public DoorTimerAdapter(TimedDoor theDoor)
 {
     timedDoor = theDoor;
 }