// this will be called when the user is submitting a diagnosis and the local keys need to go to the server public async Task UploadSelfExposureKeysToServerAsync(IEnumerable <TemporaryExposureKey> temporaryExposureKeys) { var pendingDiagnosis = userData.PendingDiagnosis; if (pendingDiagnosis == null || string.IsNullOrEmpty(pendingDiagnosis.DiagnosisUid)) { throw new InvalidOperationException(); } var selfDiag = await CreateSubmissionAsync(temporaryExposureKeys, pendingDiagnosis); HttpStatusCode httpStatusCode = await httpDataService.PutSelfExposureKeysAsync(selfDiag); if (httpStatusCode == HttpStatusCode.NotAcceptable) { await UserDialogs.Instance.AlertAsync( "", AppResources.ExposureNotificationHandler1ErrorMessage, Resources.AppResources.ButtonOk); throw new InvalidOperationException(); } else if (httpStatusCode == HttpStatusCode.ServiceUnavailable || httpStatusCode == HttpStatusCode.InternalServerError) { await UserDialogs.Instance.AlertAsync( "", AppResources.ExposureNotificationHandler2ErrorMessage, Resources.AppResources.ButtonOk); throw new InvalidOperationException(); } // Update pending status pendingDiagnosis.Shared = true; await userDataService.SetAsync(userData); }
public async Task<HttpStatusCode> SubmitDiagnosisKeysAsync( bool hasSymptom, DateTime symptomOnsetDate, IList<TemporaryExposureKey> temporaryExposureKeys, string processNumber, string idempotencyKey ) { try { _loggerService.StartMethod(); if (string.IsNullOrEmpty(processNumber)) { _loggerService.Error($"Process number is null or empty."); throw new InvalidOperationException(); } _loggerService.Info($"TemporaryExposureKey count: {temporaryExposureKeys.Count()}"); foreach (var tek in temporaryExposureKeys) { _loggerService.Info( $"TemporaryExposureKey: " + $"RollingStartIntervalNumber: {tek.RollingStartIntervalNumber}({tek.GetRollingStartIntervalNumberAsUnixTimeInSec()}), " + $"RollingPeriod: {tek.RollingPeriod}, " + $"RiskLevel: {tek.RiskLevel}" ); } var diagnosisInfo = await CreateSubmissionAsync( hasSymptom, symptomOnsetDate, temporaryExposureKeys, processNumber, idempotencyKey ); return await _httpDataService.PutSelfExposureKeysAsync(diagnosisInfo); } finally { _loggerService.EndMethod(); } }
// this will be called when the user is submitting a diagnosis and the local keys need to go to the server public async Task UploadSelfExposureKeysToServerAsync(IEnumerable <TemporaryExposureKey> temporaryExposureKeys) { loggerService.StartMethod(); loggerService.Info($"TemporaryExposureKey count: {temporaryExposureKeys.Count()}"); foreach (var temporaryExposureKey in temporaryExposureKeys) { loggerService.Info($"TemporaryExposureKey: RollingStart: {temporaryExposureKey.RollingStart}({temporaryExposureKey.RollingStart.ToUnixTimeSeconds()}), RollingDuration: {temporaryExposureKey.RollingDuration}, TransmissionRiskLevel: {temporaryExposureKey.TransmissionRiskLevel}"); } var latestDiagnosis = userData.LatestDiagnosis; if (latestDiagnosis == null || string.IsNullOrEmpty(latestDiagnosis.DiagnosisUid)) { loggerService.Error($"Diagnostic number is null or empty."); loggerService.EndMethod(); throw new InvalidOperationException(); } var selfDiag = await CreateSubmissionAsync(temporaryExposureKeys, latestDiagnosis); HttpStatusCode httpStatusCode = await httpDataService.PutSelfExposureKeysAsync(selfDiag); loggerService.Info($"HTTP status is {httpStatusCode}({(int)httpStatusCode})."); if (httpStatusCode == HttpStatusCode.NotAcceptable) { await UserDialogs.Instance.AlertAsync( "", AppResources.ExposureNotificationHandler1ErrorMessage, Resources.AppResources.ButtonOk); loggerService.Error($"The diagnostic number is incorrect."); loggerService.EndMethod(); throw new InvalidOperationException(); } else if (httpStatusCode == HttpStatusCode.ServiceUnavailable || httpStatusCode == HttpStatusCode.InternalServerError) { await UserDialogs.Instance.AlertAsync( "", AppResources.ExposureNotificationHandler2ErrorMessage, Resources.AppResources.ButtonOk); loggerService.Error($"Cannot connect to the center."); loggerService.EndMethod(); throw new InvalidOperationException(); } else if (httpStatusCode == HttpStatusCode.BadRequest) { await UserDialogs.Instance.AlertAsync( "", AppResources.ExposureNotificationHandler3ErrorMessage, Resources.AppResources.ButtonOk); loggerService.Error($"There is a problem with the record data."); loggerService.EndMethod(); throw new InvalidOperationException(); } await userDataService.SetAsync(userData); loggerService.EndMethod(); }