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 if (e.SensorReading.Source == ApplicationSensorReadingSource.Cloud)
                {
                    this.DeviceName          = "Cloud";
                    this.ShowTelemetryStatus = false;
                }
                else
                {
                    this.DeviceName          = "Not Detected";
                    this.ShowTelemetryStatus = false;
                }
            }
            catch (Exception ex)
            {
                this.EventAggregator.GetEvent <Events.DebugEvent>().Publish(new DebugEventArgs(ex));
            }

            await Task.FromResult(0);
        }
Exemplo n.º 2
0
    public void raise_TemperatureChanged(TemperatureChangedEventArgs eventArgs)
    {
        if (TemperatureChanged == null)
        {
            return;
        }

        foreach (TemperatureChanged d in TemperatureChanged.GetInvocationList())
        {
            if (d.Method.Name.Contains("Duplicate"))
            {
                Console.WriteLine("Duplicate event handler; event handler not executed.");
            }
            else
            {
                d.Invoke(this, eventArgs);
            }
        }
    }
Exemplo n.º 3
0
 /// <summary>
 /// Temperature change event handler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void HandleTemperatureChanged(object sender, TemperatureChangedEventArgs e)
 {
     Check(e.Temperature.Value);
 }
        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
                    };

                    var messageString = JsonConvert.SerializeObject(sensorReading);
                    var message       = new Message(Encoding.UTF8.GetBytes(messageString));

                    try
                    {
                        // ***
                        // *** Send the event.
                        // ***
                        await _deviceClient.SendEventAsync(message);

                        // ***
                        // *** Increment the counter
                        // ***
                        _totalSent++;
                    }
                    catch
                    {
                        // ***
                        // *** 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
                });
            }
        }
Exemplo n.º 5
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.º 6
0
 public void DuplicateTemperatureNotification(Object sender, TemperatureChangedEventArgs e)
 {
     Console.WriteLine("Notification 2: The temperature changed from {0} to {1}", e.OldTemperature, e.CurrentTemperature);
 }
Exemplo n.º 7
0
 //温度改变
 private void mFloorSet_temperatureChanged(object sender, TemperatureChangedEventArgs e)
 {
     //   SendMessageToAllClient("Coffer " + e.ChangedRoom.ToString() + " " + e.ChangedRoom.IsCofferOpen);
     SendMessageToAllClient("temperatureChanged " + e.ChangedRoom.ToString() + " " + e.ChangedRoom.Temperature.ToString());
 }