Exemple #1
0
        /// <summary>
        /// Updates the raw data object <paramref name="data"/> for the element identified by <paramref name="info"/>.
        /// </summary>
        /// <param name="data">The raw data to upload.</param>
        /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type, the uuid and the key of the raw data that should be updated.</param>
        /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
        public Task UpdateRawData(RawDataInformation info, byte[] data, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (info.Key < 0)
            {
                throw new InvalidOperationException("Unable to update raw data object: A key must be specified.");
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data), "Unable to update raw data object: Data object is null.");
            }

            return(UploadRawData(info, data, HttpMethod.Put, cancellationToken));
        }
Exemple #2
0
        private Task UploadRawData(RawDataInformation info, byte[] data, HttpMethod method, CancellationToken cancellationToken)
        {
            StringUuidTools.CheckUuid(info.Target.Entity, info.Target.Uuid);

            if (string.IsNullOrEmpty(info.FileName))
            {
                throw new ArgumentException("FileName needs to be set.", nameof(info));
            }

            var requestString = info.KeySpecified && info.Key >= 0
                                ? $"rawData/{info.Target.Entity}/{info.Target.Uuid}/{info.Key}"
                                : $"rawData/{info.Target.Entity}/{info.Target.Uuid}";

            var stream = new MemoryStream(data, 0, data.Length, false, true);

            return(_RestClient.Request(RequestBuilder.CreateWithAttachment(method, requestString, stream, info.MimeType, info.Size, info.MD5, info.FileName), cancellationToken));
        }
        /// <summary>
        /// Copy-Constructor.
        /// </summary>
        /// <param name="data">The raw data information object that should be copied.</param>
        public RawDataInformation(RawDataInformation data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            Target       = data.Target;
            Key          = data.Key;
            KeySpecified = data.KeySpecified;
            FileName     = data.FileName;
            MimeType     = data.MimeType;
            Created      = data.Created;
            LastModified = data.LastModified;
            Size         = data.Size;
            MD5          = data.MD5;
        }
Exemple #4
0
 /// <summary>
 /// Creates a new raw data object <paramref name="data"/> for the element specified by <paramref name="info"/>.
 /// </summary>
 /// <param name="data">The raw data to upload.</param>
 /// <param name="info">The <see cref="RawDataInformation"/> object containing the <see cref="RawDataEntity"/> type and the uuid of the raw data that should be uploaded.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 /// <remarks>
 /// If key speciefied by <see cref="RawDataInformation.Key"/> is -1, a new key will be chosen by the server automatically. This is the preferred way.
 /// </remarks>
 public Task CreateRawData(RawDataInformation info, byte[] data, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(UploadRawData(info, data, HttpMethod.Post, cancellationToken));
 }
Exemple #5
0
 public RawData(RawDataInformation info, byte[] data)
     : base(info)
 {
     Data = data;
 }
Exemple #6
0
 /// <summary>
 /// Deletes the raw data object identified by the <paramref name="info"/>.
 /// </summary>
 /// <param name="info">The raw data entry to delete.</param>
 /// <param name="client">The client class to use.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public static Task DeleteRawData(this IRawDataServiceRestClient client, RawDataInformation info, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(client.DeleteRawData(info.Target, info.Key, cancellationToken));
 }
Exemple #7
0
 /// <summary>
 /// Fetches raw data as a byte array for the raw data item identified by <paramref name="info"/>.
 /// </summary>
 /// <param name="client">The client class to use.</param>
 /// <param name="info">The <see cref="RawDataInformation"/> that specifies the raw data object that should be fetched.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public static Task <byte[]> GetRawData(this IRawDataServiceRestClient client, RawDataInformation info, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(client.GetRawData(info.Target, info.Key, info.MD5, cancellationToken));
 }