public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages) { foreach (var eventData in messages) { // get the alarm from event hub var stream = eventData.GetBodyStream(); var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); var json = bytes.Aggregate(string.Empty, (current, t) => current + ((char)t).ToString()); BiometricReading alarm = null; try { alarm = ModelManager.JsonToModel <BiometricReading>(json); } catch (Exception) { continue; } // log the alarm to biometrics database using the API //Rest.Post(new Uri(_biometricsApi), json); // lookup the user that rasied the alarm var user = _profile.GetById(alarm.participantid); //format the toast message var biometric = string.Empty; switch (alarm.type) { case BiometricType.Glucose: biometric = "Glucose"; break; case BiometricType.Heartrate: biometric = "Heartrate"; break; case BiometricType.Temperature: biometric = "Tempurature"; break; case BiometricType.Bloodoxygen: biometric = "Blood Oxygen"; break; case BiometricType.NotSet: break; default: biometric = "Not Set"; break; } var toast = "<toast><visual><binding template = 'ToastText04'> " + $"<text id = '1'>{"BioMax Alert"}</text>" + $"<text id = '2'>{"The " + biometric + " reading for " + user.firstname + " " + user.lastname + " is out of range."}</text>" + $"<text id = '3' >{"Contact: " + user.social.phone}</text>" + "</binding ></visual></toast>"; _hub.SendWindowsNativeNotificationAsync(toast).Wait(); } await context.CheckpointAsync(); }
public UserProfile GetById(string id) { return(_profileM.GetById(id)); }