Esempio n. 1
0
        /// <summary>
        /// Creates a <see cref="ParameterDefinition"/> list that represents this filter.
        /// </summary>
        public ParameterDefinition[] ToParameterDefinition()
        {
            var result = new List <ParameterDefinition>();

            if (Deep)
            {
                result.Add(ParameterDefinition.Create(DeepParamName, Deep.ToString()));
            }

            if (LimitResult >= 0)
            {
                result.Add(ParameterDefinition.Create(LimitResultParamName, LimitResult.ToString()));
            }

            if (MeasurementUuids != null && MeasurementUuids.Length > 0)
            {
                result.Add(ParameterDefinition.Create(MeasurementUuidsParamName, RestClientHelper.ConvertGuidListToString(MeasurementUuids)));
            }

            if (RequestedMeasurementAttributes != null && RequestedMeasurementAttributes.AllAttributes != AllAttributeSelection.True && RequestedMeasurementAttributes.Attributes != null)
            {
                result.Add(ParameterDefinition.Create(RequestedMeasurementAttributesParamName, RestClientHelper.ConvertUInt16ListToString(RequestedMeasurementAttributes.Attributes)));
            }

            if (OrderBy != null && OrderBy.Length > 0)
            {
                result.Add(ParameterDefinition.Create(OrderByParamName, OrderByToString(OrderBy)));
            }

            if (SearchCondition != null)
            {
                result.Add(ParameterDefinition.Create(SearchConditionParamName, SearchConditionParser.GenericConditionToString(SearchCondition)));
            }

            if (Statistics != MeasurementStatistics.None)
            {
                result.Add(ParameterDefinition.Create(StatisticsParamName, Statistics.ToString()));
            }

            if (AggregationMeasurements != AggregationMeasurementSelection.Default)
            {
                result.Add(ParameterDefinition.Create(AggregationParamName, AggregationMeasurements.ToString()));
            }

            if (FromModificationDate.HasValue)
            {
                result.Add(ParameterDefinition.Create(FromModificationDateParamName, XmlConvert.ToString(FromModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind)));
            }

            if (ToModificationDate.HasValue)
            {
                result.Add(ParameterDefinition.Create(ToModificationDateParamName, XmlConvert.ToString(ToModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind)));
            }

            return(result.ToArray());
        }
Esempio n. 2
0
        /// <inheritdoc />
        public async Task DeleteMeasurementsByPartUuids(Guid[] partUuids, GenericSearchConditionDto filter = null, AggregationMeasurementSelectionDto aggregation = AggregationMeasurementSelectionDto.Default, CancellationToken cancellationToken = default)
        {
            if (partUuids == null)
            {
                var parameter = new List <ParameterDefinition>();

                if (filter != null)
                {
                    parameter.Add(ParameterDefinition.Create("searchCondition", SearchConditionParser.GenericConditionToString(filter)));
                }

                if (aggregation != AggregationMeasurementSelectionDto.Default)
                {
                    parameter.Add(ParameterDefinition.Create("aggregation", aggregation.ToString()));
                }

                await _RestClient.Request(RequestBuilder.CreateDelete("measurements", parameter.ToArray()), cancellationToken).ConfigureAwait(false);
            }
            else
            {
                foreach (var partUuid in partUuids)
                {
                    var parameter = new List <ParameterDefinition> {
                        ParameterDefinition.Create("partUuids", RestClientHelper.ConvertGuidListToString(new[] { partUuid }))
                    };

                    if (filter != null)
                    {
                        parameter.Add(ParameterDefinition.Create("searchCondition", SearchConditionParser.GenericConditionToString(filter)));
                    }

                    if (aggregation != AggregationMeasurementSelectionDto.Default)
                    {
                        parameter.Add(ParameterDefinition.Create("aggregation", aggregation.ToString()));
                    }

                    await _RestClient.Request(RequestBuilder.CreateDelete("measurements", parameter.ToArray()), cancellationToken).ConfigureAwait(false);
                }
            }
        }
