/// <summary>
        /// Parses the filter and returns a <see cref="MeasurementValueFilterAttributes"/> 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="MeasurementValueFilterAttributes"/> with the parsed information.</returns>
        public static MeasurementValueFilterAttributes Parse( string measurementUuids, string characteristicUuids, string deep, string limitResult, string order, string requestedMeasurementAttributes, string requestedValueAttributes, string searchCondition, string aggregation, string fromModificationDate, string toModificationDate )
        {
            var items = new[]
            {
                Tuple.Create( MeasurementUuidsParamName, measurementUuids ),
                Tuple.Create( CharacteristicsUuidListParamName, characteristicUuids ),
                Tuple.Create( DeepParamName, deep ),
                Tuple.Create( LimitResultParamName, limitResult ),
                Tuple.Create( OrderByParamName, order ),
                Tuple.Create( RequestedValueAttributesParamName, requestedValueAttributes ),
                Tuple.Create( RequestedMeasurementAttributesParamName, requestedMeasurementAttributes ),
                Tuple.Create( SearchConditionParamName, searchCondition ),
                Tuple.Create( AggregationParamName, aggregation ),
                Tuple.Create( FromModificationDateParamName, fromModificationDate ),
                Tuple.Create( ToModificationDateParamName, toModificationDate )
            };

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

                if( string.IsNullOrEmpty( value ) )
                    continue;

                try
                {
                    switch( key )
                    {
                        case DeepParamName:
                            result.Deep = bool.Parse( value );
                            break;
                        case MeasurementUuidsParamName:
                            result.MeasurementUuids = RestClientHelper.ConvertStringToGuidList( value );
                            break;
                        case CharacteristicsUuidListParamName:
                            result.CharacteristicsUuidList = RestClientHelper.ConvertStringToGuidList( value );
                            break;
                        case LimitResultParamName:
                            result.LimitResult = short.Parse( value, System.Globalization.CultureInfo.InvariantCulture );
                            break;
                        case RequestedValueAttributesParamName:
                            result.RequestedValueAttributes = new AttributeSelector( RestClientHelper.ConvertStringToUInt16List( value ) );
                            break;
                        case RequestedMeasurementAttributesParamName:
                            result.RequestedMeasurementAttributes = new AttributeSelector( RestClientHelper.ConvertStringToUInt16List( value ) );
                            break;
                        case OrderByParamName:
                            result.OrderBy = value.Split( ',' ).Select( MeasurementFilterAttributes.ParseOrderBy ).ToArray();
                            break;
                        case SearchConditionParamName:
                            result.SearchCondition = SearchConditionParser.Parse( 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;
                    }
                }
                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,
                        "deep = [True|False]\r\n" +
                        "limitResult = [short]\r\n" +
                        "measurementUuids = [list of measurement uuids]\r\n" +
                        "characteristicUuids = [list of characteristic uuids]\r\n" +
                        "valueAttributes = [attribute keys csv|Empty for all attributes]\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" +
                        "fromModificationDate:[Date]\r\n" +
                        "toModificationDate:[Date]" ), ex );
                }
            }
            return result;
        }
