Esempio n. 1
0
 /// <summary>
 /// Get manifest with provided manifest_id.
 /// </summary>
 /// <param name="manifestId">Id</param>
 /// <returns><see cref="FirmwareManifest"/></returns>
 /// <exception cref="CloudApiException">CloudApiException</exception>
 /// <example>
 /// <code>
 /// try
 /// {
 ///     var manifest = updateApI.GetFirmwareManifest("015baf5f4f04000000000001001003d5");
 ///     return manifest;
 /// }
 /// catch (CloudApiException)
 /// {
 ///     throw;
 /// }
 /// </code>
 /// </example>
 public FirmwareManifest GetFirmwareManifest(string manifestId)
 {
     try
     {
         return(FirmwareManifest.Map(Api.FirmwareManifestRetrieve(manifestId)));
     }
     catch (update_service.Client.ApiException ex)
     {
         return(HandleNotFound <FirmwareManifest, update_service.Client.ApiException>(ex));
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Add Firmware Manifest.
        /// </summary>
        /// <param name="manifest">
        /// Entity with all the properties required to create a new firmware manifest.
        /// <see cref="FirmwareManifest.DataFile"/> and <see cref="FirmwareManifest.Name"/>
        /// are mandatory.
        /// </param>
        /// <returns>The newly create firmware manifest.</returns>
        /// <exception cref="CloudApiException">
        /// If the operation cannot be completed because of a server-side error (caused, for example,
        /// by an invalid parameter value).
        /// </exception>
        /// <exception cref="IOException">
        /// If an I/O error occured when reading <c>FirmwareManifestInfo.DataFilePath</c>
        /// or <c>FirmwareManifestInfo.KeyTableFilePath</c>.
        /// </exception>
        /// <exception cref="UnauthorizedAccessException">
        /// If current user has not the permission to read file specified in
        /// <c>FirmwareManifestInfo.DataFilePath</c> or <c>FirmwareManifestInfo.KeyTableFilePath</c>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="manifest"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <see cref="FirmwareManifest.DataFile"/> is a <see langword="null"/> or blank string.
        /// <br/>-Or-<br/>
        /// If <see cref="FirmwareManifest.Name"/> is a <see langword="null"/> or blank string.
        /// </exception>
        /// <example>
        /// <code>
        /// try
        /// {
        ///     return updateApi.AddFirmwareManifest(new FirmwareManifest
        ///     {
        ///         DataFilePath = "path to the file",
        ///         Name = "description of the manifest"
        ///     });
        /// }
        /// catch (CloudApiException)
        /// {
        ///     throw;
        /// }
        /// </code>
        /// </example>
        public FirmwareManifest AddFirmwareManifest(FirmwareManifest manifest)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException(nameof(manifest));
            }

            if (string.IsNullOrWhiteSpace(manifest.DataFile))
            {
                throw new ArgumentException($"{nameof(FirmwareManifest)}.{nameof(FirmwareManifest.DataFile)} cannot be empty");
            }

            if (string.IsNullOrWhiteSpace(manifest.Name))
            {
                throw new ArgumentException($"{nameof(FirmwareManifest)}.{nameof(FirmwareManifest.Name)} cannot be empty");
            }

            using (var dataFileStream = File.OpenRead(manifest.DataFile))
            {
                var keyTableFileStream = OpenKeyTableStream();
                try
                {
                    var response = Api.FirmwareManifestCreate(dataFileStream, manifest.Name, manifest.Description, keyTableFileStream);
                    return(FirmwareManifest.Map(response));
                }
                catch (update_service.Client.ApiException e)
                {
                    throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent);
                }
                finally
                {
                    keyTableFileStream?.Close();
                }
            }

            FileStream OpenKeyTableStream()
            => string.IsNullOrWhiteSpace(manifest.KeyTableFile) ? null : File.OpenRead(manifest.KeyTableFile);
        }