Ejemplo n.º 1
0
        public Task <long> GetLastProcessDiagnosisKeyTimestampAsync(string region)
        {
            _loggerService.StartMethod();

            try
            {
                var result = 0L;

                var jsonString = _preferencesService.GetStringValue(PreferenceKey.LastProcessTekTimestamp, null);
                if (!string.IsNullOrEmpty(jsonString))
                {
                    var dict = JsonConvert.DeserializeObject <Dictionary <string, long> >(jsonString);
                    if (dict.ContainsKey(region))
                    {
                        result = dict[region];
                    }
                }

                return(Task.FromResult(result));
            }
            finally
            {
                _loggerService.EndMethod();
            }
        }
Ejemplo n.º 2
0
        private void MigrateDateTimeToEpoch(string dateTimeKey, string epochKey, TimeZoneInfo?timeZoneInfo, DateTime fallbackDateTime)
        {
            string dateTimeStr = _preferencesService.GetStringValue(dateTimeKey, fallbackDateTime.ToString());

            /// **Note**
            /// `dateTime` still can be `0001/01/01 00:00:00` (= UNIX Epoch:`-62135596800`).
            /// For compatibility reasons, do not change this behavior.
            DateTime dateTime;

            try
            {
                dateTime = DateTime.Parse(dateTimeStr);

                if (timeZoneInfo is null)
                {
                    dateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
                }
                else
                {
                    dateTime = TimeZoneInfo.ConvertTimeToUtc(
                        DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified),
                        timeZoneInfo
                        );
                }
            }
            catch (FormatException exception)
            {
                _loggerService.Exception($"Parse dateTime FormatException occurred. {dateTimeStr}", exception);
                dateTime = fallbackDateTime;
            }

            _preferencesService.SetLongValue(epochKey, dateTime.ToUnixEpoch());
            _preferencesService.RemoveValue(dateTimeKey);
        }
Ejemplo n.º 3
0
        public SendEventLogState GetSendEventLogState(EventType eventType)
        {
            string stateString = EMPTY_DICT;

            try
            {
                _loggerService.StartMethod();

                if (!_preferencesService.ContainsKey(PreferenceKey.SendEventLogState))
                {
                    return(SendEventLogState.NotSet);
                }

                stateString = _preferencesService.GetStringValue(
                    PreferenceKey.SendEventLogState,
                    EMPTY_DICT
                    );

                IDictionary <string, int> stateDict
                    = JsonConvert.DeserializeObject <IDictionary <string, int> >(stateString);

                if (!stateDict.ContainsKey(eventType.ToString()))
                {
                    return(SendEventLogState.NotSet);
                }

                int value = stateDict[eventType.ToString()];
                return((SendEventLogState)Enum.ToObject(typeof(SendEventLogState), value));
            }
            catch (JsonReaderException exception)
            {
                _preferencesService.SetStringValue(PreferenceKey.SendEventLogState, EMPTY_DICT);

                _loggerService.Exception($"JsonSerializationException {stateString}", exception);
                _loggerService.Warning($"Preference-key {PreferenceKey.SendEventLogState} has been initialized.");
            }
            finally
            {
                _loggerService.EndMethod();
            }

            return(SendEventLogState.NotSet);
        }