Exemplo n.º 1
0
		/// <summary>
		/// This method creates a new measurement including two attributes: inspector and time. The inspector is set to a random inspector taken 
		/// from the particular catalog, time is set to the current time. Please note that datetime values need to be 
		/// Xml converted in order to be handled correctly. Measurement's time can also be set via the <see cref="DataMeasurement.Time"/> property. 
		/// As it internally sets the particular attribute be patient: Setting the <see cref="DataMeasurement.Time"/> property before setting the 
		/// <see cref="SimpleMeasurement.Attributes"/> property will cause the <see cref="DataMeasurement.Time"/> property to be overwritten/deleted.
		/// </summary>
		private async void CreateMeasurementsButton_Click( object sender, EventArgs e )
		{
			double val1, val2, val3;
			
			if( !Double.TryParse( _Value1TextBox.Text, out val1 ) || !Double.TryParse( _Value2TextBox.Text, out val2 ) ||
				!Double.TryParse( _Value3TextBox.Text, out val3 ) || _CurrentPart == null|| _CurrentCharacteristics == null || _CurrentCharacteristics.Length != 3 )
			{
				LogMessage( "Creating measurement failed due to badly formatted values!\r\n" );
				return;
			}

			try
			{
				LogMessage( "Creating a measurement and three values" );

				var sw = System.Diagnostics.Stopwatch.StartNew();

				var attributes = new List<DataService.Attribute>();
				attributes.Add( new DataService.Attribute( WellKnownKeys.Measurement.Time, XmlConvert.ToString( DateTime.Now, XmlDateTimeSerializationMode.RoundtripKind ) ) );
				
				var inspectorDef = _Configuration.GetDefinition( Entity.Measurement, WellKnownKeys.Measurement.InspectorName ) as CatalogAttributeDefinition;
				var rdm = new Random();
				if( inspectorDef != null )
				{
					var catalogEntry = _Catalogs[ inspectorDef.Catalog, rdm.Next( 0, _Catalogs[ inspectorDef.Catalog ].CatalogEntries.Length ).ToString() ];
					attributes.Add( new DataService.Attribute( WellKnownKeys.Measurement.InspectorName, catalogEntry.Key ) );
				}

				var measurement = new DataMeasurement
				{
					Uuid = Guid.NewGuid(),
					Attributes = attributes.ToArray(),
					Characteristics = new[]
					{
						new DataCharacteristic
						{
							Uuid = _CurrentCharacteristics[0].Uuid, 
							Timestamp = DateTime.Now, 
							Value = new DataValue( val1 )
						},
						new DataCharacteristic
						{
							Uuid = _CurrentCharacteristics[1].Uuid, 
							Timestamp = DateTime.Now, 
							Value = new DataValue( val2 )
						},
						new DataCharacteristic
						{
							Uuid = _CurrentCharacteristics[2].Uuid, 
							Timestamp = DateTime.Now, 
							Value = new DataValue( val3 )
						}
					},
					PartUuid = _CurrentPart.Uuid
				};
				await _RestDataServiceClient.CreateMeasurementValues( new[] { measurement } );

				sw.Stop();
				LogMessage( "Successfully create a measurmeent and three values in {0} ms.\r\n", sw.ElapsedMilliseconds );
			}
			catch( Exception ex )
			{
				LogMessage( String.Format( "Error creating measurement: '{0}'.\r\n", ex.Message ) );
			}
		}
Exemplo n.º 2
0
		/// <summary>
		/// Updates the measurements and measurement values parts to the database. Please note that no single values can be inserted or updated. Whole
		/// measurements with all values can be created or updated only.
		/// </summary>
		/// <param name="values">The measurements and values to update.</param>
		/// <param name="cancellationToken">A token to cancel the asynchronous operation.</param>
		public Task UpdateMeasurementValues( DataMeasurement[] values, CancellationToken cancellationToken = default(CancellationToken) )
		{
			return Put( "values", values, cancellationToken );
		}