private void Scheduler(object state)
        {
            if (!_done)
            {
                var currentTime = DateTime.Now;

                lock (_programs)
                {
                    ZoneController turnOn = null;
                    IEnumerable <ZoneController> turnOff = null;
                    if (_manualZone == null)
                    {
                        var cycles       = _programs.SelectMany(program => program.Cycles);
                        var runningCycle = cycles.Where(cycle => cycle.IsRunning(currentTime.DayOfWeek, currentTime.Hour, currentTime.Minute)).FirstOrDefault();
                        if (runningCycle != null)
                        {
                            Debug.WriteLine("Program {0}({1}), cycle {2} is running", runningCycle.Parent.Name, runningCycle.Parent.Id, runningCycle.Id);
                            var runningZone = runningCycle.Zones.Where(zone => zone.IsRunning(currentTime.DayOfWeek, currentTime.Hour, currentTime.Minute)).FirstOrDefault();
                            if (runningZone != null)
                            {
                                Debug.WriteLine("Current time is " + currentTime.TimeOfDay + " zone " + runningZone.Id + " is running.");
                                turnOn = _zoneControllers[runningZone.Id];
                            }
                        }
                    }
                    else
                    {
                        Debug.WriteLine("zone " + _manualZone.ZoneNumber + " is manual mode");
                        turnOn = _manualZone;
                    }

                    if (turnOn != null)
                    {
                        turnOff = _zoneControllers.Where(zoneController => zoneController.Value != turnOn).Select(zoneController => zoneController.Value);
                    }
                    else
                    {
                        turnOff = _zoneControllers.Select(zoneController => zoneController.Value);
                    }

                    turnOff.ToList().ForEach(zoneController => zoneController.Stop());
                    if (turnOn != null)
                    {
                        turnOn.Start();
                    }
                }
                if (!_done)
                {
                    _timer = ThreadPoolTimer.CreateTimer(Scheduler, TimeSpan.FromSeconds(1));
                }
            }
        }
 public void StopZone()
 {
     _manualZone = null;
 }
 public void StartZone(int zoneNumber)
 {
     ValidateZone(zoneNumber);
     _manualZone = _zoneControllers[zoneNumber];
 }