/// <summary> /// Deletes the raw data object identified by the key <paramref name="rawDataKey"/> and the part with uuid <paramref name="partUuid"/>. /// </summary> /// <param name="client">The client class to use.</param> /// <param name="partUuid">The uuid of the part the raw data objects belongs to.</param> /// <param name="rawDataKey">The key of the raw data object which should be deleted.</param> /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> is <see langword="null" />.</exception> public static Task DeleteRawDataForPart([NotNull] this IRawDataServiceRestClient client, Guid partUuid, int?rawDataKey = null, CancellationToken cancellationToken = default) { if (client == null) { throw new ArgumentNullException(nameof(client)); } return(client.DeleteRawData(RawDataTargetEntityDto.CreateForPart(partUuid), rawDataKey, cancellationToken)); }
public static async Task Lesson(DataServiceRestClient client, RawDataServiceRestClient rawClient) { await client.CreateParts(new[] { Part }); //PiWeb only accepts binary data var data = Encoding.UTF8.GetBytes("Hello RawDataService!"); var target = RawDataTargetEntityDto.CreateForPart(Part.Uuid); //Notes: - see e.g. http://wiki.selfhtml.org/wiki/Referenz:MIME-Typen for a complete list of mime types // - When using Key = -1, the server will generate a new key. The generated key can be read from the result. var createdRawDataInfo = await rawClient.CreateRawData(new RawDataInformationDto { FileName = "Hello.txt", MimeType = "text/plain", Key = -1, Created = DateTime.Now, LastModified = DateTime.Now, MD5 = new Guid(MD5.Create().ComputeHash(data)), Size = data.Length, Target = target }, data); Console.WriteLine($"RawData created with key: {createdRawDataInfo.Key}"); //We can simply update raw data information like filename or MIME-type if (createdRawDataInfo.Key.HasValue) { createdRawDataInfo.FileName = "HelloEdit.txt"; Console.WriteLine($"Renaming raw data file to {createdRawDataInfo.FileName}"); await rawClient.UpdateRawDataInformation(target, createdRawDataInfo.Key.Value, createdRawDataInfo); } var rawDataInformation = await rawClient.ListRawData(new[] { target }); foreach (var information in rawDataInformation) { Console.WriteLine($"Fetching {information.FileName}: {information.Size} bytes"); //Fetch the data by providing the correct RawDataInformation data = await rawClient.GetRawData(information); Console.WriteLine($"Content: {Encoding.UTF8.GetString( data )}"); //We can use the key we found with the ListRawData function to delete a single file await rawClient.DeleteRawDataForPart(Part.Uuid, information.Key); } //Or we simply delete all raw data for a certain entity await rawClient.DeleteRawDataForPart(Part.Uuid); }