Beispiel #2
0
        /// <summary>
        /// Parses the filter and returns a <see cref="MeasurementValueFilterAttributes"/> 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="MeasurementValueFilterAttributes"/> with the parsed information.</returns>
        public static MeasurementValueFilterAttributes Parse(string measurementUuids, string characteristicUuids, string deep, string limitResult, string order, string requestedMeasurementAttributes, string requestedValueAttributes, string searchCondition, string aggregation, string fromModificationDate, string toModificationDate)
        {
            var items = new[]
            {
                Tuple.Create(MeasurementUuidsParamName, measurementUuids),
                Tuple.Create(CharacteristicsUuidListParamName, characteristicUuids),
                Tuple.Create(DeepParamName, deep),
                Tuple.Create(LimitResultParamName, limitResult),
                Tuple.Create(OrderByParamName, order),
                Tuple.Create(RequestedValueAttributesParamName, requestedValueAttributes),
                Tuple.Create(RequestedMeasurementAttributesParamName, requestedMeasurementAttributes),
                Tuple.Create(SearchConditionParamName, searchCondition),
                Tuple.Create(AggregationParamName, aggregation),
                Tuple.Create(FromModificationDateParamName, fromModificationDate),
                Tuple.Create(ToModificationDateParamName, toModificationDate)
            };

            var result = new MeasurementValueFilterAttributes();

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

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

                try
                {
                    switch (key)
                    {
                    case DeepParamName:
                        result.Deep = bool.Parse(value);
                        break;

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

                    case CharacteristicsUuidListParamName:
                        result.CharacteristicsUuidList = RestClientHelper.ConvertStringToGuidList(value);
                        break;

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

                    case RequestedValueAttributesParamName:
                        result.RequestedValueAttributes = new AttributeSelector(RestClientHelper.ConvertStringToUInt16List(value));
                        break;

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

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

                    case SearchConditionParamName:
                        result.SearchCondition = SearchConditionParser.Parse(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;
                    }
                }
                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,
                                                                      "deep = [True|False]\r\n" +
                                                                      "limitResult = [short]\r\n" +
                                                                      "measurementUuids = [list of measurement uuids]\r\n" +
                                                                      "characteristicUuids = [list of characteristic uuids]\r\n" +
                                                                      "valueAttributes = [attribute keys csv|Empty for all attributes]\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" +
                                                                      "fromModificationDate:[Date]\r\n" +
                                                                      "toModificationDate:[Date]"), ex);
                }
            }
            return(result);
        }
        /// <summary>
        /// Fetches a list of measurements and measurement values for the <paramref name="partPath"/>. The search operation
        /// can be parameterized using the specified <paramref name="filter"/>. If the filter is empty, all measurements for
        /// the specified part will be fetched.
        /// </summary>
        /// <param name="partPath">The part path to fetch the measurements and values for.</param>
        /// <param name="filter">A filter that can be used to further restrict the search operation.</param>
        /// <param name="streamed">
        /// This controls whether to choose a streamed transfer mode or not. Using streamed mode has the side effect, that the result is transfered
        /// using http/s when the caller enumerates the result. The caller should be aware of because then enumerating might take longer than expected.
        /// Non streamed transfer mode first reads the whole result inside the task and then returns an enumerator over the buffered result. This is
        /// the preferred way when calling the task from UI code or when enumerating the whole result. The streamed mode would be preferred when the
        /// result is processed in blocks on non UI code or when not the complete result set is used.
        /// </param>
        /// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
        public async Task <IEnumerable <DataMeasurement> > GetMeasurementValues(PathInformation partPath = null, MeasurementValueFilterAttributes filter = null, bool streamed = false, CancellationToken cancellationToken = default(CancellationToken))
        {
            var parameter = new List <ParameterDefinition>();

            if (filter != null)
            {
                parameter.AddRange(filter.ToParameterDefinition());
            }

            if (partPath != null)
            {
                parameter.Add(ParameterDefinition.Create("partPath", PathHelper.PathInformation2String(partPath)));
            }

            if (streamed)
            {
                return(await GetEnumerated <DataMeasurement>("values", cancellationToken, parameter.ToArray()).ConfigureAwait(false));
            }

            return(await Get <DataMeasurement[]>("values", cancellationToken, parameter.ToArray()).ConfigureAwait(false));
        }
		/// <summary>
		/// Fetches a list of measurements and measurement values for the <paramref name="partPath"/>. The search operation 
		/// can be parameterized using the specified <paramref name="filter"/>. If the filter is empty, all measurements for 
		/// the specified part will be fetched.
		/// </summary>
		/// <param name="partPath">The part path to fetch the measurements and values for.</param>
		/// <param name="filter">A filter that can be used to further restrict the search operation.</param>
		/// <param name="streamed">
		/// This controls whether to choose a streamed transfer mode or not. Using streamed mode has the side effect, that the result is transfered 
		/// using http/s when the caller enumerates the result. The caller should be aware of because then enumerating might take longer than expected.
		/// Non streamed transfer mode first reads the whole result inside the task and then returns an enumerator over the buffered result. This is
		/// the preferred way when calling the task from UI code or when enumerating the whole result. The streamed mode would be preferred when the 
		/// result is processed in blocks on non UI code or when not the complete result set is used.
		/// </param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public async Task<IEnumerable<DataMeasurement>> GetMeasurementValues( PathInformation partPath = null, MeasurementValueFilterAttributes filter = null, bool streamed = false, CancellationToken cancellationToken = default( CancellationToken ) )
		{
			var parameter = new List<ParameterDefinition>();
			if( filter != null )
				parameter.AddRange( filter.ToParameterDefinition() );

			if( partPath != null )
				parameter.Add( ParameterDefinition.Create( "partPath", PathHelper.PathInformation2String( partPath ) ) );

			if( streamed )
				return await GetEnumerated<DataMeasurement>( "values", cancellationToken, parameter.ToArray() ).ConfigureAwait( false );

			return await Get<DataMeasurement[]>( "values", cancellationToken, parameter.ToArray() ).ConfigureAwait( false );
		}