public static CollectionParameterDefinition <Guid> Create(string name, IEnumerable <Guid> values)
        {
            var conversion = new Func <IEnumerable <Guid>, string>(
                guids => RestClientHelper.ConvertGuidListToString(guids.ToArray()));

            return(new CollectionParameterDefinition <Guid>(name, values, conversion));
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="ParameterDefinition"/> list that represents this filter.
        /// </summary>
        public IEnumerable <ParameterDefinition> ToParameterDefinition()
        {
            var result = new List <ParameterDefinition>();

            if (Depth.HasValue)
            {
                result.Add(ParameterDefinition.Create(DepthParamName, Depth.ToString()));
            }

            if (WithHistory)
            {
                result.Add(ParameterDefinition.Create(WithHistoryParamName, WithHistory.ToString()));
            }

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

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

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

            return(result);
        }
        /// <summary>
        /// Deletes the specified catalogs including their entries from the database. If the parameter <paramref name="catalogUuids"/>
        /// is empty, all catalogs will be deleted.
        /// </summary>
        /// <param name="catalogUuids">The catalog uuids to delete.</param>
        /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
        public Task DeleteCatalogs(Guid[] catalogUuids = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (catalogUuids != null && catalogUuids.Length > 0)
            {
                return(Delete(string.Format("catalogs/{0}", RestClientHelper.ConvertGuidListToString(catalogUuids)), cancellationToken));
            }

            return(Delete("catalogs", cancellationToken));
        }
Пример #4
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());
        }
Пример #5
0
        /// <inheritdoc />
        public async Task DeleteCharacteristics(Guid[] charUuid, CancellationToken cancellationToken = default)
        {
            const string requestPath = "characteristics";
            var          targetSize  = RestClientHelper.GetUriTargetSize(ServiceLocation, requestPath, MaxUriLength, ParameterDefinition.Create("charUuids", "{}"));

            foreach (var uuidList in ArrayHelper.Split(charUuid, targetSize, RestClientHelper.LengthOfListElementInUri))
            {
                var uuidListParameter = ParameterDefinition.Create("charUuids", RestClientHelper.ConvertGuidListToString(uuidList));
                await _RestClient.Request(RequestBuilder.CreateDelete(requestPath, uuidListParameter), cancellationToken).ConfigureAwait(false);
            }
        }
Пример #6
0
        /// <inheritdoc />
        public async Task DeleteMeasurementsByUuid(Guid[] measurementUuids, CancellationToken cancellationToken = default)
        {
            if (measurementUuids.Any())
            {
                var emptyParameter     = new[] { ParameterDefinition.Create("measurementUuids", "") };
                var requestRestriction = RequestBuilder.AppendParameters("measurements", emptyParameter);

                var targetSize = RestClientHelper.GetUriTargetSize(ServiceLocation, requestRestriction, MaxUriLength);

                foreach (var uuids in ArrayHelper.Split(measurementUuids, targetSize, RestClientHelper.LengthOfListElementInUri))
                {
                    var parameter = ParameterDefinition.Create("measurementUuids", RestClientHelper.ConvertGuidListToString(uuids));
                    await _RestClient.Request(RequestBuilder.CreateDelete("measurements", parameter), cancellationToken).ConfigureAwait(false);
                }
            }
        }
Пример #7
0
        /// <inheritdoc />
        public async Task DeleteCatalogs(Guid[] catalogUuids = null, CancellationToken cancellationToken = default)
        {
            const string uri = "catalogs";

            if (catalogUuids == null || catalogUuids.Length == 0)
            {
                await _RestClient.Request(RequestBuilder.CreateDelete(uri), cancellationToken).ConfigureAwait(false);
            }
            else
            {
                //As the keys are passed as path segment within the uri target size is set to maximum length of path segemnts: 255
                foreach (var catUuids in ArrayHelper.Split(catalogUuids, RestClientBase.MaximumPathSegmentLength, RestClientHelper.LengthOfListElementInUri))
                {
                    var restriction = $"/{RestClientHelper.ConvertGuidListToString( catUuids )}";
                    await _RestClient.Request(RequestBuilder.CreateDelete(string.Concat(uri, restriction)), cancellationToken).ConfigureAwait(false);
                }
            }
        }
Пример #8
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);
                }
            }
        }
 /// <summary>
 /// Deletes the measurements that are part of the <paramref name="measurementUuids"/> list.
 /// </summary>
 /// <param name="measurementUuids">The list of uuids of the measurements to delete.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public Task DeleteMeasurements(Guid[] measurementUuids, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Delete(string.Format("measurements?measurementUuids={0}", RestClientHelper.ConvertGuidListToString(measurementUuids)), cancellationToken));
 }
 /// <summary>
 /// Deletes the characteristics <paramref name="charUuid"/> and their sub characteristics from the database.
 /// </summary>
 /// <param name="charUuid">The characteristic uuid list for the delete operation.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public Task DeleteCharacteristics(Guid[] charUuid, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Delete(string.Format("characteristics?charUuids={0}", RestClientHelper.ConvertGuidListToString(charUuid)), cancellationToken));
 }
 /// <summary>
 /// Deletes all parts and child parts below the parts specified by <paramref name="partUuids"/> from the database. Since parts act as the parent
 /// of characteristics and measurements, this call will delete all characteristics and measurements including the measurement
 /// values that are a child of the specified parent part.
 /// </summary>
 /// <param name="partUuids">The uuid list of the parent part for the delete operation.</param>
 /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
 public Task DeleteParts(Guid[] partUuids, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(Delete(string.Format("parts?partUuids={0}", RestClientHelper.ConvertGuidListToString(partUuids)), cancellationToken));
 }
Пример #12
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());
        }