Пример #1
0
 /// <summary>
 /// Sets the color of all LEDs of the controller having the specified <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 whose LEDs should be set</param>
 /// <param name="rgb">the RGB value of the LEDs</param>
 public void SetColor(int id, string rgb)
 {
     if (_controllerStorage.HasControllerById(id))
     {
         foreach (ILedDataSet lds in _ledStorage.GetAllLedsOfController(id))
         {
             _ledStorage.SetColor(lds.Id, rgb);
         }
     }
     else
     {
         throw new ResourceNotFoundException(ResourceNotFoundException.MSG_CONTROLLER_NOT_FOUND.Replace("{VALUE}", id + ""));
     }
 }
        /// Sets the color of all <see cref="Leds"/> being member of the <see cref="Group"/> having the specified <see cref="Group.Id"/>.
        /// The methods throws a <see cref="ResourceNotFoundException"/> if the underlying <see cref="Group"/> does not exist.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="rgbValue"></param>
        public void SetColorOfGroup(int id, string rgbValue)
        {
            IGroupDataSet gds = _groupStorage.GetGroup(id);

            if (gds != null)
            {
                foreach (string ledId in gds.Leds)
                {
                    if (_ledStorage.HasLed(ledId))
                    {
                        _ledStorage.SetColor(ledId, rgbValue);
                    }
                }
            }
            else
            {
                throw new ResourceNotFoundException(ResourceNotFoundException.MSG_GROUP_NOT_FOUND.Replace("{VALUE}", id + ""));
            }
        }
 /// <summary>
 /// Sets the color of the <see cref="Led"/> having the specified ID.
 /// The method throws a <see cref="ResourceNotFoundException"/> if the underlying <see cref="Led"/> does not exist.
 /// The method throws a <see cref="BadRequestException"/> if the passed ID is invalid.
 /// </summary>
 /// <param name="ledId">ID of the <see cref="Led"/> whose color should be changed</param>
 /// <param name="rbg">desired RGB value</param>
 public void SetColor(string ledId, string rgb)
 {
     string[] split = ledId.Split(':');
     if (split.Length != 2)
     {
         throw new BadRequestException(BadRequestException.MSG_INVALID_LED_ID);
     }
     else
     {
         int controllerId = ApiBase.ParseInt(split[0], BadRequestException.MSG_INVALID_LED_ID);
         int ledNumber    = ApiBase.ParseInt(split[1], BadRequestException.MSG_INVALID_LED_ID);
         if (_ledStorage.HasLed(controllerId, ledNumber))
         {
             _ledStorage.SetColor(controllerId, ledNumber, rgb);
         }
         else
         {
             throw new ResourceNotFoundException(ResourceNotFoundException.MSG_LED_NOT_FOUND.Replace("{VALUE}", ledId));
         }
     }
 }