Ejemplo n.º 1
0
        public void SetLed(HttpContext context, string ledId)
        {
            if (context.Request.Payload.Length > 0)
            {
                string   json     = context.Request.Payload.ReadAll();
                RgbValue rgbValue = JsonSerializer.DeserializeJson <RgbValue>(json);
                if (rgbValue == null)
                {
                    throw new BadRequestException(BadRequestException.MSG_INVALID_PAYLOAD);
                }
                _ledHandler.SetColor(ledId, rgbValue.Rgb);

                Led    response     = _ledHandler.GetLed(ledId);
                string jsonResponse = JsonSerializer.SerializeJson(response);
                context.Response.Payload.Write(jsonResponse);
                context.Response.Status = HttpStatus.OK;
            }
            else
            {
                throw new BadRequestException(BadRequestException.MSG_PAYLOAD_EXPECTED);
            }
        }