Beispiel #1
0
        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());
        }
Beispiel #2
0
        /// <inheritdoc />
        public async Task <SimpleMeasurementDto[]> GetMeasurements(PathInformationDto partPath = null, MeasurementFilterAttributesDto filter = null, CancellationToken cancellationToken = default)
        {
            if (filter?.MergeAttributes?.Length > 0)
            {
                var featureMatrix = await GetFeatureMatrixInternal(FetchBehavior.FetchIfNotCached, cancellationToken).ConfigureAwait(false);

                if (!featureMatrix.SupportsRestrictMeasurementSearchByMergeAttributes)
                {
                    throw new OperationNotSupportedOnServerException(
                              "Restricting measurement search by merge attributes is not supported by this server.",
                              DataServiceFeatureMatrix.RestrictMeasurementSearchByMergeAttributesMinVersion,
                              featureMatrix.CurrentInterfaceVersion);
                }
            }

            if (filter?.MergeMasterPart != null)
            {
                var featureMatrix = await GetFeatureMatrixInternal(FetchBehavior.FetchIfNotCached, cancellationToken).ConfigureAwait(false);

                if (!featureMatrix.SupportRestrictMeasurementSearchByMergeMasterPart)
                {
                    throw new OperationNotSupportedOnServerException(
                              "Restricting measurement search by merge master part is not supported by this server.",
                              DataServiceFeatureMatrix.RestrictMeasurementSearchByMergeAttributesMinVersion,
                              featureMatrix.CurrentInterfaceVersion);
                }
            }

            const string requestPath = "measurements";

            // split multiple measurement uuids into chunks of uuids using multiple requests to avoid "Request-URI Too Long" exception
            if (filter?.MeasurementUuids?.Length > 0)
            {
                var newFilter = filter.Clone();
                newFilter.MeasurementUuids = null;

                var parameterName        = AbstractMeasurementFilterAttributesDto.MeasurementUuidsParamName;
                var parameterDefinitions = CreateParameterDefinitions(partPath, newFilter);

                //Split into multiple parameter sets to limit uuid parameter lenght
                var splitter            = new ParameterSplitter(this, requestPath);
                var collectionParameter = CollectionParameterFactory.Create(parameterName, filter.MeasurementUuids);
                var parameterSets       = splitter.SplitAndMerge(collectionParameter, parameterDefinitions);

                //Execute requests in parallel
                var requests = parameterSets
                               .Select(set => RequestBuilder.CreateGet(requestPath, set.ToArray()))
                               .Select(request => _RestClient.Request <SimpleMeasurementDto[]>(request, cancellationToken));
                var result = await Task.WhenAll(requests).ConfigureAwait(false);

                return(result.SelectMany(r => r).ToArray());
            }

            // split multiple part uuids into chunks of uuids using multiple requests to avoid "Request-URI Too Long" exception
            if (filter?.PartUuids?.Length > 0)
            {
                var newFilter = filter.Clone();
                newFilter.PartUuids = null;

                const string parameterName        = AbstractMeasurementFilterAttributesDto.PartUuidsParamName;
                var          parameterDefinitions = CreateParameterDefinitions(partPath, newFilter);

                //Split into multiple parameter sets to limit uuid parameter lenght
                var splitter            = new ParameterSplitter(this, requestPath);
                var collectionParameter = CollectionParameterFactory.Create(parameterName, filter.PartUuids);
                var parameterSets       = splitter.SplitAndMerge(collectionParameter, parameterDefinitions);

                //Execute requests in parallel
                var requests = parameterSets
                               .Select(set => RequestBuilder.CreateGet(requestPath, set.ToArray()))
                               .Select(request => _RestClient.Request <SimpleMeasurementDto[]>(request, cancellationToken));
                var result = await Task.WhenAll(requests).ConfigureAwait(false);

                return(result.SelectMany(r => r).ToArray());
            }

            {
                var parameterDefinitions = CreateParameterDefinitions(partPath, filter).ToArray();
                var requestUrl           = RequestBuilder.CreateGet(requestPath, parameterDefinitions);
                return(await _RestClient.Request <SimpleMeasurementDto[]>(requestUrl, cancellationToken).ConfigureAwait(false));
            }
        }