public override async void Initialize(INavigationParameters parameters)
        {
            base.Initialize(parameters);

            _loggerService.StartMethod();

            _exposureRiskCalculationConfiguration
                = parameters.GetValue <V1ExposureRiskCalculationConfiguration>(ExposureCheckPage.ExposureRiskCalculationConfigurationKey);

            if (_exposureRiskCalculationConfiguration is null)
            {
                _exposureRiskCalculationConfiguration
                    = await _exposureRiskCalculationConfigurationRepository.GetExposureRiskCalculationConfigurationAsync(preferCache : true);
            }

            _loggerService.Info(_exposureRiskCalculationConfiguration.ToString());

            ShowExposureRiskCalculationConfiguration();

            try
            {
                // 一時的に閾値未満の内容は表示しないようにするためコメントアウト
                //_ = Setup();
            }
            catch (Exception exception)
            {
                _loggerService.Exception("Exception occurred", exception);
            }
            finally
            {
                _loggerService.EndMethod();
            }
        }
Esempio n. 2
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");
            }
        }
Esempio n. 3
0
        public override async void Initialize(INavigationParameters parameters)
        {
            base.Initialize(parameters);

            loggerService.StartMethod();

            // It seems the life cycle methods are not called after background fetch in iOS.
            // The days of use will be updated at this time.
            MessagingCenter.Unsubscribe <object>(this, AppConstants.IosOnActivatedMessage);
            MessagingCenter.Subscribe <object>(this, AppConstants.IosOnActivatedMessage, async(sender) =>
            {
                await UpdateView();
            });

            // Check Version
            _ = Task.Run(async() => {
                bool isUpdated = await checkVersionService.IsUpdateVersionExistAsync();
                if (isUpdated)
                {
                    MainThread.BeginInvokeOnMainThread(async() =>
                    {
                        await UserDialogs.Instance.AlertAsync(
                            AppResources.AppUtilsGetNewVersionDescription,
                            AppResources.AppUtilsGetNewVersionTitle,
                            AppResources.ButtonOk
                            );
                        await Browser.OpenAsync(essentialsService.StoreUrl, BrowserLaunchMode.External);
                    });
                }
            });

            // Load necessary files asynchronous
            _ = exposureConfigurationRepository.GetExposureConfigurationAsync();
            _ = exposureRiskCalculationConfigurationRepository
                .GetExposureRiskCalculationConfigurationAsync(preferCache: false);

            await localNotificationService.PrepareAsync();

            await StartExposureNotificationAsync();

            ExposureDetectionAsync();

            loggerService.EndMethod();
        }
Esempio n. 4
0
        public override async void Initialize(INavigationParameters parameters)
        {
            base.Initialize(parameters);

            loggerService.StartMethod();

            // It seems the life cycle methods are not called after background fetch in iOS.
            // The days of use will be updated at this time.
            MessagingCenter.Unsubscribe <object>(this, AppConstants.IosOnActivatedMessage);
            MessagingCenter.Subscribe <object>(this, AppConstants.IosOnActivatedMessage, async(sender) =>
            {
                await UpdateView();
            });

            // Check Version
            AppUtils.CheckVersion(loggerService);

            // Load necessary files asynchronous
            _ = exposureConfigurationRepository.GetExposureConfigurationAsync();
            _ = exposureRiskCalculationConfigurationRepository
                .GetExposureRiskCalculationConfigurationAsync(preferCache: false);

            await localNotificationService.PrepareAsync();

            await StartExposureNotificationAsync();

            _ = Task.Run(async() => {
                try
                {
                    await exposureDetectionBackgroundService.ExposureDetectionAsync();
                }
                finally
                {
                    await UpdateView();
                }
            });

            loggerService.EndMethod();
        }
