Expand settings UI to manage systems, containers, and certificate paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-29 08:53:13 +02:00
co-authored by Cursor
parent 121a428755
commit ed6777ffed
8 changed files with 2291 additions and 501 deletions
@@ -0,0 +1,235 @@
using ZA.CoreService.ESBCertificateManager.Models;
namespace ZA.CoreService.ESBCertificateManager.Setup;
public sealed class AddContainerForm : Form
{
private readonly SetupCoordinator _coordinator;
private readonly ComboBox _cmbCompany;
private readonly ComboBox _cmbSystem;
private readonly TextBox _txtName;
private readonly TextBox _txtDisplay;
private readonly TextBox _txtTimeout;
private readonly Button _btnSave;
private bool _running;
public int? CreatedSonicContainerId { get; private set; }
public AddContainerForm(
SetupCoordinator coordinator,
int? preferredSonicConnectionId = null)
{
_coordinator = coordinator;
Text = "Container hinzufügen";
StartPosition = FormStartPosition.CenterParent;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;
ClientSize = new Size(540, 470);
BackColor = SettingsUi.Background;
ForeColor = SettingsUi.Text;
Font = new Font("Segoe UI", 10f);
Label title = new()
{
Text = "Neuer Container",
Location = new Point(28, 22),
AutoSize = true,
Font = new Font("Segoe UI Semibold", 18f, FontStyle.Bold),
ForeColor = SettingsUi.Text
};
Label subtitle = new()
{
Text =
"Container einer Company und einem Sonic-System zuordnen.",
Location = new Point(30, 58),
AutoSize = true,
ForeColor = SettingsUi.Muted
};
Panel card = SettingsUi.CreateCard();
card.Location = new Point(28, 95);
card.Size = new Size(484, 290);
card.Paint += SettingsUi.PaintCardBorder;
_cmbCompany = SettingsUi.CreateComboBox();
_cmbSystem = SettingsUi.CreateComboBox();
_txtName = SettingsUi.CreateTextBox();
_txtDisplay = SettingsUi.CreateTextBox();
_txtTimeout = SettingsUi.CreateTextBox();
_txtTimeout.Text = "180";
AddField(card, "Company", _cmbCompany, 18, 18, 440);
AddField(card, "Sonic-System", _cmbSystem, 18, 78, 440);
AddField(card, "Container-Name", _txtName, 18, 138, 440);
AddField(card, "Anzeigename (optional)", _txtDisplay, 18, 198, 280);
AddField(card, "Timeout (s)", _txtTimeout, 318, 198, 140);
_btnSave = SettingsUi.CreatePrimaryButton("Container anlegen");
_btnSave.Location = new Point(292, 405);
_btnSave.Size = new Size(220, 40);
_btnSave.Click += async (_, _) => await SaveAsync();
Button cancel = SettingsUi.CreateGhostButton("Abbrechen");
cancel.Location = new Point(170, 405);
cancel.Size = new Size(110, 40);
cancel.Click += (_, _) =>
{
DialogResult = DialogResult.Cancel;
Close();
};
Controls.Add(title);
Controls.Add(subtitle);
Controls.Add(card);
Controls.Add(cancel);
Controls.Add(_btnSave);
Shown += async (_, _) =>
await LoadLookupsAsync(preferredSonicConnectionId);
}
private async Task LoadLookupsAsync(int? preferredSonicConnectionId)
{
try
{
IReadOnlyList<CompanyOption> companies =
await _coordinator.LoadCompaniesAsync();
IReadOnlyList<SonicSystemOption> systems =
await _coordinator.LoadSystemsAsync();
_cmbCompany.Items.Clear();
foreach (CompanyOption company in companies)
{
_cmbCompany.Items.Add(company);
}
if (_cmbCompany.Items.Count > 0)
{
_cmbCompany.SelectedIndex = 0;
}
_cmbSystem.Items.Clear();
int selected = 0;
for (int index = 0; index < systems.Count; index++)
{
_cmbSystem.Items.Add(systems[index]);
if (preferredSonicConnectionId is int id
&& systems[index].SonicConnectionId == id)
{
selected = index;
}
}
if (_cmbSystem.Items.Count > 0)
{
_cmbSystem.SelectedIndex = selected;
}
}
catch (Exception ex)
{
MessageBox.Show(
this,
ex.Message,
"Container",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private async Task SaveAsync()
{
if (_running)
{
return;
}
if (_cmbCompany.SelectedItem is not CompanyOption company)
{
MessageBox.Show(
this,
"Bitte eine Company wählen.",
"Container",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
if (_cmbSystem.SelectedItem is not SonicSystemOption system)
{
MessageBox.Show(
this,
"Bitte ein Sonic-System wählen.",
"Container",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
if (!int.TryParse(_txtTimeout.Text.Trim(), out int timeout))
{
MessageBox.Show(
this,
"Bitte einen gültigen Timeout eingeben.",
"Container",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
_running = true;
_btnSave.Enabled = false;
Cursor = Cursors.WaitCursor;
try
{
CreatedSonicContainerId =
await _coordinator.AddSonicContainerAsync(
company.CompanyId,
system.SonicConnectionId,
_txtName.Text,
_txtDisplay.Text,
timeout);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(
this,
ex.Message,
"Container",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
_running = false;
_btnSave.Enabled = true;
Cursor = Cursors.Default;
}
}
private static void AddField(
Control parent,
string label,
Control input,
int x,
int y,
int width)
{
Label fieldLabel = SettingsUi.CreateFieldLabel(label);
fieldLabel.Location = new Point(x, y);
input.Location = new Point(x, y + 22);
input.Width = width;
parent.Controls.Add(fieldLabel);
parent.Controls.Add(input);
}
}
@@ -0,0 +1,160 @@
namespace ZA.CoreService.ESBCertificateManager.Setup;
public sealed class AddSonicSystemForm : Form
{
private readonly SetupCoordinator _coordinator;
private readonly TextBox _txtName;
private readonly TextBox _txtHost;
private readonly TextBox _txtPort;
private readonly TextBox _txtDomain;
private readonly ComboBox _cmbProtocol;
private readonly Button _btnSave;
private bool _running;
public int? CreatedSonicConnectionId { get; private set; }
public AddSonicSystemForm(SetupCoordinator coordinator)
{
_coordinator = coordinator;
Text = "Sonic-System hinzufügen";
StartPosition = FormStartPosition.CenterParent;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;
ClientSize = new Size(520, 430);
BackColor = SettingsUi.Background;
ForeColor = SettingsUi.Text;
Font = new Font("Segoe UI", 10f);
Label title = new()
{
Text = "Neues Sonic-System",
Location = new Point(28, 22),
AutoSize = true,
Font = new Font("Segoe UI Semibold", 18f, FontStyle.Bold),
ForeColor = SettingsUi.Text
};
Label subtitle = new()
{
Text =
$"Umgebung {_coordinator.Settings.EnvironmentCode} · " +
"Management-Verbindung für Container-Neustarts",
Location = new Point(30, 58),
AutoSize = true,
ForeColor = SettingsUi.Muted
};
Panel card = SettingsUi.CreateCard();
card.Location = new Point(28, 95);
card.Size = new Size(464, 250);
card.Paint += SettingsUi.PaintCardBorder;
_txtName = SettingsUi.CreateTextBox();
_txtHost = SettingsUi.CreateTextBox();
_txtPort = SettingsUi.CreateTextBox();
_txtDomain = SettingsUi.CreateTextBox();
_cmbProtocol = SettingsUi.CreateComboBox();
_cmbProtocol.Items.AddRange(["tcp", "ssl"]);
_cmbProtocol.SelectedIndex = 0;
_txtPort.Text = "13070";
AddField(card, "Verbindungsname", _txtName, 18, 18, 420);
AddField(card, "Management-Host", _txtHost, 18, 78, 280);
AddField(card, "Port", _txtPort, 316, 78, 122);
AddField(card, "Domain", _txtDomain, 18, 138, 420);
AddField(card, "Protokoll", _cmbProtocol, 18, 198, 160);
_btnSave = SettingsUi.CreatePrimaryButton("System anlegen");
_btnSave.Location = new Point(292, 365);
_btnSave.Size = new Size(200, 40);
_btnSave.Click += async (_, _) => await SaveAsync();
Button cancel = SettingsUi.CreateGhostButton("Abbrechen");
cancel.Location = new Point(170, 365);
cancel.Size = new Size(110, 40);
cancel.Click += (_, _) =>
{
DialogResult = DialogResult.Cancel;
Close();
};
Controls.Add(title);
Controls.Add(subtitle);
Controls.Add(card);
Controls.Add(cancel);
Controls.Add(_btnSave);
AcceptButton = _btnSave;
CancelButton = cancel;
}
private async Task SaveAsync()
{
if (_running)
{
return;
}
if (!int.TryParse(_txtPort.Text.Trim(), out int port))
{
MessageBox.Show(
this,
"Bitte einen gültigen Port eingeben.",
"Sonic-System",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
_running = true;
_btnSave.Enabled = false;
Cursor = Cursors.WaitCursor;
try
{
CreatedSonicConnectionId =
await _coordinator.AddSonicConnectionAsync(
_txtName.Text,
_txtHost.Text,
port,
_txtDomain.Text,
_cmbProtocol.SelectedItem?.ToString() ?? "tcp");
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(
this,
ex.Message,
"Sonic-System",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
_running = false;
_btnSave.Enabled = true;
Cursor = Cursors.Default;
}
}
private static void AddField(
Control parent,
string label,
Control input,
int x,
int y,
int width)
{
Label fieldLabel = SettingsUi.CreateFieldLabel(label);
fieldLabel.Location = new Point(x, y);
input.Location = new Point(x, y + 22);
input.Width = width;
parent.Controls.Add(fieldLabel);
parent.Controls.Add(input);
}
}
@@ -0,0 +1,210 @@
using ZA.CoreService.ESBCertificateManager.Models;
namespace ZA.CoreService.ESBCertificateManager.Setup;
public sealed class AddTargetPathForm : Form
{
private readonly SetupCoordinator _coordinator;
private readonly ComboBox _cmbContainer;
private readonly TextBox _txtDirectory;
private readonly TextBox _txtFileName;
private readonly TextBox _txtBackupFolder;
private readonly CheckBox _chkBackup;
private readonly Button _btnSave;
private bool _running;
public int? CreatedCertificateTargetId { get; private set; }
public AddTargetPathForm(
SetupCoordinator coordinator,
int? preferredSonicContainerId = null)
{
_coordinator = coordinator;
Text = "Zertifikat-Pfad hinzufügen";
StartPosition = FormStartPosition.CenterParent;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
ShowInTaskbar = false;
ClientSize = new Size(560, 450);
BackColor = SettingsUi.Background;
ForeColor = SettingsUi.Text;
Font = new Font("Segoe UI", 10f);
Label title = new()
{
Text = "Neuer Zertifikat-Pfad",
Location = new Point(28, 22),
AutoSize = true,
Font = new Font("Segoe UI Semibold", 18f, FontStyle.Bold),
ForeColor = SettingsUi.Text
};
Label subtitle = new()
{
Text =
"Zielverzeichnis und Dateiname für die Zertifikatsablage.",
Location = new Point(30, 58),
AutoSize = true,
ForeColor = SettingsUi.Muted
};
Panel card = SettingsUi.CreateCard();
card.Location = new Point(28, 95);
card.Size = new Size(504, 270);
card.Paint += SettingsUi.PaintCardBorder;
_cmbContainer = SettingsUi.CreateComboBox();
_txtDirectory = SettingsUi.CreateTextBox();
_txtFileName = SettingsUi.CreateTextBox();
_txtBackupFolder = SettingsUi.CreateTextBox();
_txtBackupFolder.Text = "Backup";
_txtFileName.Text = "server.crt";
_chkBackup = new CheckBox
{
Text = "Backup vor dem Überschreiben",
AutoSize = true,
Checked = true,
ForeColor = SettingsUi.Text,
Font = new Font("Segoe UI", 9.5f)
};
AddField(card, "Container", _cmbContainer, 18, 18, 460);
AddField(card, "Zielverzeichnis", _txtDirectory, 18, 78, 460);
AddField(card, "Dateiname", _txtFileName, 18, 138, 220);
AddField(card, "Backup-Ordner", _txtBackupFolder, 258, 138, 220);
_chkBackup.Location = new Point(18, 210);
card.Controls.Add(_chkBackup);
_btnSave = SettingsUi.CreatePrimaryButton("Pfad anlegen");
_btnSave.Location = new Point(312, 385);
_btnSave.Size = new Size(220, 40);
_btnSave.Click += async (_, _) => await SaveAsync();
Button cancel = SettingsUi.CreateGhostButton("Abbrechen");
cancel.Location = new Point(190, 385);
cancel.Size = new Size(110, 40);
cancel.Click += (_, _) =>
{
DialogResult = DialogResult.Cancel;
Close();
};
Controls.Add(title);
Controls.Add(subtitle);
Controls.Add(card);
Controls.Add(cancel);
Controls.Add(_btnSave);
Shown += async (_, _) =>
await LoadContainersAsync(preferredSonicContainerId);
}
private async Task LoadContainersAsync(int? preferredSonicContainerId)
{
try
{
IReadOnlyList<ContainerOption> containers =
await _coordinator.LoadContainersAsync();
_cmbContainer.Items.Clear();
int selected = 0;
for (int index = 0; index < containers.Count; index++)
{
_cmbContainer.Items.Add(containers[index]);
if (preferredSonicContainerId is int id
&& containers[index].SonicContainerId == id)
{
selected = index;
}
}
if (_cmbContainer.Items.Count > 0)
{
_cmbContainer.SelectedIndex = selected;
}
}
catch (Exception ex)
{
MessageBox.Show(
this,
ex.Message,
"Zertifikat-Pfad",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private async Task SaveAsync()
{
if (_running)
{
return;
}
if (_cmbContainer.SelectedItem is not ContainerOption container)
{
MessageBox.Show(
this,
"Bitte einen Container wählen.",
"Zertifikat-Pfad",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return;
}
_running = true;
_btnSave.Enabled = false;
Cursor = Cursors.WaitCursor;
try
{
CreatedCertificateTargetId =
await _coordinator.AddCertificateTargetAsync(
container.SonicContainerId,
_txtDirectory.Text,
_txtFileName.Text,
_chkBackup.Checked,
_txtBackupFolder.Text);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(
this,
ex.Message,
"Zertifikat-Pfad",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
_running = false;
_btnSave.Enabled = true;
Cursor = Cursors.Default;
}
}
private static void AddField(
Control parent,
string label,
Control input,
int x,
int y,
int width)
{
Label fieldLabel = SettingsUi.CreateFieldLabel(label);
fieldLabel.Location = new Point(x, y);
input.Location = new Point(x, y + 22);
input.Width = width;
parent.Controls.Add(fieldLabel);
parent.Controls.Add(input);
}
}
@@ -0,0 +1,156 @@
namespace ZA.CoreService.ESBCertificateManager.Setup;
internal static class SettingsUi
{
public static readonly Color Background =
Color.FromArgb(10, 18, 34);
public static readonly Color Sidebar =
Color.FromArgb(7, 23, 45);
public static readonly Color Card =
Color.FromArgb(16, 38, 65);
public static readonly Color CardHover =
Color.FromArgb(23, 55, 94);
public static readonly Color Border =
Color.FromArgb(36, 74, 117);
public static readonly Color Text =
Color.FromArgb(241, 245, 249);
public static readonly Color Muted =
Color.FromArgb(169, 184, 200);
public static readonly Color Gold =
Color.FromArgb(208, 171, 57);
public static readonly Color Blue =
Color.FromArgb(0, 110, 182);
public static readonly Color Green =
Color.FromArgb(60, 203, 127);
public static readonly Color Red =
Color.FromArgb(239, 106, 106);
public static Button CreatePrimaryButton(string text)
{
Button button = new()
{
Text = text,
BackColor = Gold,
ForeColor = Color.FromArgb(30, 25, 10),
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI Semibold", 9f, FontStyle.Bold),
Cursor = Cursors.Hand,
Height = 38
};
button.FlatAppearance.BorderSize = 0;
button.FlatAppearance.MouseOverBackColor =
Color.FromArgb(226, 196, 93);
return button;
}
public static Button CreateGhostButton(string text)
{
Button button = new()
{
Text = text,
BackColor = Card,
ForeColor = Text,
FlatStyle = FlatStyle.Flat,
Font = new Font("Segoe UI Semibold", 9f, FontStyle.Bold),
Cursor = Cursors.Hand,
Height = 38
};
button.FlatAppearance.BorderColor = Border;
button.FlatAppearance.BorderSize = 1;
button.FlatAppearance.MouseOverBackColor = CardHover;
return button;
}
public static TextBox CreateTextBox()
{
return new TextBox
{
BackColor = Color.FromArgb(12, 28, 48),
ForeColor = Text,
BorderStyle = BorderStyle.FixedSingle,
Font = new Font("Segoe UI", 10f),
Height = 30
};
}
public static ComboBox CreateComboBox()
{
return new ComboBox
{
BackColor = Color.FromArgb(12, 28, 48),
ForeColor = Text,
FlatStyle = FlatStyle.Flat,
DropDownStyle = ComboBoxStyle.DropDownList,
Font = new Font("Segoe UI", 10f),
Height = 30
};
}
public static Label CreateFieldLabel(string text)
{
return new Label
{
Text = text,
AutoSize = true,
ForeColor = Muted,
Font = new Font("Segoe UI Semibold", 8.5f, FontStyle.Bold)
};
}
public static Panel CreateCard()
{
return new Panel
{
BackColor = Card,
Padding = new Padding(18)
};
}
public static ListView CreateListView()
{
ListView list = new()
{
View = View.Details,
FullRowSelect = true,
MultiSelect = false,
HeaderStyle = ColumnHeaderStyle.Nonclickable,
BorderStyle = BorderStyle.FixedSingle,
BackColor = Color.FromArgb(12, 28, 48),
ForeColor = Text,
Font = new Font("Segoe UI", 9.5f),
HideSelection = false
};
return list;
}
public static void PaintCardBorder(
object? sender,
PaintEventArgs e)
{
if (sender is not Control control)
{
return;
}
using Pen pen = new(Border, 1);
Rectangle bounds = control.ClientRectangle;
bounds.Width -= 1;
bounds.Height -= 1;
e.Graphics.DrawRectangle(pen, bounds);
}
}
@@ -325,6 +325,85 @@ public sealed class SetupCoordinator
cancellationToken);
}
public Task<IReadOnlyList<CompanyOption>> LoadCompaniesAsync(
CancellationToken cancellationToken = default)
{
return _setupRepository.GetCompaniesAsync(cancellationToken);
}
public Task<IReadOnlyList<ContainerOption>> LoadContainersAsync(
int? sonicConnectionId = null,
CancellationToken cancellationToken = default)
{
return _setupRepository.GetContainersAsync(
_settings.EnvironmentCode,
sonicConnectionId,
cancellationToken);
}
public Task<IReadOnlyList<CertificateTargetOption>>
LoadCertificateTargetsAsync(
int? sonicContainerId = null,
CancellationToken cancellationToken = default)
{
return _setupRepository.GetCertificateTargetsAsync(
_settings.EnvironmentCode,
sonicContainerId,
cancellationToken);
}
public Task<int> AddSonicConnectionAsync(
string connectionName,
string managementHost,
int managementPort,
string domainName,
string connectionProtocol,
CancellationToken cancellationToken = default)
{
return _setupRepository.AddSonicConnectionAsync(
_settings.EnvironmentCode,
connectionName,
managementHost,
managementPort,
domainName,
connectionProtocol,
cancellationToken);
}
public Task<int> AddSonicContainerAsync(
int companyId,
int sonicConnectionId,
string containerName,
string? containerDisplayName,
int restartTimeoutSeconds,
CancellationToken cancellationToken = default)
{
return _setupRepository.AddSonicContainerAsync(
companyId,
sonicConnectionId,
containerName,
containerDisplayName,
restartTimeoutSeconds,
cancellationToken);
}
public Task<int> AddCertificateTargetAsync(
int sonicContainerId,
string targetDirectory,
string targetFileName,
bool backupEnabled,
string backupDirectoryName,
CancellationToken cancellationToken = default)
{
return _setupRepository.AddCertificateTargetAsync(
sonicContainerId,
targetDirectory,
targetFileName,
backupEnabled,
backupDirectoryName,
cancellationToken);
}
public void SaveSelection(
SonicSystemOption system,
SonicCredentialProfile profile)
File diff suppressed because it is too large Load Diff