async Task DoAsyncWork() { if (await ExposureNotification.IsEnabledAsync()) { await ExposureNotification.UpdateKeysFromServer(); } }
public async Task <bool> StartExposureNotification() { loggerService.StartMethod(); try { var enabled = await ExposureNotification.IsEnabledAsync(); if (!enabled) { await ExposureNotification.StartAsync(); } loggerService.EndMethod(); return(true); } catch (Exception ex) { loggerService.Exception("Error enabling notifications.", ex); loggerService.EndMethod(); return(false); } finally { } }
public async Task <bool> IsEnabled() { try { return(await ExposureNotification.IsEnabledAsync()); } catch (Exception e) { if (!e.HandleExposureNotificationException(nameof(InfectionStatusViewModel), nameof(IsEnabled))) { throw e; } return(false); } }
async Task <Result> DoAsyncWork() { try { if (await ExposureNotification.IsEnabledAsync()) { await ExposureNotification.UpdateKeysFromServer(); } return(Result.InvokeSuccess()); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); return(Result.InvokeRetry()); } }
public async Task UploadSelfExposureKeysToServerAsync(IEnumerable <TemporaryExposureKey> tempKeys) { // Convert to ExposureKeyModel list as it is extended with DaysSinceOnsetOfSymptoms value IEnumerable <ExposureKeyModel> temporaryExposureKeys = tempKeys?.Select(key => new ExposureKeyModel(key)) ?? new List <ExposureKeyModel>(); // There is a better behaviour of uploading keys when scanning is Stoped/Started (UIAlert for permission is always shown then), // The IF-check just toggles the scanning status on/off or off/on to keep the scanning status // the same as it was before method is called try { if (ServiceLocator.Current.GetInstance <IDeviceInfo>().Platform == DevicePlatform.iOS) { if (await ExposureNotification.IsEnabledAsync()) { await ExposureNotification.StopAsync(); await ExposureNotification.StartAsync(); } else { await ExposureNotification.StartAsync(); await ExposureNotification.StopAsync(); } } } catch (Exception e) { if (!e.HandleExposureNotificationException(nameof(ExposureNotificationHandler), nameof(UploadSelfExposureKeysToServerAsync))) { throw e; } } if (FakeGatewayUtils.IsFakeGatewayTest) { FakeGatewayUtils.LastPulledExposureKeys = temporaryExposureKeys; return; } if (AuthenticationState.PersonalData?.Access_token == null) { throw new AccessTokenMissingFromIDPortenException("The token from ID Porten is not set"); } if (AuthenticationState.PersonalData?.VisitedCountries == null) { throw new VisitedCountriesMissingException( "The visited countries list is missing. Possibly garbage collection removed it."); } if (!MiBaDate.HasValue) { throw new MiBaDateMissingException("The symptom onset date is not set from the calling view model"); } DateTime MiBaDateAsUniversalTime = MiBaDate.Value.ToUniversalTime(); List <ExposureKeyModel> validKeys = UploadDiagnosisKeysHelper.CreateAValidListOfTemporaryExposureKeys(temporaryExposureKeys); // Here all keys are extended with DaysSinceOnsetOfSymptoms value validKeys = UploadDiagnosisKeysHelper.SetTransmissionRiskLevel(validKeys, MiBaDateAsUniversalTime); bool success = await exposureNotificationWebService.PostSelfExposureKeys(validKeys); if (!success) { throw new FailedToPushToServerException("Failed to push keys to the server"); } }