/// <inheritdoc /> public async Task <DataMeasurementDto[]> GetMeasurementValues(PathInformationDto partPath = null, MeasurementValueFilterAttributesDto 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?.MeasurementUuids?.Length > 0) { return(await GetMeasurementValuesSplitByMeasurement(partPath, filter, cancellationToken).ConfigureAwait(false)); } if (filter?.CharacteristicsUuidList?.Length > 0) { return(await GetMeasurementValuesSplitByCharacteristics(partPath, filter, cancellationToken).ConfigureAwait(false)); } return(await _RestClient.Request <DataMeasurementDto[]>(RequestBuilder.CreateGet("values", CreateParameterDefinitions(partPath, filter).ToArray()), cancellationToken).ConfigureAwait(false)); }
/// <inheritdoc /> /// <exception cref="ArgumentNullException"><paramref name="charPath"/> is <see langword="null"/>.</exception> public Task DeleteCharacteristics(PathInformationDto charPath, CancellationToken cancellationToken = default) { if (charPath == null) { throw new ArgumentNullException(nameof(charPath)); } var parameter = ParameterDefinition.Create("charPath", PathHelper.PathInformation2DatabaseString(charPath)); return(_RestClient.Request(RequestBuilder.CreateDelete("characteristics", parameter), cancellationToken)); }
/// <summary> /// Parses inspection plan filter criterias to a <see cref="ParameterDefinition"/> list. /// </summary> /// <param name="partPath">Path of the part the query should be restricted by.</param> /// <param name="partUuids">Uuids of the parts the query should be restricted by.</param> /// <param name="charUuids">Uuids of the parts the query should be restricted by.</param> /// <param name="depth">The depth determines how deep the response should be.</param> /// <param name="requestedPartAttributes">Restricts the part attributes that are returned.</param> /// <param name="requestedCharacteristicAttributes">Restricts the characteristic attributes that are returned.</param> /// <param name="withHistory">Determines if the history should be returned.</param> /// <returns></returns> public static List <ParameterDefinition> ParseToParameter(PathInformationDto partPath = null, Guid[] partUuids = null, Guid[] charUuids = null, ushort?depth = null, AttributeSelector requestedPartAttributes = null, AttributeSelector requestedCharacteristicAttributes = null, bool withHistory = false) { var parameter = new List <ParameterDefinition>(); if (partPath != null) { parameter.Add(ParameterDefinition.Create("partPath", PathHelper.PathInformation2DatabaseString(partPath))); } if (depth.HasValue) { parameter.Add(ParameterDefinition.Create("depth", depth.ToString())); } if (withHistory) { parameter.Add(ParameterDefinition.Create("withHistory", true.ToString())); } if (partUuids != null && partUuids.Length > 0) { parameter.Add(ParameterDefinition.Create("partUuids", ConvertGuidListToString(partUuids))); } if (charUuids != null && charUuids.Length > 0) { parameter.Add(ParameterDefinition.Create("charUuids", ConvertGuidListToString(charUuids))); } if (requestedPartAttributes != null) { if (requestedPartAttributes.AllAttributes != AllAttributeSelectionDto.True && requestedPartAttributes.Attributes != null) { parameter.Add(ParameterDefinition.Create("requestedPartAttributes", ConvertUshortArrayToString(requestedPartAttributes.Attributes))); } else if (requestedPartAttributes.AllAttributes == AllAttributeSelectionDto.False) { parameter.Add(ParameterDefinition.Create("requestedPartAttributes", "None")); } } if (requestedCharacteristicAttributes != null) { if (requestedCharacteristicAttributes.AllAttributes != AllAttributeSelectionDto.True && requestedCharacteristicAttributes.Attributes != null) { parameter.Add(ParameterDefinition.Create("requestedCharacteristicAttributes", ConvertUshortArrayToString(requestedCharacteristicAttributes.Attributes))); } else if (requestedCharacteristicAttributes.AllAttributes == AllAttributeSelectionDto.False) { parameter.Add(ParameterDefinition.Create("requestedCharacteristicAttributes", "None")); } } return(parameter); }
public static string GetStructure([NotNull] PathInformationDto path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var result = new char[path.Count]; for (var i = 0; i < path.Count; i++) { result[i] = path[i].Type == InspectionPlanEntityDto.Part ? 'P' : 'C'; } return(new string( result )); }
public static string PathInformation2String([NotNull] PathInformationDto path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } // fast code path for root path if (path.IsRoot) { return(DelimiterString); } var sb = new StringBuilder(25); PathInformation2StringInternal(sb, path); return(sb.ToString()); }
private static List <ParameterDefinition> CreateParameterDefinitions <T>(PathInformationDto partPath, T filter, int?key = null) where T : AbstractMeasurementFilterAttributesDto { var parameter = new List <ParameterDefinition>(); if (filter != null) { parameter.AddRange(filter.ToParameterDefinition()); } if (partPath != null) { parameter.Add(ParameterDefinition.Create("partPath", PathHelper.PathInformation2DatabaseString(partPath))); } if (key.HasValue) { parameter.Add(ParameterDefinition.Create("key", key.ToString())); } return(parameter); }
public static string PathInformation2RoundtripString([NotNull] PathInformationDto path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } // fast code path for root path if (path.IsRoot) { return(DelimiterString); } var sb = new StringBuilder(25); sb.Append(GetStructure(path)); sb.Append(":"); sb.Append(PathInformation2DatabaseString(path)); return(sb.ToString()); }
/// <inheritdoc /> public async Task <IEnumerable <InspectionPlanPartDto> > GetParts(PathInformationDto partPath = null, Guid[] partUuids = null, ushort?depth = null, AttributeSelector requestedPartAttributes = null, bool withHistory = false, CancellationToken cancellationToken = default) { if (partUuids != null && partUuids.Length > 0) { var result = new List <InspectionPlanPartDto>(partUuids.Length); foreach (var uuid in partUuids) { var inspectionPlanPart = await GetPartByUuid(uuid, requestedPartAttributes, withHistory, cancellationToken).ConfigureAwait(false); if (inspectionPlanPart != null) { result.Add(inspectionPlanPart); } } return(result); } var parameter = RestClientHelper.ParseToParameter(partPath, partUuids, null, depth, requestedPartAttributes, withHistory: withHistory); return(await _RestClient.Request <InspectionPlanPartDto[]>(RequestBuilder.CreateGet("parts", parameter.ToArray()), cancellationToken).ConfigureAwait(false)); }
/// <inheritdoc /> public async Task DeleteMeasurementsByPartPath(PathInformationDto partPath = null, GenericSearchConditionDto filter = null, AggregationMeasurementSelectionDto aggregation = AggregationMeasurementSelectionDto.Default, MeasurementDeleteBehaviorDto deep = MeasurementDeleteBehaviorDto.DeleteForCurrentPartOnly, CancellationToken cancellationToken = default) { var parameter = new List <ParameterDefinition>(); if (partPath != null) { parameter.Add(ParameterDefinition.Create("partPath", PathHelper.PathInformation2DatabaseString(partPath))); } if (filter != null) { parameter.Add(ParameterDefinition.Create("searchCondition", SearchConditionParser.GenericConditionToString(filter))); } if (aggregation != AggregationMeasurementSelectionDto.Default) { parameter.Add(ParameterDefinition.Create("aggregation", aggregation.ToString())); } if (deep == MeasurementDeleteBehaviorDto.DeleteDeep) { var featureMatrix = await GetFeatureMatrixInternal(FetchBehavior.FetchIfNotCached, cancellationToken).ConfigureAwait(false); if (!featureMatrix.SupportsDeleteMeasurementsForSubParts) { throw new OperationNotSupportedOnServerException( "Deleting measurements for sub parts is not supported by this server.", DataServiceFeatureMatrix.DeleteMeasurementsForSubPartsMinVersion, featureMatrix.CurrentInterfaceVersion); } parameter.Add(ParameterDefinition.Create("deep", deep.ToString())); } await _RestClient.Request(RequestBuilder.CreateDelete("measurements", parameter.ToArray()), cancellationToken).ConfigureAwait(false); }
private async Task <DataMeasurementDto[]> GetMeasurementValuesSplitByMeasurement(PathInformationDto partPath, MeasurementValueFilterAttributesDto filter, CancellationToken cancellationToken) { var newFilter = filter.Clone(); newFilter.MeasurementUuids = null; var parameter = CreateParameterDefinitions(partPath, newFilter); parameter.Add(ParameterDefinition.Create(AbstractMeasurementFilterAttributesDto.MeasurementUuidsParamName, "")); var requestRestriction = RequestBuilder.AppendParameters("values", parameter); var targetSize = RestClientHelper.GetUriTargetSize(ServiceLocation, requestRestriction, MaxUriLength); var result = new List <DataMeasurementDto>(filter.MeasurementUuids.Length); foreach (var uuids in ArrayHelper.Split(filter.MeasurementUuids, targetSize, RestClientHelper.LengthOfListElementInUri)) { newFilter.MeasurementUuids = uuids; if (newFilter.CharacteristicsUuidList?.Length > 0) { result.AddRange(await GetMeasurementValuesSplitByCharacteristics(partPath, newFilter, cancellationToken).ConfigureAwait(false)); } else { result.AddRange(await _RestClient.Request <DataMeasurementDto[]>(RequestBuilder.CreateGet("values", CreateParameterDefinitions(partPath, newFilter).ToArray()), cancellationToken).ConfigureAwait(false)); } } return(result.ToArray()); }
/// <inheritdoc /> public async Task <string[]> GetDistinctMeasurementAttributeValues(ushort key, PathInformationDto partPath = null, DistinctMeasurementFilterAttributesDto filter = null, CancellationToken cancellationToken = default) { var featureMatrix = await GetFeatureMatrixInternal(FetchBehavior.FetchIfNotCached, cancellationToken).ConfigureAwait(false); if (!featureMatrix.SupportsDistinctMeasurementAttributeValuesSearch) { throw new OperationNotSupportedOnServerException( "Fetching distinct measurement values is not supported by this server.", DataServiceFeatureMatrix.DistinctMeasurementAttributsValuesSearchMinVersion, featureMatrix.CurrentInterfaceVersion); } if (filter?.MeasurementUuids?.Length > 0) { var newFilter = filter.Clone(); newFilter.MeasurementUuids = null; var parameter = CreateParameterDefinitions(partPath, newFilter, key); parameter.Add(ParameterDefinition.Create(AbstractMeasurementFilterAttributesDto.MeasurementUuidsParamName, "")); var requestRestriction = RequestBuilder.AppendParameters("values", parameter); var targetSize = RestClientHelper.GetUriTargetSize(ServiceLocation, requestRestriction, MaxUriLength); var result = new List <string>(filter.MeasurementUuids.Length); foreach (var uuids in ArrayHelper.Split(filter.MeasurementUuids, targetSize, RestClientHelper.LengthOfListElementInUri)) { newFilter.MeasurementUuids = uuids; var attributes = await _RestClient.Request <string[]>(RequestBuilder.CreateGet("distinctMeasurementAttributeValues", CreateParameterDefinitions(partPath, newFilter, key).ToArray()), cancellationToken).ConfigureAwait(false); result.AddRange(attributes); } return(result.ToArray()); } return(await _RestClient.Request <string[]>(RequestBuilder.CreateGet("distinctMeasurementAttributeValues", CreateParameterDefinitions(partPath, filter, key).ToArray()), cancellationToken).ConfigureAwait(false)); }
/// <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)); } }
/// <inheritdoc /> public async Task <IEnumerable <InspectionPlanCharacteristicDto> > GetCharacteristics(PathInformationDto partPath = null, ushort?depth = null, AttributeSelector requestedCharacteristicAttributes = null, bool withHistory = false, CancellationToken cancellationToken = default) { var parameter = RestClientHelper.ParseToParameter(partPath, null, null, depth, null, requestedCharacteristicAttributes, withHistory); return(await _RestClient.Request <InspectionPlanCharacteristicDto[]>(RequestBuilder.CreateGet("characteristics", parameter.ToArray()), cancellationToken).ConfigureAwait(false)); }
private async Task <DataMeasurementDto[]> GetMeasurementValuesSplitByCharacteristics(PathInformationDto partPath, MeasurementValueFilterAttributesDto filter, CancellationToken cancellationToken) { var newFilter = filter.Clone(); newFilter.CharacteristicsUuidList = null; var parameter = CreateParameterDefinitions(partPath, newFilter); parameter.Add(ParameterDefinition.Create(MeasurementValueFilterAttributesDto.CharacteristicsUuidListParamName, "")); var requestRestriction = RequestBuilder.AppendParameters("values", parameter); var targetSize = RestClientHelper.GetUriTargetSize(ServiceLocation, requestRestriction, MaxUriLength); var result = new List <DataMeasurementDto>(filter.MeasurementUuids?.Length ?? 0); var allMeasurements = new Dictionary <Guid, DataMeasurementDto>(); foreach (var uuids in ArrayHelper.Split(filter.CharacteristicsUuidList, targetSize, RestClientHelper.LengthOfListElementInUri)) { newFilter.CharacteristicsUuidList = uuids; var measurements = await _RestClient.Request <DataMeasurementDto[]>(RequestBuilder.CreateGet("values", CreateParameterDefinitions(partPath, newFilter).ToArray()), cancellationToken).ConfigureAwait(false); foreach (var measurement in measurements) { if (allMeasurements.TryGetValue(measurement.Uuid, out var existingMeasurement)) { existingMeasurement.Characteristics = Combine(existingMeasurement.Characteristics, measurement.Characteristics); } else { result.Add(measurement); allMeasurements.Add(measurement.Uuid, measurement); } } } return(result.ToArray()); }
private static void PathInformation2StringInternal([NotNull] StringBuilder sb, [NotNull] PathInformationDto path) { var count = path.Count; for (var i = 0; i < path.Count; i++) { sb.Append(path[i].Value.Replace(@"\", @"\\").Replace(DelimiterString, EscapedDelimiter)); if ((i + 1) < count) { sb.Append(Delimiter); } } }