public List <UserEntity> ReadUsers() { var key = PrefixConstants.GetUsersReadKey(); var keyBytes = Encoding.UTF8.GetBytes(key); List <UserEntity> users = new List <UserEntity>(); try { List <byte[]> values = _database.GetAllStartingWith(keyBytes); foreach (var value in values) { try { users.Add(JsonSerializer.Deserialize <UserEntity>(Encoding.UTF8.GetString(value))); } catch (Exception e) { _logger.Error(e, $"Failed to deserialize {Encoding.UTF8.GetString(value)} to UserEntity"); } } } catch (Exception e) { _logger.Error(e, "Failed to read users!"); } return(users); }
private List <SensorDataEntity> GetValuesWithKeyEqualOrGreater(byte[] key, string path) { List <SensorDataEntity> result = new List <SensorDataEntity>(); try { var values = _database.GetAllStartingWith(key); foreach (var value in values) { try { var currentEl = JsonSerializer.Deserialize <SensorDataEntity>(Encoding.UTF8.GetString(value)); if (currentEl.Path == path) { result.Add(currentEl); } } catch (Exception e) { _logger.Error(e, $"Failed to deserialize {Encoding.UTF8.GetString(value)} to SensorDataEntity"); } } } catch (Exception e) { _logger.Error(e, $"Failed to read all sensors values for {Encoding.UTF8.GetString(key)}"); } return(result); }