Improve Sonic Java discovery beyond SonicHome\jre layouts.

Parse setenv scripts, search recursively under Sonic/MQ/ESB roots, and surface resolved SonicHome + java paths in the UI and full error lists.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-24 09:07:21 +02:00
co-authored by Cursor
parent ea6e760434
commit d1ef63f3f7
4 changed files with 886 additions and 100 deletions
+51 -20
View File
@@ -1781,11 +1781,6 @@ namespace ZA.CoreService.ESBCertificateManager
cmbSonicConnection.Items.Add(conn.Name);
}
if (cmbSonicConnection.Items.Count > 0)
{
cmbSonicConnection.SelectedIndex = 0;
}
btnLoadFromSonic = CreateSecondaryButton("Container laden");
btnLoadFromSonic.Location = new Point(392, 103);
btnLoadFromSonic.Size = new Size(148, 28);
@@ -1797,20 +1792,19 @@ namespace ZA.CoreService.ESBCertificateManager
ForeColor = MutedTextColor,
Font = new Font("Segoe UI", 8.5f),
AutoSize = true,
Location = new Point(552, 109)
MaximumSize = new Size(720, 0),
Location = new Point(552, 100)
};
if (!_sonicDiscovery.HasConnections)
cmbSonicConnection.SelectedIndexChanged += (_, _) => RefreshSonicStatusLine();
if (cmbSonicConnection.Items.Count > 0)
{
lblSonicStatus.Text = "Keine Sonic-Verbindung in appsettings konfiguriert";
lblSonicStatus.ForeColor = RedColor;
cmbSonicConnection.SelectedIndex = 0;
}
else
{
SonicConnection first = _sonicDiscovery.Connections[0];
lblSonicStatus.Text =
$"{_sonicDiscovery.Connections.Count} Verb. | {first.ManagementModeDisplay} | {first.DomainName} | {first.ConnectionUrl}";
lblSonicStatus.ForeColor = GreenColor;
RefreshSonicStatusLine();
}
card.Controls.Add(sonicLabel);
@@ -1819,6 +1813,44 @@ namespace ZA.CoreService.ESBCertificateManager
card.Controls.Add(lblSonicStatus);
}
private void RefreshSonicStatusLine(string? suffix = null)
{
if (!_sonicDiscovery.HasConnections)
{
lblSonicStatus.Text = "Keine Sonic-Verbindung in appsettings konfiguriert";
lblSonicStatus.ForeColor = RedColor;
return;
}
string? selectedName = cmbSonicConnection?.SelectedItem?.ToString();
SonicConnection conn = _sonicDiscovery.Connections
.FirstOrDefault(c => string.Equals(c.Name, selectedName, StringComparison.OrdinalIgnoreCase))
?? _sonicDiscovery.Connections[0];
(string sonicHome, string? javaExe) = new SonicMfApiExecutor(conn).ResolveRuntimePaths();
string javaDisplay = string.IsNullOrWhiteSpace(javaExe) ? "java=?" : javaExe;
string baseText =
$"{conn.ManagementModeDisplay} | SonicHome={sonicHome} | {javaDisplay}";
if (!string.IsNullOrWhiteSpace(suffix))
{
baseText = $"{suffix} | {baseText}";
}
lblSonicStatus.Text = baseText;
lblSonicStatus.ForeColor = string.IsNullOrWhiteSpace(javaExe) ? GoldColor : GreenColor;
}
private static string TruncateStatus(string? text, int max = 120)
{
if (string.IsNullOrWhiteSpace(text))
{
return "unbekannt";
}
string oneLine = text.Replace('\r', ' ').Replace('\n', ' ').Trim();
return oneLine.Length <= max ? oneLine : oneLine[..max] + "…";
}
private async Task LoadFromSonicAsync()
{
if (_isOperationRunning) return;
@@ -1840,7 +1872,7 @@ namespace ZA.CoreService.ESBCertificateManager
if (!result.Success)
{
lblSonicStatus.Text = $"Fehler: {result.ErrorMessage}";
RefreshSonicStatusLine($"Fehler: {TruncateStatus(result.ErrorMessage)}");
lblSonicStatus.ForeColor = RedColor;
SetStatus($"Sonic-Discovery fehlgeschlagen: {result.ErrorMessage}", isError: true);
return;
@@ -1858,7 +1890,7 @@ namespace ZA.CoreService.ESBCertificateManager
if (total == 0)
{
lblSonicStatus.Text = $"Verb. ok 0 Container in Domain '{domain}'";
RefreshSonicStatusLine($"Verb. ok 0 Container '{domain}'");
lblSonicStatus.ForeColor = GoldColor;
SetStatus(
result.ErrorMessage
@@ -1867,7 +1899,7 @@ namespace ZA.CoreService.ESBCertificateManager
}
else if (remote == 0)
{
lblSonicStatus.Text = $"Verb. ok Domain '{domain}': 0 remote, {total} aus Config";
RefreshSonicStatusLine($"Verb. ok 0 remote, {total} Config '{domain}'");
lblSonicStatus.ForeColor = GoldColor;
SetStatus(
$"Domain '{domain}': Remote leer {total} Ziel(e) aus appsettings/KnownContainers. "
@@ -1876,8 +1908,7 @@ namespace ZA.CoreService.ESBCertificateManager
}
else
{
lblSonicStatus.Text = $"Domain '{domain}': {remote} remote, {total} gesamt";
lblSonicStatus.ForeColor = GreenColor;
RefreshSonicStatusLine($"Domain '{domain}': {remote} remote, {total} gesamt");
SetStatus($"Sonic Domain '{domain}': {total} Ziel(e) geladen ({remote} remote).", isError: false);
}
@@ -1885,13 +1916,13 @@ namespace ZA.CoreService.ESBCertificateManager
}
catch (OperationCanceledException)
{
lblSonicStatus.Text = "Timeout Verbindung nicht erreichbar";
RefreshSonicStatusLine("Timeout");
lblSonicStatus.ForeColor = RedColor;
SetStatus($"Sonic-Discovery Timeout ({selectedConnection})", isError: true);
}
catch (Exception ex)
{
lblSonicStatus.Text = $"Fehler: {ex.Message}";
RefreshSonicStatusLine($"Fehler: {TruncateStatus(ex.Message)}");
lblSonicStatus.ForeColor = RedColor;
SetStatus($"Sonic-Discovery Fehler: {ex.Message}", isError: true);
}