Esempio n. 3
0
        /// <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);
        }
        /// <summary>
        /// Parses the filter and returns a <see cref="MeasurementFilterAttributes"/> object that represents the filter values.
        /// If the parse operation was not successful, an <see cref="InvalidOperationException"/> will be thrown.
        /// </summary>
        /// <returns>The <see cref="MeasurementFilterAttributes"/> with the parsed information.</returns>
        public static MeasurementFilterAttributes Parse(
            string partUuids,
            string measurementUuids,
            string deep,
            string limitResult,
            string order,
            string requestedMeasurementAttributes,
            string searchCondition,
            string statistics,
            string aggregation,
            string fromModificationDate,
            string toModificationDate,
            string mergeAttributes,
            string mergeCondition,
            string mergeMasterPart)
        {
            var items = new[]
            {
                Tuple.Create(PartUuidsParamName, partUuids),
                Tuple.Create(MeasurementUuidsParamName, measurementUuids),
                Tuple.Create(DeepParamName, deep),
                Tuple.Create(LimitResultParamName, limitResult),
                Tuple.Create(OrderByParamName, order),
                Tuple.Create(RequestedMeasurementAttributesParamName, requestedMeasurementAttributes),
                Tuple.Create(SearchConditionParamName, searchCondition),
                Tuple.Create(StatisticsParamName, statistics),
                Tuple.Create(AggregationParamName, aggregation),
                Tuple.Create(FromModificationDateParamName, fromModificationDate),
                Tuple.Create(ToModificationDateParamName, toModificationDate),
                Tuple.Create(MergeAttributesParamName, mergeAttributes),
                Tuple.Create(MergeConditionParamName, mergeCondition),
                Tuple.Create(MergeMasterPartParamName, mergeMasterPart)
            };

            var result = new MeasurementFilterAttributes();

            foreach (var item in items)
            {
                var key   = item.Item1;
                var value = item.Item2;

                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }

                try
                {
                    switch (key)
                    {
                    case PartUuidsParamName:
                        result.PartUuids = RestClientHelper.ConvertStringToGuidList(value);
                        break;

                    case DeepParamName:
                        result.Deep = bool.Parse(value);
                        break;

                    case MeasurementUuidsParamName:
                        result.MeasurementUuids = RestClientHelper.ConvertStringToGuidList(value);
                        break;

                    case LimitResultParamName:
                        result.LimitResult = int.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case RequestedMeasurementAttributesParamName:
                        result.RequestedMeasurementAttributes = new AttributeSelector(RestClientHelper.ConvertStringToUInt16List(value));
                        break;

                    case OrderByParamName:
                        result.OrderBy = value.Split(',').Select(ParseOrderBy).ToArray();
                        break;

                    case SearchConditionParamName:
                        result.SearchCondition = SearchConditionParser.Parse(value);
                        break;

                    case StatisticsParamName:
                        result.Statistics = ( MeasurementStatistics )Enum.Parse(typeof(MeasurementStatistics), value);
                        break;

                    case AggregationParamName:
                        result.AggregationMeasurements = ( AggregationMeasurementSelection )Enum.Parse(typeof(AggregationMeasurementSelection), value);
                        break;

                    case ToModificationDateParamName:
                        result.ToModificationDate = XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind);
                        break;

                    case FromModificationDateParamName:
                        result.FromModificationDate = XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.RoundtripKind);
                        break;

                    case MergeAttributesParamName:
                        result.MergeAttributes = RestClientHelper.ConvertStringToUInt16List(value);
                        break;

                    case MergeConditionParamName:
                        result.MergeCondition = (MeasurementMergeCondition)Enum.Parse(typeof(MeasurementMergeCondition), value);
                        break;

                    case MergeMasterPartParamName:
                        result.MergeMasterPart = string.IsNullOrWhiteSpace(value) ? (Guid?)null : Guid.Parse(value);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException(string.Format("Invalid filter value '{0}' for parameter '{1}'. The can be specified via url parameter in the form of 'key=value'. The following keys are valid: {2}",
                                                                      value, key,
                                                                      "partUuids: [list of part uuids]\r\n" +
                                                                      "deep: [True|False]\r\n" +
                                                                      "limitResult: [short]\r\n" +
                                                                      "measurementUuids: [list of measurement uuids]\r\n" +
                                                                      "measurementAttributes: [attribute keys csv|Empty for all attributes]\r\n" +
                                                                      "orderBy:[ushort asc|desc, ushort asc|desc, ...]\r\n" +
                                                                      "searchCondition:[search filter string]\r\n" +
                                                                      "aggregation:[Measurements|AggregationMeasurements|Default|All]\r\n" +
                                                                      "statistics:[None|Simple|Detailed]\r\n" +
                                                                      "mergeAttributes:[list of measurement attributes]\r\n" +
                                                                      "mergeCondition: [None|MeasurementsInAtLeastTwoParts|MeasurementsInAllParts]\r\n" +
                                                                      "mergeMasterPart: [part uuid]\r\n" +
                                                                      "fromModificationDate:[Date]\r\n" +
                                                                      "toModificationDate:[Date]"), ex);
                }
            }
            return(result);
        }
        /// <summary>
        /// Deletes the measurements including the measurement values for part <paramref name="partPath"/>. The <paramref name="filter"/> can be used
        /// to restrict the measurements. If the filter is empty, all measurements for the specified part will be deleted. If the partPath is empty,
        /// all measurements from the whole database will be deleted.
        /// </summary>
        /// <param name="partPath">The part path to delete the measurements from.</param>
        /// <param name="filter">A filter to restruct the delete operation.</param>
        /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
        public Task DeleteMeasurements(PathInformation partPath = null, GenericSearchCondition filter = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (filter != null)
            {
                return(Delete(string.Format("measurements?partPath={0}&searchCondition={1}", PathHelper.PathInformation2String(partPath), SearchConditionParser.GenericConditionToString(filter)), cancellationToken));
            }

            return(Delete(string.Format("measurements?partPath={0}", PathHelper.PathInformation2String(partPath)), cancellationToken));
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a <see cref="ParameterDefinition"/> list that represents this filter.
        /// </summary>
        public override ParameterDefinition[] ToParameterDefinition()
        {
            var result = new List <ParameterDefinition>();

            if (PartUuids != null && PartUuids.Length > 0)
            {
                result.Add(ParameterDefinition.Create(PartUuidsParamName, RestClientHelper.ConvertGuidListToString(PartUuids)));
            }

            if (Deep)
            {
                result.Add(ParameterDefinition.Create(DeepParamName, Deep.ToString()));
            }

            if (LimitResult >= 0)
            {
                result.Add(ParameterDefinition.Create(LimitResultParamName, LimitResult.ToString()));
            }

            if (MeasurementUuids != null && MeasurementUuids.Length > 0)
            {
                result.Add(ParameterDefinition.Create(MeasurementUuidsParamName, RestClientHelper.ConvertGuidListToString(MeasurementUuids)));
            }

            if (CharacteristicsUuidList != null && CharacteristicsUuidList.Length > 0)
            {
                result.Add(ParameterDefinition.Create(CharacteristicsUuidListParamName, RestClientHelper.ConvertGuidListToString(CharacteristicsUuidList)));
            }

            if (RequestedValueAttributes != null && RequestedValueAttributes.AllAttributes != AllAttributeSelection.True && RequestedValueAttributes.Attributes != null)
            {
                result.Add(ParameterDefinition.Create(RequestedValueAttributesParamName, RestClientHelper.ConvertUshortArrayToString(RequestedValueAttributes.Attributes)));
            }

            if (RequestedMeasurementAttributes != null && RequestedMeasurementAttributes.AllAttributes != AllAttributeSelection.True && RequestedMeasurementAttributes.Attributes != null)
            {
                result.Add(ParameterDefinition.Create(RequestedMeasurementAttributesParamName, RestClientHelper.ConvertUshortArrayToString(RequestedMeasurementAttributes.Attributes)));
            }

            if (OrderBy != null && OrderBy.Length > 0)
            {
                result.Add(ParameterDefinition.Create(OrderByParamName, MeasurementFilterAttributes.OrderByToString(OrderBy)));
            }

            if (SearchCondition != null)
            {
                result.Add(ParameterDefinition.Create(SearchConditionParamName, SearchConditionParser.GenericConditionToString(SearchCondition)));
            }

            if (AggregationMeasurements != AggregationMeasurementSelection.Default)
            {
                result.Add(ParameterDefinition.Create(AggregationParamName, AggregationMeasurements.ToString()));
            }

            if (FromModificationDate.HasValue)
            {
                result.Add(ParameterDefinition.Create(FromModificationDateParamName, XmlConvert.ToString(FromModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind)));
            }

            if (ToModificationDate.HasValue)
            {
                result.Add(ParameterDefinition.Create(ToModificationDateParamName, XmlConvert.ToString(ToModificationDate.Value, XmlDateTimeSerializationMode.RoundtripKind)));
            }

            if (MergeAttributes != null && MergeAttributes.Length > 0)
            {
                result.Add(ParameterDefinition.Create(MergeAttributesParamName, RestClientHelper.ConvertUshortArrayToString(MergeAttributes)));
            }

            if (MergeCondition != MeasurementMergeCondition.MeasurementsInAllParts)
            {
                result.Add(ParameterDefinition.Create(MergeConditionParamName, MergeCondition.ToString()));
            }

            if (MergeMasterPart != null)
            {
                result.Add(ParameterDefinition.Create(MergeMasterPartParamName, MergeMasterPart.ToString()));
            }

            return(result.ToArray());
        }