115 lines
3.3 KiB
C#
115 lines
3.3 KiB
C#
using ZA.CoreService.ESBCertificateManager.Services;
|
|
|
|
namespace ZA.CoreService.ESBCertificateManager.Models;
|
|
|
|
/// <summary>
|
|
/// Aus dbo.SonicConnection geladene Verbindungsdaten.
|
|
/// Zugangsdaten liegen ausschließlich in dbo.SonicCredential.
|
|
/// </summary>
|
|
public sealed class DatabaseSonicConnection
|
|
{
|
|
public int Id { get; init; }
|
|
|
|
public required string Name { get; init; }
|
|
|
|
public required string ManagementHost { get; init; }
|
|
|
|
public int ManagementPort { get; init; }
|
|
|
|
public string? ConnectionProtocol { get; init; }
|
|
|
|
public string? DomainName { get; init; }
|
|
|
|
public string? EnvironmentCode { get; init; }
|
|
|
|
public bool IsActive { get; init; }
|
|
|
|
public string BuildConnectionUrl()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ConnectionProtocol))
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt ConnectionProtocol.");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(ManagementHost))
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt ManagementHost.");
|
|
}
|
|
|
|
if (ManagementPort is < 1 or > 65535)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt ein gültiger ManagementPort.");
|
|
}
|
|
|
|
string protocol = ConnectionProtocol
|
|
.Trim()
|
|
.TrimEnd(':', '/');
|
|
|
|
string host = ManagementHost.Trim();
|
|
|
|
return $"{protocol}://{host}:{ManagementPort}";
|
|
}
|
|
|
|
public SonicConnection ToRuntimeConnection(
|
|
RuntimeSettings runtimeSettings,
|
|
SonicCredentialProfile credential)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(credential);
|
|
|
|
if (string.IsNullOrWhiteSpace(DomainName))
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt DomainName.");
|
|
}
|
|
|
|
if (!credential.IsComplete)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlen die Zugangsdaten. " +
|
|
"Bitte die Einstellungen öffnen und ein Benutzerprofil hinterlegen.");
|
|
}
|
|
|
|
string javaExecutablePath =
|
|
PathResolver.ResolvePath(
|
|
runtimeSettings.JavaExecutablePath);
|
|
|
|
string sonicClientLibraryPath =
|
|
PathResolver.ResolvePath(
|
|
runtimeSettings.SonicClientLibraryPath);
|
|
|
|
string javaBinDirectory =
|
|
Path.GetDirectoryName(javaExecutablePath)
|
|
?? string.Empty;
|
|
|
|
string javaHome =
|
|
Directory.GetParent(javaBinDirectory)?.FullName
|
|
?? string.Empty;
|
|
|
|
string sonicHome =
|
|
Directory.GetParent(sonicClientLibraryPath)?.FullName
|
|
?? string.Empty;
|
|
|
|
return new SonicConnection
|
|
{
|
|
Name = Name,
|
|
DomainName = DomainName,
|
|
ConnectionUrl = BuildConnectionUrl(),
|
|
Username = credential.UserName,
|
|
|
|
// Nur Laufzeitwert, bereits clientseitig entschlüsselt.
|
|
Password = credential.Secret,
|
|
|
|
JavaPath = javaExecutablePath,
|
|
JavaHome = javaHome,
|
|
MfClientLibPath = sonicClientLibraryPath,
|
|
SonicHome = sonicHome,
|
|
|
|
TimeoutSeconds = 120,
|
|
PostRestartDelaySeconds = 20
|
|
};
|
|
}
|
|
}
|