feat(core): add shared DTOs, MqttTopics constants, DatabaseBootstrapper, and ManagedMqttClient extensions
This commit is contained in:
@@ -108,11 +108,10 @@ public class SettingsService : ISettingsService
|
||||
IEnumerable<Type>? customKeyHolders = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var holderTypes = new List<Type> { typeof(CoreSettingKeys) };
|
||||
if (customKeyHolders != null)
|
||||
{
|
||||
holderTypes.AddRange(customKeyHolders);
|
||||
}
|
||||
var isCustomScoped = customKeyHolders != null && customKeyHolders.Any();
|
||||
var holderTypes = isCustomScoped
|
||||
? customKeyHolders!.ToList()
|
||||
: new List<Type> { typeof(CoreSettingKeys) };
|
||||
|
||||
var resultList = new List<DynamicSettingDto>();
|
||||
var seenKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
@@ -154,34 +153,37 @@ public class SettingsService : ISettingsService
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Prüfen, ob in der DB weitere gespeicherte Settings existieren, die nicht im Code deklariert sind
|
||||
try
|
||||
// 2. Prüfen, ob in der DB weitere gespeicherte Settings existieren (nur wenn nicht strikt auf custom KeyHolders begrenzt)
|
||||
if (!isCustomScoped)
|
||||
{
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
var dbContext = scope.ServiceProvider.GetService<ISettingsDbContext>();
|
||||
if (dbContext != null)
|
||||
try
|
||||
{
|
||||
var dbSettings = await dbContext.DynamicSettings.AsNoTracking().ToListAsync(cancellationToken);
|
||||
foreach (var dbSetting in dbSettings)
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
var dbContext = scope.ServiceProvider.GetService<ISettingsDbContext>();
|
||||
if (dbContext != null)
|
||||
{
|
||||
if (!seenKeys.Contains(dbSetting.Key))
|
||||
var dbSettings = await dbContext.DynamicSettings.AsNoTracking().ToListAsync(cancellationToken);
|
||||
foreach (var dbSetting in dbSettings)
|
||||
{
|
||||
seenKeys.Add(dbSetting.Key);
|
||||
var (inferredVal, inferredType) = InferJsonValueAndType(dbSetting.ValueJson);
|
||||
resultList.Add(new DynamicSettingDto(
|
||||
Key: dbSetting.Key,
|
||||
Value: inferredVal,
|
||||
Type: inferredType,
|
||||
Description: FormatDescriptionFromKey(dbSetting.Key),
|
||||
UpdatedAt: dbSetting.LastUpdatedUtc
|
||||
));
|
||||
if (!seenKeys.Contains(dbSetting.Key))
|
||||
{
|
||||
seenKeys.Add(dbSetting.Key);
|
||||
var (inferredVal, inferredType) = InferJsonValueAndType(dbSetting.ValueJson);
|
||||
resultList.Add(new DynamicSettingDto(
|
||||
Key: dbSetting.Key,
|
||||
Value: inferredVal,
|
||||
Type: inferredType,
|
||||
Description: FormatDescriptionFromKey(dbSetting.Key),
|
||||
UpdatedAt: dbSetting.LastUpdatedUtc
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogWarning(ex, "[SettingsService] Error reading database settings during GetAllRegisteredSettingsAsync.");
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogWarning(ex, "[SettingsService] Error reading database settings during GetAllRegisteredSettingsAsync.");
|
||||
}
|
||||
}
|
||||
|
||||
return resultList.OrderBy(s => s.Key).ToList();
|
||||
|
||||
Reference in New Issue
Block a user