// this will be called when a potential exposure has been detected public async Task ExposureDetectedAsync(ExposureDetectionSummary summary, Func <Task <IEnumerable <ExposureInfo> > > getExposureInfo) { UserExposureSummary userExposureSummary = new UserExposureSummary(summary.DaysSinceLastExposure, summary.MatchedKeyCount, summary.HighestRiskScore, summary.AttenuationDurations, summary.SummationRiskScore); userData.ExposureSummary = userExposureSummary; var exposureInfo = await getExposureInfo(); // Add these on main thread in case the UI is visible so it can update await Device.InvokeOnMainThreadAsync(() => { foreach (var exposure in exposureInfo) { Console.WriteLine($"COCOA found exposure {exposure.Timestamp}"); UserExposureInfo userExposureInfo = new UserExposureInfo(exposure.Timestamp, exposure.Duration, exposure.AttenuationValue, exposure.TotalRiskScore, (Covid19Radar.Model.UserRiskLevel)exposure.TransmissionRiskLevel); userData.ExposureInformation.Add(userExposureInfo); } }); await userDataService.SetAsync(userData); // If Enabled Local Notifications //if (userData.IsNotificationEnabled) //{ // var notification = new NotificationRequest // { // NotificationId = 100, // Title = AppResources.LocalNotificationTitle, // Description = AppResources.LocalNotificationDescription // }; // NotificationCenter.Current.Show(notification); //} }
// this will be called when a potential exposure has been detected public async Task ExposureDetectedAsync(ExposureDetectionSummary summary, Func <Task <IEnumerable <ExposureInfo> > > getExposureInfo) { loggerService.StartMethod(); UserExposureSummary userExposureSummary = new UserExposureSummary(summary.DaysSinceLastExposure, summary.MatchedKeyCount, summary.HighestRiskScore, summary.AttenuationDurations, summary.SummationRiskScore); userData.ExposureSummary = userExposureSummary; loggerService.Info($"ExposureSummary.MatchedKeyCount: {userExposureSummary.MatchedKeyCount}"); loggerService.Info($"ExposureSummary.DaysSinceLastExposure: {userExposureSummary.DaysSinceLastExposure}"); loggerService.Info($"ExposureSummary.HighestRiskScore: {userExposureSummary.HighestRiskScore}"); loggerService.Info($"ExposureSummary.AttenuationDurations: {string.Join(",", userExposureSummary.AttenuationDurations)}"); loggerService.Info($"ExposureSummary.SummationRiskScore: {userExposureSummary.SummationRiskScore}"); var config = await GetConfigurationAsync(); if (userData.ExposureSummary.HighestRiskScore >= config.MinimumRiskScore) { var exposureInfo = await getExposureInfo(); loggerService.Info($"ExposureInfo: {exposureInfo.Count()}"); // Add these on main thread in case the UI is visible so it can update await Device.InvokeOnMainThreadAsync(() => { foreach (var exposure in exposureInfo) { loggerService.Info($"Exposure.Timestamp: {exposure.Timestamp}"); loggerService.Info($"Exposure.Duration: {exposure.Duration}"); loggerService.Info($"Exposure.AttenuationValue: {exposure.AttenuationValue}"); loggerService.Info($"Exposure.TotalRiskScore: {exposure.TotalRiskScore}"); loggerService.Info($"Exposure.TransmissionRiskLevel: {exposure.TransmissionRiskLevel}"); UserExposureInfo userExposureInfo = new UserExposureInfo(exposure.Timestamp, exposure.Duration, exposure.AttenuationValue, exposure.TotalRiskScore, (Covid19Radar.Model.UserRiskLevel)exposure.TransmissionRiskLevel); userData.ExposureInformation.Add(userExposureInfo); } }); } loggerService.Info($"Save ExposureSummary. MatchedKeyCount: {userData.ExposureSummary.MatchedKeyCount}"); loggerService.Info($"Save ExposureInformation. Count: {userData.ExposureInformation.Count}"); await userDataService.SetAsync(userData); // If Enabled Local Notifications //if (userData.IsNotificationEnabled) //{ // var notification = new NotificationRequest // { // NotificationId = 100, // Title = AppResources.LocalNotificationTitle, // Description = AppResources.LocalNotificationDescription // }; // NotificationCenter.Current.Show(notification); //} loggerService.EndMethod(); }
// this will be called when a potential exposure has been detected public async Task ExposureDetectedAsync(ExposureDetectionSummary summary, Func <Task <IEnumerable <ExposureInfo> > > getExposureInfo) { var loggerService = LoggerService; loggerService.StartMethod(); var exposureNotificationService = ExposureNotificationService; var exposureInformationList = exposureNotificationService.GetExposureInformationList() ?? new List <UserExposureInfo>(); UserExposureSummary userExposureSummary = new UserExposureSummary(summary.DaysSinceLastExposure, summary.MatchedKeyCount, summary.HighestRiskScore, summary.AttenuationDurations, summary.SummationRiskScore); loggerService.Info($"ExposureSummary.MatchedKeyCount: {userExposureSummary.MatchedKeyCount}"); loggerService.Info($"ExposureSummary.DaysSinceLastExposure: {userExposureSummary.DaysSinceLastExposure}"); loggerService.Info($"ExposureSummary.HighestRiskScore: {userExposureSummary.HighestRiskScore}"); loggerService.Info($"ExposureSummary.AttenuationDurations: {string.Join(",", userExposureSummary.AttenuationDurations)}"); loggerService.Info($"ExposureSummary.SummationRiskScore: {userExposureSummary.SummationRiskScore}"); var config = await GetConfigurationAsync(); if (userExposureSummary.HighestRiskScore >= config.MinimumRiskScore) { var exposureInfo = await getExposureInfo(); loggerService.Info($"ExposureInfo: {exposureInfo.Count()}"); // Add these on main thread in case the UI is visible so it can update await Device.InvokeOnMainThreadAsync(() => { foreach (var exposure in exposureInfo) { loggerService.Info($"Exposure.Timestamp: {exposure.Timestamp}"); loggerService.Info($"Exposure.Duration: {exposure.Duration}"); loggerService.Info($"Exposure.AttenuationValue: {exposure.AttenuationValue}"); loggerService.Info($"Exposure.TotalRiskScore: {exposure.TotalRiskScore}"); loggerService.Info($"Exposure.TransmissionRiskLevel: {exposure.TransmissionRiskLevel}"); if (exposure.TotalRiskScore >= config.MinimumRiskScore) { UserExposureInfo userExposureInfo = new UserExposureInfo(exposure.Timestamp, exposure.Duration, exposure.AttenuationValue, exposure.TotalRiskScore, (Covid19Radar.Model.UserRiskLevel)exposure.TransmissionRiskLevel); exposureInformationList.Add(userExposureInfo); } } }); } exposureInformationList.Sort((a, b) => a.Timestamp.CompareTo(b.Timestamp)); loggerService.Info($"Save ExposureSummary. MatchedKeyCount: {userExposureSummary.MatchedKeyCount}"); loggerService.Info($"Save ExposureInformation. Count: {exposureInformationList.Count}"); exposureNotificationService.SetExposureInformation(userExposureSummary, exposureInformationList); loggerService.EndMethod(); }
public void JsonSerializeTests() { var testTimestamp = new DateTime(2020, 12, 21, 9, 3, 30); var testDuration = new TimeSpan(1, 2, 3, 4, 5); var testAttenuationValue = 1; var testTotalRiskScore = 20; var testRiskLevel = UserRiskLevel.Medium; var testExposureInfo = new UserExposureInfo(testTimestamp, testDuration, testAttenuationValue, testTotalRiskScore, testRiskLevel); var serializedJson = JsonConvert.SerializeObject(testExposureInfo); Assert.NotEmpty(serializedJson); Assert.Contains("\"Timestamp\":\"2020-12-21T09:03:30\"", serializedJson); Assert.Contains("\"Duration\":\"1.02:03:04.0050000\"", serializedJson); Assert.Contains($"\"AttenuationValue\":{testAttenuationValue}", serializedJson); Assert.Contains($"\"TotalRiskScore\":{testTotalRiskScore}", serializedJson); Assert.Contains($"\"TransmissionRiskLevel\":{(int)testRiskLevel}", serializedJson); }
// this will be called when a potential exposure has been detected public async Task ExposureDetectedAsync(ExposureDetectionSummary summary, Func <Task <IEnumerable <ExposureInfo> > > getExposureInfo) { var loggerService = LoggerService; loggerService.StartMethod(); var exposureNotificationService = ExposureNotificationService; var exposureInformationList = exposureNotificationService.GetExposureInformationList() ?? new List <UserExposureInfo>(); UserExposureSummary userExposureSummary = new UserExposureSummary(summary.DaysSinceLastExposure, summary.MatchedKeyCount, summary.HighestRiskScore, summary.AttenuationDurations, summary.SummationRiskScore); loggerService.Info($"ExposureSummary.MatchedKeyCount: {userExposureSummary.MatchedKeyCount}"); loggerService.Info($"ExposureSummary.DaysSinceLastExposure: {userExposureSummary.DaysSinceLastExposure}"); loggerService.Info($"ExposureSummary.HighestRiskScore: {userExposureSummary.HighestRiskScore}"); loggerService.Info($"ExposureSummary.AttenuationDurations: {string.Join(",", userExposureSummary.AttenuationDurations)}"); loggerService.Info($"ExposureSummary.SummationRiskScore: {userExposureSummary.SummationRiskScore}"); var config = await GetConfigurationAsync(); var isNewExposureDetected = false; if (userExposureSummary.HighestRiskScore >= config.MinimumRiskScore) { var exposureInfo = await getExposureInfo(); loggerService.Info($"ExposureInfo: {exposureInfo.Count()}"); foreach (var exposure in exposureInfo) { loggerService.Info($"Exposure.Timestamp: {exposure.Timestamp}"); loggerService.Info($"Exposure.Duration: {exposure.Duration}"); loggerService.Info($"Exposure.AttenuationValue: {exposure.AttenuationValue}"); loggerService.Info($"Exposure.TotalRiskScore: {exposure.TotalRiskScore}"); loggerService.Info($"Exposure.TransmissionRiskLevel: {exposure.TransmissionRiskLevel}"); if (exposure.TotalRiskScore >= config.MinimumRiskScore) { UserExposureInfo userExposureInfo = new UserExposureInfo(exposure.Timestamp, exposure.Duration, exposure.AttenuationValue, exposure.TotalRiskScore, (Covid19Radar.Model.UserRiskLevel)exposure.TransmissionRiskLevel); exposureInformationList.Add(userExposureInfo); isNewExposureDetected = true; } } } if (isNewExposureDetected) { loggerService.Info($"Save ExposureSummary. MatchedKeyCount: {userExposureSummary.MatchedKeyCount}"); loggerService.Info($"Save ExposureInformation. Count: {exposureInformationList.Count}"); exposureInformationList.Sort((a, b) => a.Timestamp.CompareTo(b.Timestamp)); exposureNotificationService.SetExposureInformation(userExposureSummary, exposureInformationList); await LocalNotificationService.ShowExposureNotificationAsync(); } else { loggerService.Info($"MatchedKeyCount: {userExposureSummary.MatchedKeyCount}, but no new exposure detected"); } loggerService.EndMethod(); }