public void SetName(int id, string name) { IControllerDataSet cds = GetControllerById(id); if (cds == null) { throw new Exception("Unknown Controller"); } else { cds.FriendlyName = name; SaveToDisk(cds); } }
public void SetLedCount(int id, int count) { IControllerDataSet cds = GetControllerById(id); if (cds == null) { throw new Exception("Unknown Controller"); } else { cds.LedCount = count; SaveToDisk(cds); } }
public void CreateController(IControllerDataSet controllerDataSet) { if (String.IsNullOrWhiteSpace(controllerDataSet.UuId)) { throw new Exception("UUID is not set"); } if (HasControllerById(controllerDataSet.Id) || HasControllerByUuid(controllerDataSet.UuId)) { throw new Exception("Controller already existing"); } else { _controllers.Add(controllerDataSet); SaveToDisk(controllerDataSet); } }
public void SetFirmware(string uuId, int minVersion, int majVersion, string firmwareId, string deviceName) { IControllerDataSet cds = GetControllerByUuId(uuId); if (cds == null) { throw new Exception("Unknown Controller"); } else { cds.MinorVersion = minVersion; cds.MajorVersion = majVersion; cds.FirmwareId = firmwareId; cds.DeviceName = deviceName; cds.Timestamp = DateTime.UtcNow; } }
/// <summary> /// Returns the <see cref="Controller"/> having the passed ID or throws a <see cref="ResourceNotFoundException"/> if a <see cref="Controller"/> /// with the passed ID does not exist. /// </summary> /// <param name="id">id of the controller</param> /// <returns>controller</returns> public Controller GetController(int id) { if (_controllerStorage.HasControllerById(id)) { Controller controller = new Controller(); IControllerDataSet cds = _controllerStorage.GetControllerById(id); controller.Id = cds.Id; controller.Name = cds.FriendlyName; controller.LedCount = cds.LedCount; controller.State = CalculateState(cds.Timestamp); return(controller); } else { throw new ResourceNotFoundException(ResourceNotFoundException.MSG_CONTROLLER_NOT_FOUND.Replace("{VALUE}", id + "")); } }
/// <summary> /// Returns an instance of <see cref="ControllerFirmware"/> encompassing all firmware details 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="ControllerFirmware"/></returns> public ControllerFirmware GetFirmware(int id) { if (_controllerStorage.HasControllerById(id)) { IControllerDataSet cds = _controllerStorage.GetControllerById(id); ControllerFirmware firmware = new ControllerFirmware(id, cds.UuId, cds.LedCount); firmware.DeviceName = cds.DeviceName; firmware.FirmwareId = cds.FirmwareId; firmware.MajorVersion = cds.MajorVersion; firmware.MinorVersion = cds.MinorVersion; firmware.TimeStamp = cds.Timestamp; return(firmware); } else { throw new ResourceNotFoundException(ResourceNotFoundException.MSG_CONTROLLER_NOT_FOUND.Replace("{VALUE}", id + "")); } }
public void DeleteController(IControllerDataSet controllerDataSet) { DeleteController(controllerDataSet.Id); }
/// <summary> /// Saves the passed <see cref="ControllerDataSetJson"/> to disk. /// </summary> /// <param name="data"></param> private void SaveToDisk(IControllerDataSet data) { File.WriteAllText(_homeDirectory + data.Id + ".json", JsonSerializer.SerializeJson((ControllerDataSetJson)data)); }