private async Task <RawDataInformation[]> ListRawDataByUuidList(RawDataEntity entity, string[] uuids, FilterCondition filter, CancellationToken cancellationToken = default(CancellationToken)) { StringUuidTools.CheckUuids(entity, uuids); var requestPath = $"rawData/{entity}"; var parameterDefinitions = new List <ParameterDefinition>(); if (filter != null) { var filterTree = filter.BuildFilterTree(); var filterString = new FilterTreeFormatter().FormatString(filterTree); var filterParameter = ParameterDefinition.Create("filter", filterString); parameterDefinitions.Add(filterParameter); } //Split into multiple parameter sets to limit uuid parameter lenght var splitter = new ParameterSplitter(this, requestPath); var collectionParameter = CollectionParameterFactory.Create("uuids", uuids); var parameterSets = splitter.SplitAndMerge(collectionParameter, parameterDefinitions); //Execute requests in parallel var requests = parameterSets .Select(set => RequestBuilder.CreateGet(requestPath, set.ToArray())) .Select(request => _RestClient.Request <RawDataInformation[]>(request, cancellationToken)); var result = await Task.WhenAll(requests).ConfigureAwait(false); return(result.SelectMany(r => r).ToArray()); }
private Task UploadRawData(RawDataInformation info, Stream data, HttpMethod method, CancellationToken cancellationToken) { if (info.Target.Entity == RawDataEntity.Value && !StringUuidTools.IsStringUuidPair(info.Target.Uuid)) { throw new ArgumentOutOfRangeException("info", "The uuid string for uploading raw data for measurement value needs 2 uuids in the format: {measurementUuid}|{characteristicUuid}"); } if (String.IsNullOrEmpty(info.FileName)) { throw new ArgumentException("FileName needs to be set.", "info"); } var requestString = info.Key >= 0 ? string.Format("rawData/{0}/{1}/{2}", info.Target.Entity, info.Target.Uuid, info.Key) : string.Format("rawData/{0}/{1}", info.Target.Entity, info.Target.Uuid); if (method.Equals(HttpMethod.Post)) { return(Post(requestString, data, cancellationToken, info.Size, info.MimeType, info.MD5, info.FileName)); } if (method.Equals(HttpMethod.Put)) { return(Put(requestString, data, cancellationToken, info.Size, info.MimeType, info.MD5, info.FileName)); } throw new ArgumentOutOfRangeException("method"); }
/// <summary> /// Deletes raw data for the element identified by <paramref name="target"/> and <paramref name="rawDataKey"/>. /// </summary> /// <param name="target">The <see cref="RawDataTargetEntity"/> object containing the <see cref="RawDataEntity"/> type and the uuid of the raw data that should be deleted.</param> /// <param name="rawDataKey">The key of the raw data object which should be deleted.</param> /// <param name="cancellationToken">A token to cancel the hronous operation.</param> public Task DeleteRawData(RawDataTargetEntity target, int?rawDataKey, CancellationToken cancellationToken = default(CancellationToken)) { StringUuidTools.CheckUuid(target.Entity, target.Uuid); var url = rawDataKey.HasValue ? $"rawData/{target.Entity}/{{{target.Uuid}}}/{rawDataKey}" : $"rawData/{target.Entity}/{{{target.Uuid}}}"; return(_RestClient.Request(RequestBuilder.CreateDelete(url), cancellationToken)); }
/// <summary> /// Deletes raw data for the element identified by <paramref name="info"/>. /// </summary> /// <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 deleted.</param> /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> public Task DeleteRawData(RawDataInformation info, CancellationToken cancellationToken = default(CancellationToken)) { if (info.Target.Entity == RawDataEntity.Value && !StringUuidTools.IsStringUuidPair(info.Target.Uuid)) { throw new ArgumentOutOfRangeException("info", "The uuid string for uploading raw data for measurement value needs two uuids in the format: {measurementUuid}|{characteristicUuid}"); } var url = info.Key >= 0 ? string.Format("rawData/{0}/{{{1}}}/{2}", info.Target.Entity, info.Target.Uuid, info.Key) : string.Format("rawData/{0}/{{{1}}}", info.Target.Entity, info.Target.Uuid); return(Delete(url, cancellationToken)); }
/// <summary> /// Deletes raw data for the element identified by <paramref name="target"/> and <paramref name="rawDataKey"/>. /// </summary> /// <param name="target">The <see cref="RawDataTargetEntityDto"/> object containing the <see cref="RawDataEntityDto"/> type and the uuid of the raw data that should be deleted.</param> /// <param name="rawDataKey">The key of the raw data object which should be deleted.</param> /// <param name="cancellationToken">A token to cancel the hronous operation.</param> /// <exception cref="ArgumentNullException"><paramref name="target"/> is <see langword="null" />.</exception> public Task DeleteRawData(RawDataTargetEntityDto target, int?rawDataKey = null, CancellationToken cancellationToken = default) { if (target == null) { throw new ArgumentNullException(nameof(target)); } StringUuidTools.CheckUuid(target.Entity, target.Uuid); var url = rawDataKey.HasValue ? $"rawData/{target.Entity}/{{{target.Uuid}}}/{rawDataKey}" : $"rawData/{target.Entity}/{{{target.Uuid}}}"; return(_RestClient.Request(RequestBuilder.CreateDelete(url), cancellationToken)); }
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>Factory method to create a new <see cref="RawDataTargetEntity"/>-object for a <see cref="RawDataEntity.Value"/>.</summary> /// <remarks> /// Please note that the characteristic should belong to the part to which the specified measurement belongs to. /// </remarks> /// <param name="characteristicUuid">The uuid of a characteristic.</param> /// <param name="measurementUuid">The uuid of a measurement.</param> public static RawDataTargetEntity CreateForValue(Guid measurementUuid, Guid characteristicUuid) { return(new RawDataTargetEntity(RawDataEntity.Value, StringUuidTools.CreateStringUuidPair(measurementUuid, characteristicUuid))); }
/// <summary> /// Parses a string to a list of Guids. /// </summary> public static Guid[] ConvertStringToGuidList(string value) { var stringArray = ParseListToStringArray(value); return(StringUuidTools.StringUuidListToGuidList(stringArray).ToArray()); }