Beispiel #1
0
        /// <summary>
        /// Returns the <see cref="Firmware"/> having the passed <see cref="Firmware.Id"/>.
        /// Additionally, the<code> uuid</code> and<code> leds</code> query parameter can be set. These parameter values will be added as query parameters in all hyperlinks of the returned resource representation such that
        /// a consumer of the REST API is navigated to an individual firmware file where these values are already injected.
        /// The methods throws a <see cref="ResourceNotFoundException"/> if the requested <see cref="Firmware"/> does not exist.
        /// </summary>
        /// <param name="id"><see cref="Firmware.Id"/> of the requested firmeware</param>
        /// <param name="query">additional query parameters containing the UUID and the LED count (can be null)</param>
        /// <returns>the <see cref="Firmware"/> having the passed ID</returns>
        public Firmware GetFirmware(string id, IDictionary <string, string> query)
        {
            IFirmwareDataSet fds = _firmwareStorage.GetFirmware(id);

            if (fds != null)
            {
                Firmware fw = new Firmware();
                fw.FirmwareId    = id;
                fw.MajorVersion  = fds.MajorVersion;
                fw.MinorVersion  = fds.MinorVersion;
                fw.DeviceName    = fds.DeviceName;
                fw.FileExtension = fds.FirmwareFileExtension;
                if (query != null && query.ContainsKey("uuid") && query.ContainsKey("leds"))
                {
                    fw.Uuid     = query["uuid"];
                    fw.LedCount = query["leds"];
                }
                fw.HasRawData = _firmwareStorage.HasRawData(id);
                return(fw);
            }
            else
            {
                throw new ResourceNotFoundException(ResourceNotFoundException.MSG_FIRMWARE_NOT_FOUND.Replace("{VALUE}", id));
            }
        }
        public void ChangeMetaInformation(string id, string deviceName)
        {
            IFirmwareDataSet fds = GetFirmware(id);

            if (fds == null)
            {
                throw new Exception("Unknown Firmware");
            }
            fds.DeviceName = deviceName;
        }
        public void SetRawData(string id, string rawData)
        {
            IFirmwareDataSet fds = GetFirmware(id);

            if (fds == null)
            {
                throw new Exception("Unknown Firmware");
            }
            SaveToDisk(rawData, fds.FirmwareFileExtension, id);
        }
        public void ChangeMetaInformation(string id, int minorVersion, int majorVersion)
        {
            IFirmwareDataSet fds = GetFirmware(id);

            if (fds == null)
            {
                throw new Exception("Unknown Firmware");
            }
            fds.MinorVersion = minorVersion;
            fds.MajorVersion = majorVersion;
        }
 public void CreateFirmware(IFirmwareDataSet firmwareDataSet, string rawData)
 {
     if (String.IsNullOrWhiteSpace(firmwareDataSet.Id))
     {
         throw new Exception("ID is not set");
     }
     if (HasFirmware(firmwareDataSet.Id))
     {
         throw new Exception("Firmware already existing");
     }
     else
     {
         _firmwares.Add(firmwareDataSet);
         SaveToDisk(firmwareDataSet);
         //SetRawData(firmwareDataSet.Id, rawData);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Returns the raw data of the firmware file linked to the firmware meta information having the passed ID.
        /// Additionally, the <code>uuid</code> and <code>leds</code> query parameter can be set. These parameter values will be injected into the raw data such that
        /// the returned firmware file can be flashed on the corresponding controller without any modifications.
        /// The methods throws a <see cref="ResourceNotFoundException"/> if the requested <see cref="Firmware"/> does not exist.
        /// </summary>
        /// <param name="id">see cref="Firmware.Id"/> of the firmeware whose firmware file is requested</param>
        /// <param name="query">additional query parameters containing the UUID and the LED count which will be injected into the returned raw data (can be null)</param>
        /// <returns>the raw data (firmware file)</returns>
        public string GetRawData(string id, IDictionary <string, string> query)
        {
            string uuid = "";
            string leds = "";

            if (query != null && query.ContainsKey("uuid") && query.ContainsKey("leds"))
            {
                uuid = query["uuid"];
                leds = query["leds"];
            }

            IFirmwareDataSet fds = _firmwareStorage.GetFirmware(id);

            if (fds != null)
            {
                if (!_firmwareStorage.HasRawData(id))
                {
                    throw new ResourceNotFoundException(ResourceNotFoundException.MSG_FILE_NOT_FOUND);
                }
                string rawData = _firmwareStorage.GetRawData(id);
                return(rawData.Replace(PLACEHOLDER_UUID, uuid)
                       .Replace(PLACEHOLDER_MIN_VERSION, fds.MinorVersion + "")
                       .Replace(PLACEHOLDER_MAJ_VERSION, fds.MajorVersion + "")
                       .Replace(PLACEHOLDER_DEVICE_NAME_VERSION, fds.DeviceName)
                       .Replace(PLACEHOLDER_FIRMWARE_ID, fds.Id)
                       .Replace(PLACEHOLDER_WIFI_SSID, _settings.WifiSsid)
                       .Replace(PLACEHOLDER_WIFI_PWD, _settings.WifiPwd)
                       .Replace(PLACEHOLDER_TARGET_URL, _settings.TargetUrl)
                       .Replace(PLACEHOLDER_TIMEOUT, _settings.ClientTimeout + "")
                       .Replace(PLACEHOLDER_LED_COUNT, leds));
            }
            else
            {
                throw new ResourceNotFoundException(ResourceNotFoundException.MSG_FIRMWARE_NOT_FOUND.Replace("{VALUE}", id));
            }
        }
 public void DeleteFirmware(IFirmwareDataSet firmwareDataSet)
 {
     DeleteFirmware(firmwareDataSet.Id);
 }
 /// <summary>
 /// Deletes the <see cref="IFirmwareDataSet"/> as well as its firmware file having the passed ID from disk
 /// </summary>
 /// <param name="id"></param>
 private void RemoveFromDisk(IFirmwareDataSet data)
 {
     File.Delete(_homeDirectory + data.Id + ".json");
     File.Delete(_homeDirectory + data.Id + "." + data.FirmwareFileExtension);
 }
 /// <summary>
 /// Saves the passed <see cref="IFirmwareDataSet"/> to disk.
 /// </summary>
 /// <param name="data"></param>
 private void SaveToDisk(IFirmwareDataSet data)
 {
     File.WriteAllText(_homeDirectory + data.Id + ".json", JsonSerializer.SerializeJson((FirmwareDataSetJson)data));
 }