Пример #1
0
        private async Task CheckAlertAsync(DecodedMessage message)
        {
            if (cacheDatabase == null)
                return;
            string json = await cacheDatabase.StringGetAsync("message-" + message.Device);
            if (json == null)
                return;
            DecodedMessage cached = null;
            try
            {
                cached = JsonConvert.DeserializeObject<DecodedMessage>(json);
            }
            catch
            {

            }
            if (cached == null)
                return;
            if ((message.Type == FrameType.Alert) || (message.Mode == Mode.Button) || (Math.Abs(message.Temperature - cached.Temperature) > 10))
            {
                var alert = new AlertMessage();
                alert.Device = message.Device;
                var alertMessage = JsonConvert.SerializeObject(alert);
                await hubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(alertMessage)));
            }
        }
Пример #2
0
 private async Task SendEmailAsync(AlertMessage message)
 {
     if (message == null)
         return;
     if (string.IsNullOrEmpty(message.Device))
         return;
     var email = new SendGridMessage();
     email.From = new MailAddress("*****@*****.**", "Alex Danvy (Sigfox Demo)");
     List<String> recipients = new List<String>
     {
         @"Alex Danvy <*****@*****.**>"
     };
     email.AddTo(recipients);
     email.Subject = "Sigfox Demo Alert";
     email.Html = string.Format("<p><b>Sigfox Demo Alert!</b></p><p>The device '{0}' raised an alert.</p>", message.Device);
     email.Text = string.Format("Sigfox Demo Alert\nThe device '{0}' raised an alert.", message.Device);
     await transportWeb.DeliverAsync(email);
 }