Esempio n. 5
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);
            }
        }
        public override async void Initialize(INavigationParameters parameters)
        {
            base.Initialize(parameters);

            try
            {
                loggerService.StartMethod();

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

                loggerService.Info(exposureRiskCalculationConfiguration.ToString());

                var userExposureInformationList = _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

                string contactedNotifyPageCountFormat = AppResources.ContactedNotifyPageCountOneText;
                if (userExposureInformationList.Count() > 1)
                {
                    contactedNotifyPageCountFormat = AppResources.ContactedNotifyPageCountText;
                }

                var dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);

                var dailySummaryMap    = dailySummaryList.ToDictionary(ds => ds.GetDateTime());
                var exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);

                int  dayCount = 0;
                long exposureDurationInSec = 0;
                foreach (var ew in exposureWindowList.GroupBy(exposureWindow => exposureWindow.GetDateTime()))
                {
                    if (!dailySummaryMap.ContainsKey(ew.Key))
                    {
                        loggerService.Warning($"ExposureWindow: {ew.Key} found, but that is not contained the list of dailySummary.");
                        continue;
                    }

                    var dailySummary = dailySummaryMap[ew.Key];

                    RiskLevel riskLevel = _exposureRiskCalculationService.CalcRiskLevel(dailySummary, ew.ToList(), exposureRiskCalculationConfiguration);
                    if (riskLevel >= RiskLevel.High)
                    {
                        exposureDurationInSec += ew.Sum(e => e.ScanInstances.Sum(s => s.SecondsSinceLastScan));
                        dayCount += 1;
                    }
                }

                string contactedNotifyPageExposureDurationFormat = AppResources.ContactedNotifyPageExposureDurationOne;
                if (dayCount > 1)
                {
                    contactedNotifyPageExposureDurationFormat = AppResources.ContactedNotifyPageExposureDuration;
                }
                TimeSpan timeSpan     = TimeSpan.FromSeconds(exposureDurationInSec);
                var      totalMinutes = Math.Ceiling(timeSpan.TotalMinutes);

                if (userExposureInformationList.Count() > 0 && dayCount > 0)
                {
                    // Show Headers
                    var beforeDateMillisSinceEpoch = userExposureInformationList.Max(ei => ei.Timestamp.ToUnixEpochMillis());
                    var afterDateMillisSinceEpoch  = dailySummaryList.Min(ds => ds.DateMillisSinceEpoch);

                    var beforeDate = DateTimeOffset.UnixEpoch.AddMilliseconds(beforeDateMillisSinceEpoch).UtcDateTime;
                    var afterDate  = DateTimeOffset.UnixEpoch.AddMilliseconds(afterDateMillisSinceEpoch).UtcDateTime;

                    ExposureCount = string.Format(AppResources.ContactedNotifyPageCountHeader, beforeDate.ToString("D")) + "\n"
                                    + string.Format(contactedNotifyPageCountFormat, userExposureInformationList.Count());
                    ExposureDurationInMinutes = string.Format(AppResources.ContactedNotifyPageExposureDurationHeader, afterDate.ToString("D")) + "\n"
                                                + string.Format(contactedNotifyPageExposureDurationFormat, dayCount, totalMinutes);
                }
                else if (exposureDurationInSec > 0)
                {
                    ExposureDurationInMinutes = string.Format(contactedNotifyPageExposureDurationFormat, dayCount, totalMinutes);
                }
                else if (userExposureInformationList.Count() > 0)
                {
                    ExposureCount = string.Format(contactedNotifyPageCountFormat, userExposureInformationList.Count());
                }
            }
            catch (Exception exception)
            {
                loggerService.Exception("Failed to Initialize", exception);
            }
            finally
            {
                loggerService.EndMethod();
            }
        }
Esempio n. 7
0
        public async Task InitExposures()
        {
            var exposures = new ObservableCollection <ExposureSummary>();

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

            _loggerService.Info(exposureRiskCalculationConfiguration.ToString());

            var dailySummaryList
                = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);

            var dailySummaryMap = dailySummaryList.ToDictionary(ds => ds.GetDateTime());

            var exposureWindowList
                = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);

            var userExposureInformationList
                = _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

            if (dailySummaryList.Count() > 0)
            {
                foreach (var ew in exposureWindowList.GroupBy(exposureWindow => exposureWindow.GetDateTime()))
                {
                    if (!dailySummaryMap.ContainsKey(ew.Key))
                    {
                        _loggerService.Warning($"ExposureWindow: {ew.Key} found, but that is not contained the list of dailySummary.");
                        continue;
                    }

                    var dailySummary = dailySummaryMap[ew.Key];

                    RiskLevel riskLevel = _exposureRiskCalculationService.CalcRiskLevel(
                        dailySummary,
                        ew.ToList(),
                        exposureRiskCalculationConfiguration
                        );
                    if (riskLevel < RiskLevel.High)
                    {
                        continue;
                    }

                    var ens = new ExposureSummary()
                    {
                        Timestamp    = ew.Key,
                        ExposureDate = IExposureDataRepository.ConvertToTerm(dailySummary.GetDateTime()),
                    };
                    var exposureDurationInSec = ew.Sum(e => e.ScanInstances.Sum(s => s.SecondsSinceLastScan));
                    ens.SetExposureTime(exposureDurationInSec);

                    exposures.Add(ens);
                }
            }

            if (userExposureInformationList.Count() > 0)
            {
                foreach (var ei in userExposureInformationList.GroupBy(userExposureInformation => userExposureInformation.Timestamp))
                {
                    var ens = new ExposureSummary()
                    {
                        Timestamp    = ei.Key,
                        ExposureDate = IExposureDataRepository.ConvertToTerm(ei.Key),
                    };
                    ens.SetExposureCount(ei.Count());
                    exposures.Add(ens);
                }
            }

            Exposures.Clear();
            foreach (var exposure in exposures.OrderByDescending(exposureSummary => exposureSummary.Timestamp))
            {
                Exposures.Add(exposure);
            }
        }