/// <summary>
        /// Fetches a list of measurements 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 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 <SimpleMeasurement> > GetMeasurements(PathInformation partPath = null, MeasurementFilterAttributes 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 <SimpleMeasurement>("measurements", cancellationToken, parameter.ToArray()).ConfigureAwait(false));
            }

            return(await Get <SimpleMeasurement[]>("measurements", cancellationToken, parameter.ToArray()).ConfigureAwait(false));
        }
Пример #2
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 (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.ConvertUInt16ListToString(RequestedValueAttributes.Attributes)));
            }

            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, 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)));
            }

            return(result.ToArray());
        }
Пример #3
0
        /// <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 measurementUuids, string deep, string limitResult, string order, string requestedMeasurementAttributes, string searchCondition, string statistics, string aggregation, string fromModificationDate, string toModificationDate)
        {
            var items = new[]
            {
                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)
            };

            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 DeepParamName:
                        result.Deep = bool.Parse(value);
                        break;

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

                    case LimitResultParamName:
                        result.LimitResult = short.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;
                    }
                }
                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" +
                                                                      "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" +
                                                                      "fromModificationDate:[Date]\r\n" +
                                                                      "toModificationDate:[Date]"), ex);
                }
            }
            return(result);
        }
Пример #4
0
		/// <summary>
		/// Fetches a list of measurements 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 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<SimpleMeasurement>> GetMeasurements( PathInformation partPath = null, MeasurementFilterAttributes 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<SimpleMeasurement>( "measurements", cancellationToken, parameter.ToArray() ).ConfigureAwait( false );

			return await Get<SimpleMeasurement[]>( "measurements", cancellationToken, parameter.ToArray() ).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 measurementUuids, string deep, string limitResult, string order, string requestedMeasurementAttributes, string searchCondition, string statistics, string aggregation, string fromModificationDate, string toModificationDate )
        {
            var items = new[]
            {
                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 )
            };

            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 DeepParamName:
                            result.Deep = bool.Parse( value );
                            break;
                        case MeasurementUuidsParamName:
                            result.MeasurementUuids = RestClientHelper.ConvertStringToGuidList( value );
                            break;
                        case LimitResultParamName:
                            result.LimitResult = short.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;
                    }
                }
                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" +
                        "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" +
                        "fromModificationDate:[Date]\r\n" +
                        "toModificationDate:[Date]" ), ex );
                }
            }
            return result;
        }