private async void OnTemperatureChangedEvent(TemperatureChangedEventArgs e)
		{
			try
			{
				this.SensorReading = e.SensorReading;
				this.ResetAlertCommand.RaiseCanExecuteChanged();

				if (e.SensorReading.Source == ApplicationSensorReadingSource.Device)
				{
					this.DeviceName = "MCP9808";
					this.ShowTelemetryStatus = true;
				}
				else
				{
					this.DeviceName = "Cloud";
					this.ShowTelemetryStatus = false;
				}
			}
			catch (Exception ex)
			{
				this.EventAggregator.GetEvent<Events.DebugEvent>().Publish(new DebugEventArgs(ex));
			}

			await Task.FromResult(0);
		}
Exemplo n.º 2
0
		/// <summary>
		/// Sends a sensor reading to all connected clients.
		/// </summary>
		/// <param name="e">The temperature changed event arguments.</param>
		public void SendTemperatureChangedEvent(TemperatureChangedEventArgs e)
		{
			this.Clients.All.OnTemperatureChangedEvent(e);
		}
Exemplo n.º 3
0
		private async void OnTemperatureChangedEvent(TemperatureChangedEventArgs e)
		{
			try
			{
				// ***
				// *** Send the start event
				// ***
				this.EventAggregator.GetEvent<Events.TelemetryStatusChangedEvent>().Publish(new TelemetryStatusChangedEventArgs()
				{
					Status = TelemetryChangedStatus.Sending,
					TotalSent = _totalSent,
					TotalFailed = _totalFailed
				});

				// ***
				// *** Only send telemetry events when the source is Device
				// ***
				if (e.SensorReading.Source == ApplicationSensorReadingSource.Device)
				{
					SensorReading sensorReading = new SensorReading()
					{
						Source = 1,
						TimestampUtc = e.SensorReading.TimestampUtc,
						Temperature = e.SensorReading.Temperature,
						IsCritical = e.SensorReading.IsCritical ? 1 : 0,
						IsAboveUpperThreshold = e.SensorReading.IsAboveUpperThreshold ? 1 : 0,
						IsBelowLowerThreshold = e.SensorReading.IsBelowLowerThreshold ? 1 : 0
					};

					if (await AzureServiceBusHub.SendData(this.HubConfiguration, sensorReading))
					{
						// ***
						// *** Increment the counter
						// ***
						_totalSent++;
					}
					else
					{
						// ***
						// *** Increment the failed counter
						// ***
						_totalFailed++;
					}
				}
			}
			catch (Exception ex)
			{
				// ***
				// *** Increment the failed counter
				// ***
				_totalFailed++;

				this.EventAggregator.GetEvent<Events.DebugEvent>().Publish(new DebugEventArgs(ex));
			}
			finally
			{
				// ***
				// *** Send the completed event
				// ***
				this.EventAggregator.GetEvent<Events.TelemetryStatusChangedEvent>().Publish(new TelemetryStatusChangedEventArgs()
				{
					Status = TelemetryChangedStatus.Completed,
					TotalSent = _totalSent,
					TotalFailed = _totalFailed
				});
			}
		}