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()); }
/// <exception cref="ArgumentOutOfRangeException">The syntax of any uuid in <paramref name="uuids"/> is invalid.</exception> /// <exception cref="ArgumentNullException"><paramref name="uuids"/> is <see langword="null" />.</exception> public static void CheckUuids(RawDataEntity entity, [NotNull] IEnumerable <string> uuids) { if (uuids == null) { throw new ArgumentNullException(nameof(uuids)); } foreach (var uuid in uuids) { CheckUuid(entity, uuid); } }
/// <exception cref="ArgumentOutOfRangeException">The syntax of <paramref name="uuid"/> is invalid.</exception> public static void CheckUuid(RawDataEntity entity, string uuid) { var uuidMustBeComposed = entity == RawDataEntity.Value; if (uuidMustBeComposed && !IsStringUuidPair(uuid)) { throw new ArgumentOutOfRangeException( nameof(uuid), $"'{uuid}' is not a valid measurement value identifier. " + "Measurement value identifiers are expected in this format: MeasurementUuid|CharacteristicUuid."); } if (!uuidMustBeComposed) { StringUuidToGuid(uuid); } }
private Task <RawDataInformation[]> ListRawDataForAllEntities(RawDataEntity entity, [NotNull] FilterCondition filter, CancellationToken cancellationToken = default(CancellationToken)) { if (filter == null) { throw new ArgumentNullException(nameof(filter)); } var requestPath = $"rawData/{entity}"; var parameterDefinitionList = new List <ParameterDefinition>(); var filterTree = filter.BuildFilterTree(); var filterString = new FilterTreeFormatter().FormatString(filterTree); var filterParameter = ParameterDefinition.Create("filter", filterString); parameterDefinitionList.Add(filterParameter); return(_RestClient.Request <RawDataInformation[]>(RequestBuilder.CreateGet(requestPath, parameterDefinitionList.ToArray()), cancellationToken)); }
/// <summary> /// Fetches a list of raw data information for the <paramref name="entity"/> identified by <paramref name="uuids"/>. /// </summary> /// <param name="entity">The <see cref="RawDataEntity"/> the raw data information should be fetched for.</param> /// <param name="uuids">The list of value uuids the data information should be fetched for.</param> /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> public async Task <RawDataInformation[]> ListRawData(RawDataEntity entity, string[] uuids, CancellationToken cancellationToken = default(CancellationToken)) { if (entity == RawDataEntity.Value && !uuids.Count(StringUuidTools.IsStringUuidPair).Equals(uuids.Length)) { throw new ArgumentOutOfRangeException("uuids", "The uuid string for uploading raw data for measurement value expects two uuids in this format: measurementUuid|characteristicUuid"); } var result = new List <RawDataInformation>(uuids.Length); var targetSize = MaxUriLength - string.Format("{1}rawData/{0}?uuids={{}}", entity, ServiceLocation).Length; foreach (var uuidList in ArrayHelper.Split(uuids, targetSize, uuid => Uri.EscapeDataString(uuid).Length + 3 /* Lenght of escaped "," */)) { var listString = RestClientHelper.ToListString(string.Join(",", uuidList)); var info = await Get <RawDataInformation[]>(string.Format("rawData/{0}", entity), cancellationToken, ParameterDefinition.Create("uuids", listString)).ConfigureAwait(false); result.AddRange(info); } return(result.ToArray()); }
/// <summary> /// Fetches a list of raw data information for the <paramref name="entity"/> identified by <paramref name="uuids"/> and filtered by <paramref name="filter"/>. /// Either <paramref name="uuids" /> or <paramref name="filter"/> must have a value. /// </summary> /// <param name="entity">The <see cref="RawDataEntity"/> the raw data information should be fetched for.</param> /// <param name="uuids">The list of value uuids the data information should be fetched for.</param> /// <param name="filter">A condition used to filter the result.</param> /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> /// <exception cref="InvalidOperationException">No uuids and no filter was specified.</exception> /// <exception cref="OperationNotSupportedOnServerException">An attribute filter for raw data is not supported by this server.</exception> public async Task <RawDataInformation[]> ListRawData(RawDataEntity entity, string[] uuids, FilterCondition filter, CancellationToken cancellationToken = default(CancellationToken)) { if (uuids == null && filter == null) { throw new InvalidOperationException("Either a filter or at least one uuid must be specified."); } if (filter != null) { var featureMatrix = await GetFeatureMatrixInternal(FetchBehavior.FetchIfNotCached, cancellationToken).ConfigureAwait(false); if (!featureMatrix.SupportsRawDataAttributeFilter) { throw new OperationNotSupportedOnServerException( "An attribute filter for raw data is not supported by this server.", RawDataServiceFeatureMatrix.RawDataAttributeFilterMinVersion, featureMatrix.CurrentInterfaceVersion); } } return(uuids != null ? await ListRawDataByUuidList(entity, uuids, filter, cancellationToken).ConfigureAwait(false) : await ListRawDataForAllEntities(entity, filter, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Creates a new <see cref="RawDataTargetEntity"/> based on the specified <code>uuid</code> and <code>entity</code>. /// </summary> /// <param name="entity">The entity to which this raw data object belongs to.</param> /// <param name="uuid">The uuid of the entity.</param> private RawDataTargetEntity( RawDataEntity entity, Guid uuid ) : this(entity, uuid.ToString()) { }
/// <summary> /// Creates a new <see cref="RawDataTargetEntity"/> based on the specified <code>uuid</code> and <code>entity</code>. /// </summary> /// <param name="entity">The entity to which this raw data object belongs to.</param> /// <param name="uuid">The uuid of the entity.</param> public RawDataTargetEntity( RawDataEntity entity, string uuid ) { Entity = entity; Uuid = uuid; }
/// <summary> /// Creates a new <see cref="RawDataTargetEntity"/> based on the specified <code>uuid</code> and <code>entity</code>. /// </summary> /// <param name="entity">The entity to which this raw data object belongs to.</param> /// <param name="uuid">The uuid of the entity.</param> public RawDataTargetEntity(RawDataEntity entity, string uuid) { Entity = entity; Uuid = uuid; }
/// <summary> /// Creates a new <see cref="RawDataTargetEntity"/> based on the specified <code>uuid</code> and <code>entity</code>. /// </summary> /// <param name="entity">The entity to which this raw data object belongs to.</param> /// <param name="uuid">The uuid of the entity.</param> private RawDataTargetEntity(RawDataEntity entity, Guid uuid) : this(entity, uuid.ToString()) { }
/// <summary> /// Fetches a list of raw data information for the <paramref name="entity"/> identified by <paramref name="uuids"/>. /// </summary> /// <param name="entity">The <see cref="RawDataEntity"/> the raw data information should be fetched for.</param> /// <param name="uuids">The list of value uuids the data information should be fetched for.</param> /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param> public async Task<RawDataInformation[]> ListRawData( RawDataEntity entity, string[] uuids, CancellationToken cancellationToken = default( CancellationToken ) ) { if( entity == RawDataEntity.Value && !uuids.Count( StringUuidTools.IsStringUuidPair ).Equals( uuids.Length ) ) throw new ArgumentOutOfRangeException( "uuids", "The uuid string for uploading raw data for measurement value expects two uuids in this format: measurementUuid|characteristicUuid" ); var result = new List<RawDataInformation>( uuids.Length ); var targetSize = MaxUriLength - string.Format( "{1}rawData/{0}?uuids={{}}", entity, ServiceLocation ).Length; foreach( var uuidList in ArrayHelper.Split( uuids, targetSize, uuid => Uri.EscapeDataString( uuid ).Length + 3 /* Lenght of escaped "," */ ) ) { var listString = RestClientHelper.ToListString( string.Join( ",", uuidList ) ); var info = await Get<RawDataInformation[]>( string.Format( "rawData/{0}", entity ), cancellationToken, ParameterDefinition.Create( "uuids", listString ) ).ConfigureAwait( false ); result.AddRange( info ); } return result.ToArray(); }