Пример #1
0
        public async Task ExposureDetectedAsync(ExposureConfiguration exposureConfiguration, long enVersion, IList <DailySummary> dailySummaries, IList <ExposureWindow> exposureWindows)
        {
            _loggerService.Debug("ExposureDetected: ExposureWindows");

            var(newDailySummaries, newExposureWindows) = await _exposureDataRepository.SetExposureDataAsync(
                dailySummaries.ToList(),
                exposureWindows.ToList()
                );

            var exposureRiskCalculationConfiguration = await _exposureRiskCalculationConfigurationRepository
                                                       .GetExposureRiskCalculationConfigurationAsync(preferCache : false);

            _loggerService.Info(exposureRiskCalculationConfiguration.ToString());

            long expectOldestDateMillisSinceEpoch
                = _dateTimeUtility.UtcNow
                  .AddDays(AppConstants.TermOfExposureRecordValidityInDays)
                  .ToUnixEpochMillis();

            bool isHighRiskExposureDetected = newDailySummaries
                                              .Where(ds => ds.DateMillisSinceEpoch >= expectOldestDateMillisSinceEpoch)
                                              .Select(ds => _exposureRiskCalculationService.CalcRiskLevel(
                                                          ds,
                                                          newExposureWindows.Where(ew => ew.DateMillisSinceEpoch == ds.DateMillisSinceEpoch).ToList(),
                                                          exposureRiskCalculationConfiguration
                                                          )
                                                      )
                                              .Any(riskLevel => riskLevel >= RiskLevel.High);

            if (isHighRiskExposureDetected)
            {
                _ = _localNotificationService.ShowExposureNotificationAsync();

                bool enableSendEventExposureNotificationNotified = _sendEventLogStateRepository
                                                                   .GetSendEventLogState(EventType.ExposureNotified) == SendEventLogState.Enable;

                if (enableSendEventExposureNotificationNotified)
                {
                    await _eventLogRepository.AddEventNotifiedAsync();
                }
            }
            else
            {
                _loggerService.Info($"DailySummary: {dailySummaries.Count}, but no high-risk exposure detected");
            }
        }
Пример #2
0
        public async Task ExposureDetectedAsync(ExposureConfiguration exposureConfiguration, long enVersion, IList <DailySummary> dailySummaries, IList <ExposureWindow> exposureWindows)
        {
            _loggerService.Debug("ExposureDetected: ExposureWindows");

            var enVersionStr = enVersion.ToString();

            var(newDailySummaries, newExposureWindows) = await _exposureDataRepository.SetExposureDataAsync(
                dailySummaries.ToList(),
                exposureWindows.ToList()
                );

            var exposureRiskCalculationConfiguration = await _exposureRiskCalculationConfigurationRepository
                                                       .GetExposureRiskCalculationConfigurationAsync(preferCache : false);

            _loggerService.Info(exposureRiskCalculationConfiguration.ToString());

            long expectOldestDateMillisSinceEpoch
                = _dateTimeUtility.UtcNow
                  .AddDays(AppConstants.TermOfExposureRecordValidityInDays)
                  .ToUnixEpochMillis();

            bool isHighRiskExposureDetected = newDailySummaries
                                              .Where(ds => ds.DateMillisSinceEpoch >= expectOldestDateMillisSinceEpoch)
                                              .Select(ds => _exposureRiskCalculationService.CalcRiskLevel(
                                                          ds,
                                                          newExposureWindows.Where(ew => ew.DateMillisSinceEpoch == ds.DateMillisSinceEpoch).ToList(),
                                                          exposureRiskCalculationConfiguration
                                                          )
                                                      )
                                              .Any(riskLevel => riskLevel >= RiskLevel.High);

            if (isHighRiskExposureDetected)
            {
                _ = _localNotificationService.ShowExposureNotificationAsync();
            }
            else
            {
                _loggerService.Info($"DailySummary: {dailySummaries.Count}, but no high-risk exposure detected");
            }

            try
            {
                await _exposureDataCollectServer.UploadExposureDataAsync(
                    exposureConfiguration,
                    _deviceInfoUtility.Model,
                    enVersionStr,
                    newDailySummaries, newExposureWindows
                    );
            }
            catch (Exception e)
            {
                _loggerService.Exception("UploadExposureDataAsync", e);
            }

            string idempotencyKey = Guid.NewGuid().ToString();

            try
            {
                await _eventLogService.SendExposureDataAsync(
                    idempotencyKey,
                    exposureConfiguration,
                    _deviceInfoUtility.Model,
                    enVersionStr,
                    newDailySummaries, newExposureWindows
                    );
            }
            catch (Exception e)
            {
                _loggerService.Exception("SendExposureDataAsync", e);
            }
        }