Fix app startup and enable Sonic ESB restart via remote CMD.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-24 08:17:35 +02:00
co-authored by Cursor
parent ed8e2822d1
commit c2268f1908
9 changed files with 446 additions and 207 deletions
+102 -5
View File
@@ -52,6 +52,7 @@ namespace ZA.CoreService.ESBCertificateManager
private Button btnClose = null!;
private Button btnValidate = null!;
private Button btnDeploy = null!;
private Button btnRestartOnly = null!;
private Button btnCancelRun = null!;
private bool isMaximized = false;
@@ -1231,6 +1232,11 @@ namespace ZA.CoreService.ESBCertificateManager
btnValidate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
btnValidate.Click += async (_, _) => await RunValidationAsync();
btnRestartOnly = CreateSecondaryButton("ESB neu starten");
btnRestartOnly.Size = new Size(150, 42);
btnRestartOnly.Anchor = AnchorStyles.Top | AnchorStyles.Right;
btnRestartOnly.Click += async (_, _) => await RunRestartOnlyAsync();
btnDeploy = CreatePrimaryButton("Deployment starten");
btnDeploy.Size = new Size(170, 42);
btnDeploy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@@ -1238,12 +1244,14 @@ namespace ZA.CoreService.ESBCertificateManager
panel.Controls.Add(btnCancelRun);
panel.Controls.Add(btnValidate);
panel.Controls.Add(btnRestartOnly);
panel.Controls.Add(btnDeploy);
panel.Resize += (_, _) =>
{
btnDeploy.Left = panel.Width - btnDeploy.Width;
btnValidate.Left = btnDeploy.Left - btnValidate.Width - 12;
btnRestartOnly.Left = btnDeploy.Left - btnRestartOnly.Width - 12;
btnValidate.Left = btnRestartOnly.Left - btnValidate.Width - 12;
btnCancelRun.Left = btnValidate.Left - btnCancelRun.Width - 12;
};
@@ -1377,11 +1385,20 @@ namespace ZA.CoreService.ESBCertificateManager
btnCancelRun.Enabled = _isOperationRunning;
btnValidate.Enabled = idle && hasCertificate && hasTargets;
btnDeploy.Enabled = idle && hasCertificate && hasSelection;
if (btnRestartOnly is not null)
{
btnRestartOnly.Enabled = idle && hasSelection;
}
if (dgvTargets is not null)
{
dgvTargets.Enabled = idle;
}
if (btnLoadFromSonic is not null)
{
btnLoadFromSonic.Enabled = idle && _sonicDiscovery.HasConnections;
}
}
private void SetStatus(string message, bool isError)
@@ -1464,6 +1481,86 @@ namespace ZA.CoreService.ESBCertificateManager
return Task.CompletedTask;
}
private async Task RunRestartOnlyAsync()
{
if (_isOperationRunning)
{
return;
}
List<DeploymentTarget> selected = GetSelectedTargets();
PreflightValidationResult preflight = _orchestrator.ValidateRestartOnly(selected);
if (!preflight.IsValid)
{
ShowPreflightIssues(
preflight,
"Neustart blockiert Vorabprüfung fehlgeschlagen.",
"ESB neu starten");
return;
}
DialogResult confirm = MessageBox.Show(
this,
$"ESB/Container für {selected.Count} Ziel(e) wirklich neu starten?\n\n" +
"Es wird stopcontainer/startcontainer über die Sonic-Verbindung ausgeführt\n" +
"(WinRM Remote-CMD oder LocalCmd laut appsettings).",
"ESB neu starten",
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (confirm != DialogResult.Yes)
{
return;
}
_runCts?.Dispose();
_runCts = new CancellationTokenSource();
SetOperationRunning(true);
UpdateToNextStep(3);
SetStatus($"ESB-Neustart läuft für {selected.Count} Ziel(e)…", isError: false);
Progress<TargetProgressUpdate> progress = new(update =>
{
SetTargetRowStatus(update.TargetId, update.StatusText);
SetStatus(update.StatusText, isError: update.SuccessHint == false);
});
try
{
DeploymentRunResult runResult = await _orchestrator.RestartOnlyAsync(
selected,
progress,
_runCts.Token);
foreach (TargetStepResult targetResult in runResult.TargetResults)
{
SetTargetRowStatus(targetResult.TargetId, targetResult.StatusText);
}
SetStatus(
runResult.OverallSuccess
? $"Neustart erfolgreich ({runResult.TargetResults.Count} Ziel(e))."
: "Neustart mit Fehlern beendet. Details in Status-Spalte / Log.",
isError: !runResult.OverallSuccess);
}
catch (OperationCanceledException)
{
SetStatus("Neustart abgebrochen.", isError: true);
}
catch (Exception ex)
{
SetStatus($"Neustart fehlgeschlagen: {ex.Message}", isError: true);
MessageBox.Show(this, ex.Message, "ESB neu starten", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
SetOperationRunning(false);
_runCts?.Dispose();
_runCts = null;
}
}
private async Task RunDeploymentAsync()
{
if (_isOperationRunning || _loadedCertificateInfo is null)
@@ -1680,9 +1777,6 @@ namespace ZA.CoreService.ESBCertificateManager
lblSonicStatus = new Label
{
Text = _sonicDiscovery.HasConnections
? "Keine Verbindung konfiguriert"
: "Keine Sonic-Verbindung konfiguriert",
ForeColor = MutedTextColor,
Font = new Font("Segoe UI", 8.5f),
AutoSize = true,
@@ -1696,7 +1790,10 @@ namespace ZA.CoreService.ESBCertificateManager
}
else
{
lblSonicStatus.Text = $"{_sonicDiscovery.Connections.Count} Verbindung(en) konfiguriert noch nicht geladen";
SonicConnection first = _sonicDiscovery.Connections[0];
lblSonicStatus.Text =
$"{_sonicDiscovery.Connections.Count} Verb. | {first.ManagementMode} | {first.DomainName} | SonicHome={first.SonicHome}";
lblSonicStatus.ForeColor = GreenColor;
}
card.Controls.Add(sonicLabel);