103 lines
3.2 KiB
C#
103 lines
3.2 KiB
C#
|
|
using System.Windows;
|
||
|
|
using System.Windows.Media;
|
||
|
|
using EngineeringSync.Setup.Services;
|
||
|
|
using EngineeringSync.Setup.ViewModels;
|
||
|
|
|
||
|
|
namespace EngineeringSync.Setup.Views.Pages;
|
||
|
|
|
||
|
|
public partial class InstallingPage : WizardPageBase
|
||
|
|
{
|
||
|
|
private readonly InstallerService _installer;
|
||
|
|
private bool _started;
|
||
|
|
|
||
|
|
public InstallingPage(WizardViewModel wizard, InstallerService installer) : base(wizard)
|
||
|
|
{
|
||
|
|
_installer = installer;
|
||
|
|
InitializeComponent();
|
||
|
|
}
|
||
|
|
|
||
|
|
private async void Page_Loaded(object sender, RoutedEventArgs e)
|
||
|
|
{
|
||
|
|
// Nur einmal starten (Page kann bei Navigation neu erzeugt werden)
|
||
|
|
if (_started) return;
|
||
|
|
_started = true;
|
||
|
|
|
||
|
|
_installer.Progress += OnProgress;
|
||
|
|
_installer.LogMessage += OnLogMessage;
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
// Button während Installation deaktivieren
|
||
|
|
Wizard.SetInstallingState(true);
|
||
|
|
|
||
|
|
await _installer.InstallAsync();
|
||
|
|
ShowSuccess();
|
||
|
|
|
||
|
|
// Buttons wieder aktivieren vor Navigation
|
||
|
|
Wizard.SetInstallingState(false);
|
||
|
|
Wizard.NavigateTo(7); // → CompletionPage
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
ShowError(ex.Message);
|
||
|
|
// Buttons wieder aktivieren im Fehlerfall
|
||
|
|
Wizard.SetInstallingState(false);
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
_installer.Progress -= OnProgress;
|
||
|
|
_installer.LogMessage -= OnLogMessage;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnProgress(int percent, string step)
|
||
|
|
{
|
||
|
|
Dispatcher.Invoke(() =>
|
||
|
|
{
|
||
|
|
ProgressBar.Value = percent;
|
||
|
|
ProgressText.Text = $"{percent}%";
|
||
|
|
StepText.Text = step;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnLogMessage(string message)
|
||
|
|
{
|
||
|
|
Dispatcher.Invoke(() =>
|
||
|
|
{
|
||
|
|
var ts = DateTime.Now.ToString("HH:mm:ss");
|
||
|
|
LogText.Text += $"[{ts}] {message}\n";
|
||
|
|
LogScrollViewer.ScrollToEnd();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
private void ShowSuccess()
|
||
|
|
{
|
||
|
|
Dispatcher.Invoke(() =>
|
||
|
|
{
|
||
|
|
ResultBanner.Background = new SolidColorBrush(Color.FromRgb(232, 245, 233));
|
||
|
|
ResultIcon.Text = "\uE73E";
|
||
|
|
ResultIcon.Foreground = new SolidColorBrush(Color.FromRgb(16, 124, 16));
|
||
|
|
ResultText.Text = "Installation erfolgreich abgeschlossen.";
|
||
|
|
ResultText.Foreground = new SolidColorBrush(Color.FromRgb(16, 124, 16));
|
||
|
|
ResultBanner.Visibility = Visibility.Visible;
|
||
|
|
SubtitleText.Text = "Alle Komponenten wurden erfolgreich installiert.";
|
||
|
|
ProgressBar.Value = 100;
|
||
|
|
ProgressText.Text = "100%";
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
private void ShowError(string message)
|
||
|
|
{
|
||
|
|
Dispatcher.Invoke(() =>
|
||
|
|
{
|
||
|
|
ResultBanner.Background = new SolidColorBrush(Color.FromRgb(255, 235, 238));
|
||
|
|
ResultIcon.Text = "\uE783";
|
||
|
|
ResultIcon.Foreground = new SolidColorBrush(Color.FromRgb(196, 43, 28));
|
||
|
|
ResultText.Text = $"Fehler: {message}";
|
||
|
|
ResultText.Foreground = new SolidColorBrush(Color.FromRgb(196, 43, 28));
|
||
|
|
ResultBanner.Visibility = Visibility.Visible;
|
||
|
|
SubtitleText.Text = "Die Installation konnte nicht abgeschlossen werden.";
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|