Initial commit: ESB Certificate Manager.
EOF Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using ZA.CoreService.ESBCertificateManager.Models;
|
||||
|
||||
namespace ZA.CoreService.ESBCertificateManager.Data;
|
||||
|
||||
public static class TargetRepositoryFactory
|
||||
{
|
||||
public static async Task<(ITargetRepository Repository, string LoadMessage)> CreateAsync(
|
||||
AppSettings settings,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
string samplePath = Path.GetFullPath(
|
||||
Path.Combine(AppContext.BaseDirectory, settings.SampleTargetsPath));
|
||||
|
||||
if (settings.UseOfflineSampleData)
|
||||
{
|
||||
ITargetRepository jsonRepo = new JsonTargetRepository(samplePath);
|
||||
_ = await jsonRepo.GetActiveTargetsAsync(cancellationToken);
|
||||
return (jsonRepo, $"Ziele geladen aus {jsonRepo.SourceDescription}.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(settings.ConnectionString))
|
||||
{
|
||||
return OfflineSample(samplePath, "Keine SQL-Verbindung konfiguriert – Offline-Sample wird verwendet.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
SqlTargetRepository sqlRepo = new(settings.ConnectionString);
|
||||
_ = await sqlRepo.GetActiveTargetsAsync(cancellationToken);
|
||||
return (sqlRepo, $"Ziele geladen aus {sqlRepo.SourceDescription}.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return OfflineSample(
|
||||
samplePath,
|
||||
$"SQL nicht erreichbar ({ex.Message}). Offline-Sample wird verwendet.");
|
||||
}
|
||||
}
|
||||
|
||||
private static (ITargetRepository Repository, string LoadMessage) OfflineSample(
|
||||
string samplePath,
|
||||
string message)
|
||||
=> (new JsonTargetRepository(samplePath), message);
|
||||
}
|
||||
Reference in New Issue
Block a user