/// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer )
        {
            if( typeof( DataCharacteristic ) == objectType )
            {
                var characteristic = new DataCharacteristic();
                if( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                {
                    characteristic.Uuid = new Guid( (string)reader.Value );

                    var valueAttributes = new System.Collections.Generic.List<DataService.Attribute>();
                    if( reader.Read() && reader.TokenType == JsonToken.StartObject )
                    {
                        while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                        {
                            var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
                            var value = reader.ReadAsString();

                            valueAttributes.Add( new DataService.Attribute( key, value ) );
                        }
                    }
                    characteristic.Value = new DataValue( valueAttributes.ToArray() );
                }
                return characteristic;
            }
            else
            {
                var characteristics = new System.Collections.Generic.List<DataCharacteristic>();
                while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                {
                    var characteristic = new DataCharacteristic();
                    characteristic.Uuid = new Guid( (string) reader.Value );

                    var valueAttributes = new System.Collections.Generic.List<DataService.Attribute>();
                    if( reader.Read() && reader.TokenType == JsonToken.StartObject )
                    {
                        while( reader.Read() && reader.TokenType == JsonToken.PropertyName )
                        {
                            var key = ushort.Parse( reader.Value.ToString(), System.Globalization.CultureInfo.InvariantCulture );
                            var value = reader.ReadAsString();

                            valueAttributes.Add( new DataService.Attribute( key, value ) );
                        }
                    }
                    characteristic.Value = new DataValue( valueAttributes.ToArray() );
                    characteristics.Add( characteristic );
                }
                return characteristics.ToArray();
            }
        }
Esempio n. 2
0
		private ListViewItem CreateListViewItem( DataCharacteristic value )
		{
			var subItems = new[]
			{
				GetCharacteristicName( value.Uuid ),
				value.Value != null && value.Value.MeasuredValue.HasValue ? value.Value.MeasuredValue.Value.ToString( CultureInfo.CurrentCulture ) : "-"
			};

			return new ListViewItem( subItems )
			{
				Tag = value,
				ToolTipText = CreateAttributeTooltip( value.Value )
			};
		}
Esempio n. 3
0
		/// <summary>
		/// This method fetches all measurement values of the selected measurement. The number of characteristics can be restricted using the
		/// filter class. However, if all characteristics are fetched, fetching the whole measurement without a characteristic restriction
		/// is best practice and the most efficient way.
		/// </summary>
		private async Task FetchMeasurementValues( Guid measurementUuid )
		{
			_MeasurementValuesListView.Items.Clear();
			DataCharacteristic[] _Values = new DataCharacteristic[0];
			try
			{
				LogMessage( "Fetching all measurement values for measurement with uuid '{0}' from data service.", measurementUuid );

				var sw = System.Diagnostics.Stopwatch.StartNew();
				var values = ( await _RestDataServiceClient.GetMeasurementValues( filter: new MeasurementValueFilterAttributes { MeasurementUuids = new[] { measurementUuid } } ) ).ToArray();
				_Values = values != null ? values[ 0 ].Characteristics : new DataCharacteristic[ 0 ];
				sw.Stop();

				LogMessage( "Successfully fetched {1} measurement values from data service in {0} ms.\r\n", sw.ElapsedMilliseconds, _Values.Length );
			}
			catch( Exception ex )
			{
				LogMessage( "Error fetching measurement values for measurement with uuid '{0}' from data service: '{1}'.\r\n", measurementUuid, ex.Message );
			}

			_MeasurementValuesListView.BeginUpdate();
			foreach( var value in _Values.OrderBy( p => GetCharacteristicName( p.Uuid ) ) )
			{
				_MeasurementValuesListView.Items.Add( CreateListViewItem( value ) );
			}
			_MeasurementValuesListView.EndUpdate();
		}