public void GetLeds(HttpContext context, string controllerId)
        {
            int            id             = ApiBase.ParseId(controllerId);
            ControllerLeds controllerLeds = _controllerHandler.GetLedsOfController(id);
            string         json           = JsonSerializer.SerializeJson(controllerLeds);

            context.Response.Payload.Write(json);
            context.Response.Status = HttpStatus.OK;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns an instance of <see cref="ControllerLeds"/> encompassing all <see cref="Led"/>s of the controller having the passed <see cref="Controller.Id"/>.
        /// The method throws an <see cref="ResourceNotFoundException"/> if the specified <see cref="Controller"/> does not exists.
        /// </summary>
        /// <param name="id"><see cref="Controller.Id"/> of the controller</param>
        /// <returns>instance of <see cref="ControllerLeds"/> encompassing the Leds</returns>
        public ControllerLeds GetLedsOfController(int id)
        {
            if (!_controllerStorage.HasControllerById(id))
            {
                throw new ResourceNotFoundException(ResourceNotFoundException.MSG_CONTROLLER_NOT_FOUND.Replace("{VALUE}", id + ""));
            }
            ControllerLeds controllerLeds = new ControllerLeds();

            controllerLeds.ControllerId = id;
            foreach (ILedDataSet lds in _ledStorage.GetAllLedsOfController(id))
            {
                Led led = new Led();
                led.ControllerId = lds.ControllerId;
                led.LedNumber    = lds.LedNumber;
                led.RgbValue     = lds.RgbValue;

                controllerLeds.Leds.Add(led);
            }
            return(controllerLeds);
        }