Add PowerShell-free Windows installer
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
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 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, 485);
|
||||
MinimumSize = new Size(666, 524);
|
||||
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" });
|
||||
environment.SelectedIndex = 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();
|
||||
};
|
||||
|
||||
install.Location = new Point(190, 267);
|
||||
install.Size = new Size(200, 34);
|
||||
install.Text = "Installieren / aktualisieren";
|
||||
install.Click += async delegate { await InstallAsync(); };
|
||||
|
||||
uninstall.Location = new Point(410, 267);
|
||||
uninstall.Size = new Size(200, 34);
|
||||
uninstall.Text = "Deinstallieren";
|
||||
uninstall.Click += async delegate { await UninstallAsync(); };
|
||||
|
||||
status.Location = new Point(22, 320);
|
||||
status.Size = new Size(588, 135);
|
||||
status.Multiline = true;
|
||||
status.ReadOnly = true;
|
||||
status.ScrollBars = ScrollBars.Vertical;
|
||||
status.Text = "Bereit. Setup.exe muss aus dem vollstaendig entpackten Installationspaket gestartet werden.";
|
||||
|
||||
Controls.AddRange(new Control[]
|
||||
{
|
||||
title, description, account, password, environment, gmsa, 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,
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user