public void Run() { Light l = new Light(); l.SetState(new Off()); l.Switch(); l.Switch(); l.Switch(); }
private async Task <Light> UpdateState(Light light) { if (light.State != await _arduinoCommunicationService.Lights.Read(light.PinPort)) { light.Switch(); _lightRepository.Update(light); } return(light); }
public async Task <CommandResult> Handle(SwitchLightCommand command) { CommandResult result = new CommandResult(); ObjectId lightId = new ObjectId(); if (!ObjectId.TryParse(command.LightId, out lightId)) { AddNotification(nameof(command.LightId), ENotifications.InvalidFormat); } if (Valid) { Light light = _lightRepository.Get(lightId); if (light == null && _lightRepository.Valid) { AddNotification(nameof(command.LightId), ENotifications.NotFound); } if (Valid) { light = await UpdateState(light); light.Switch(); if (await _arduinoCommunicationService.Lights.Switch(new SwitchLightQuery(light.PinPort, light.State))) { _lightRepository.Update(light); if (_lightRepository.Valid) { result = new CommandResult(HttpStatusCode.OK); } } } else { result = new CommandResult(HttpStatusCode.BadRequest, Notifications); } } else { result = new CommandResult(HttpStatusCode.BadRequest, Notifications); } return(result); }