Ejemplo n.º 1
0
        private async Task ExecuteEvent(EventCommand command)
        {
            Debug.WriteLine("Executing command: " + command.area + " state: " + command.state);
            if (command.state.ToLower() == "off")
            {
                Debug.WriteLine("Deactivating Area " + _id);

                _state = INACTIVE_STATE;

                foreach (var zone in _zones)
                {
                    zone.Disable();
                }
            }

            else if (command.state.ToLower() == "on")
            {
                Debug.WriteLine("Activating Area " + _id);

                _state = ACTIVE_STATE;

                // the zones are sequenced so that only one zone is on at a time
                foreach (var zone in _zones)
                {
                    zone.Enable();
                    await Task.Delay(command.duration * 1000);
                    zone.Disable();
                }
            }
            else
            {
                Debug.WriteLine("Unknown command state: " + command.state);
            }
        }
Ejemplo n.º 2
0
 public void AddEvent(EventCommand command)
 {
     Debug.WriteLine("Adding event command");
     var start_time = command.schedule_time.Subtract(command.current_time).TotalSeconds;
     Debug.WriteLine("event will start in " + start_time.ToString() + " seconds");
     if (start_time > 1)
     {
         _command = command;
         if (_timer != null)
         {
             _timer.Cancel();
         }
         _timer = ThreadPoolTimer.CreateTimer(Scheduler_Callback, TimeSpan.FromSeconds(start_time));
     }
 }