public void SetSendEventLogState(SendEventLogState sendEventLogState) { _loggerService.StartMethod(); _preferencesService.SetValue(PreferenceKey.SendEventLogState, (int)sendEventLogState); _loggerService.EndMethod(); }
public void SetSendEventLogState(EventType eventType, SendEventLogState state) { try { _loggerService.StartMethod(); string stateString = EMPTY_DICT; IDictionary <string, int> stateDict = new Dictionary <string, int>(); try { if (_preferencesService.ContainsKey(PreferenceKey.SendEventLogState)) { stateString = _preferencesService.GetStringValue( PreferenceKey.SendEventLogState, EMPTY_DICT ); stateDict = JsonConvert.DeserializeObject <IDictionary <string, int> >(stateString); } } catch (JsonReaderException exception) { _loggerService.Exception($"JsonSerializationException {stateString}", exception); } stateDict[eventType.ToString()] = (int)state; string newStateString = JsonConvert.SerializeObject(stateDict); _preferencesService.SetStringValue(PreferenceKey.SendEventLogState, newStateString); } finally { _loggerService.EndMethod(); } }
private async Task SendExposureDataAsync( string idempotencyKey, ExposureData exposureData ) { _loggerService.StartMethod(); SendEventLogState sendEventLogState = _userDataRepository.GetSendEventLogState(); bool isEnabled = sendEventLogState == SendEventLogState.Enable; if (!isEnabled) { _loggerService.Debug($"Send event-log function is not enabled."); _loggerService.EndMethod(); return; } await _serverConfigurationRepository.LoadAsync(); string exposureDataCollectServerEndpoint = _serverConfigurationRepository.EventLogApiEndpoint; _loggerService.Debug($"exposureDataCollectServerEndpoint: {exposureDataCollectServerEndpoint}"); try { var contentJson = exposureData.ToJsonString(); var eventLog = new V1EventLogRequest.EventLog() { HasConsent = isEnabled, Epoch = _dateTimeUtility.UtcNow.ToUnixEpoch(), Type = "ExposureData", Subtype = "Debug", Content = contentJson, }; var eventLogs = new[] { eventLog }; var request = new V1EventLogRequest() { IdempotencyKey = idempotencyKey, Platform = _essentialsService.Platform, AppPackageName = _essentialsService.AppPackageName, EventLogs = eventLogs, }; request.DeviceVerificationPayload = await _deviceVerifier.VerifyAsync(request); var requestJson = request.ToJsonString(); var httpContent = new StringContent(requestJson, Encoding.UTF8, "application/json"); Uri uri = new Uri(exposureDataCollectServerEndpoint); HttpResponseMessage response = await _httpClient.PutAsync(uri, httpContent); if (response.IsSuccessStatusCode) { var responseJson = await response.Content.ReadAsStringAsync(); _loggerService.Debug($"{responseJson}"); } else { _loggerService.Info($"UploadExposureDataAsync {response.StatusCode}"); } } finally { _loggerService.EndMethod(); } }