194 lines
7.9 KiB
C#
194 lines
7.9 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace BizTalkCheckmkPulse.Setup
|
|
{
|
|
internal sealed class MainForm : Form
|
|
{
|
|
private readonly InstallerEngine engine;
|
|
private readonly TextBox account = new TextBox();
|
|
private readonly TextBox password = new TextBox();
|
|
private readonly ComboBox environment = new ComboBox();
|
|
private readonly CheckBox gmsa = new CheckBox();
|
|
private readonly CheckBox allowServiceNameChange = new CheckBox();
|
|
private readonly Button install = new Button();
|
|
private readonly Button uninstall = new Button();
|
|
private readonly TextBox status = new TextBox();
|
|
|
|
public MainForm(InstallerEngine engine)
|
|
{
|
|
this.engine = engine;
|
|
Text = "BizTalk Checkmk Pulse Setup";
|
|
ClientSize = new Size(650, 535);
|
|
MinimumSize = new Size(666, 574);
|
|
StartPosition = FormStartPosition.CenterScreen;
|
|
Font = new Font("Segoe UI", 9F);
|
|
|
|
var title = new Label
|
|
{
|
|
AutoSize = true,
|
|
Font = new Font(Font.FontFamily, 15F, FontStyle.Bold),
|
|
Location = new Point(20, 18),
|
|
Text = "BizTalk Checkmk Pulse installieren"
|
|
};
|
|
var description = new Label
|
|
{
|
|
AutoSize = false,
|
|
Location = new Point(22, 58),
|
|
Size = new Size(605, 48),
|
|
Text = "Installiert Anwendung, Checkmk Local Check, sichere Verzeichnisrechte und den minuetlichen Scheduled Task. PowerShell wird nicht verwendet."
|
|
};
|
|
|
|
AddLabel("Collector-Konto", 22, 120);
|
|
account.Location = new Point(190, 116);
|
|
account.Size = new Size(420, 23);
|
|
account.Text = @"BEW\t231bizmon";
|
|
|
|
AddLabel("Kennwort", 22, 158);
|
|
password.Location = new Point(190, 154);
|
|
password.Size = new Size(420, 23);
|
|
password.UseSystemPasswordChar = true;
|
|
|
|
AddLabel("Umgebung", 22, 196);
|
|
environment.Location = new Point(190, 192);
|
|
environment.Size = new Size(160, 23);
|
|
environment.DropDownStyle = ComboBoxStyle.DropDownList;
|
|
environment.Items.AddRange(new object[] { "(keine)", "ACC", "DEV", "TST", "PRD" });
|
|
var installedEnvironment = engine.GetInstalledEnvironment();
|
|
var installedIndex = environment.Items.IndexOf(installedEnvironment);
|
|
environment.SelectedIndex = installedIndex >= 0 ? installedIndex : 0;
|
|
|
|
gmsa.Location = new Point(190, 229);
|
|
gmsa.Size = new Size(420, 24);
|
|
gmsa.Text = "Konto ist ein gMSA (kein Kennwort erforderlich)";
|
|
gmsa.CheckedChanged += delegate
|
|
{
|
|
password.Enabled = !gmsa.Checked;
|
|
if (gmsa.Checked) password.Clear();
|
|
};
|
|
|
|
allowServiceNameChange.Location = new Point(190, 262);
|
|
allowServiceNameChange.Size = new Size(420, 34);
|
|
allowServiceNameChange.Text = "Service-Rename ist beabsichtigt; Checkmk Service Discovery ist eingeplant";
|
|
allowServiceNameChange.Enabled = engine.IsInstalled;
|
|
|
|
install.Location = new Point(190, 306);
|
|
install.Size = new Size(200, 34);
|
|
install.Text = "Installieren / aktualisieren";
|
|
install.Click += async delegate { await InstallAsync(); };
|
|
|
|
uninstall.Location = new Point(410, 306);
|
|
uninstall.Size = new Size(200, 34);
|
|
uninstall.Text = "Deinstallieren";
|
|
uninstall.Click += async delegate { await UninstallAsync(); };
|
|
|
|
status.Location = new Point(22, 359);
|
|
status.Size = new Size(588, 146);
|
|
status.Multiline = true;
|
|
status.ReadOnly = true;
|
|
status.ScrollBars = ScrollBars.Vertical;
|
|
status.Text = engine.IsInstalled
|
|
? "Bestehende Installation erkannt. Update behaelt Runtime-Daten und vorhandene Konfigurationswerte bei; Konto und Kennwort werden fuer den Scheduled Task neu bestaetigt."
|
|
: "Bereit. Setup.exe muss aus dem vollstaendig entpackten Installationspaket gestartet werden.";
|
|
|
|
Controls.AddRange(new Control[]
|
|
{
|
|
title, description, account, password, environment, gmsa, allowServiceNameChange, install, uninstall, status
|
|
});
|
|
AcceptButton = install;
|
|
}
|
|
|
|
private void AddLabel(string text, int left, int top)
|
|
{
|
|
Controls.Add(new Label { AutoSize = true, Location = new Point(left, top), Text = text });
|
|
}
|
|
|
|
private async Task InstallAsync()
|
|
{
|
|
var collectorAccount = account.Text.Trim();
|
|
var collectorPassword = password.Text;
|
|
var environmentName = environment.SelectedIndex <= 0 ? string.Empty : environment.SelectedItem.ToString();
|
|
var collectorIsGmsa = gmsa.Checked;
|
|
|
|
SetBusy(true, "Installation laeuft ...");
|
|
try
|
|
{
|
|
await Task.Run(() => engine.Install(
|
|
collectorAccount,
|
|
collectorPassword,
|
|
collectorIsGmsa,
|
|
environmentName,
|
|
allowServiceNameChange.Checked,
|
|
Report));
|
|
password.Clear();
|
|
Report("Installation abgeschlossen. Der Provider-Task wurde einmalig gestartet.");
|
|
MessageBox.Show(this, "Installation erfolgreich abgeschlossen.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
password.Clear();
|
|
Report("FEHLER: " + ex.Message);
|
|
MessageBox.Show(this, ex.Message, "Installation fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
finally
|
|
{
|
|
SetBusy(false, null);
|
|
}
|
|
}
|
|
|
|
private async Task UninstallAsync()
|
|
{
|
|
var result = MessageBox.Show(
|
|
this,
|
|
"Scheduled Task, Checkmk-Wrapper und Programmdateien entfernen? Snapshot und Logs bleiben erhalten.",
|
|
"Deinstallation bestaetigen",
|
|
MessageBoxButtons.YesNo,
|
|
MessageBoxIcon.Warning);
|
|
if (result != DialogResult.Yes) return;
|
|
|
|
SetBusy(true, "Deinstallation laeuft ...");
|
|
try
|
|
{
|
|
await Task.Run(() => engine.Uninstall(true, Report));
|
|
Report("Deinstallation abgeschlossen. Runtime-Daten wurden beibehalten.");
|
|
MessageBox.Show(this, "Deinstallation erfolgreich abgeschlossen.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Report("FEHLER: " + ex.Message);
|
|
MessageBox.Show(this, ex.Message, "Deinstallation fehlgeschlagen", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
finally
|
|
{
|
|
SetBusy(false, null);
|
|
}
|
|
}
|
|
|
|
private void SetBusy(bool busy, string message)
|
|
{
|
|
install.Enabled = !busy;
|
|
uninstall.Enabled = !busy;
|
|
account.Enabled = !busy;
|
|
environment.Enabled = !busy;
|
|
gmsa.Enabled = !busy;
|
|
allowServiceNameChange.Enabled = !busy && engine.IsInstalled;
|
|
password.Enabled = !busy && !gmsa.Checked;
|
|
UseWaitCursor = busy;
|
|
if (message != null) Report(message);
|
|
}
|
|
|
|
private void Report(string message)
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
BeginInvoke(new Action<string>(Report), message);
|
|
return;
|
|
}
|
|
|
|
status.AppendText(Environment.NewLine + DateTime.Now.ToString("HH:mm:ss") + " " + message);
|
|
}
|
|
}
|
|
}
|