protected async Task OnTemperatureAlertChangedEvent()
 {
     try
     {
         if (this.TemperatureRepository != null)
         {
             this.EventAggregator.GetEvent <Events.TemperatureChangedEvent>().Publish(new TemperatureChangedEventArgs()
             {
                 SensorReading = ApplicationSensorReading.FromIApplicationSensorReading(await this.TemperatureRepository.GetSensorReading())
             });
         }
     }
     catch (Exception ex)
     {
         this.EventAggregator.GetEvent <Events.DebugEvent>().Publish(new DebugEventArgs(ex));
     }
 }
Ejemplo n.º 2
0
        private async Task SendSensorReading(bool force)
        {
            try
            {
                IApplicationSensorReading sensorReading = await this.GetSensorReading();

                // ***
                // *** Add the temperature thresholds
                // ***
                sensorReading.CriticalThreshold = this.Device.CriticalTemperatureThreshold;
                sensorReading.LowerThreshold    = this.Device.LowerTemperatureThreshold;
                sensorReading.UpperThreshold    = this.Device.UpperTemperatureThreshold;

                // ***
                // *** Only send the event when the reading has changed
                // ***
                if (force ||
                    _previousReading == null ||
                    _previousReading.Temperature != sensorReading.Temperature ||
                    _previousReading.IsCritical != sensorReading.IsCritical ||
                    _previousReading.IsAboveUpperThreshold != sensorReading.IsAboveUpperThreshold ||
                    _previousReading.IsBelowLowerThreshold != sensorReading.IsBelowLowerThreshold ||
                    _previousReading.CriticalThreshold != sensorReading.CriticalThreshold ||
                    _previousReading.LowerThreshold != sensorReading.LowerThreshold ||
                    _previousReading.UpperThreshold != sensorReading.UpperThreshold)
                {
                    this.EventAggregator.GetEvent <Events.TemperatureChangedEvent>().Publish(new TemperatureChangedEventArgs()
                    {
                        SensorReading = ApplicationSensorReading.FromIApplicationSensorReading(sensorReading)
                    });
                    _previousReading = sensorReading;
                }
            }
            catch (Exception ex)
            {
                this.EventAggregator.GetEvent <Events.DebugEvent>().Publish(new DebugEventArgs(ex));
            }
        }