Vollständige Implementierung des EngineeringSync-Middleware-Tools: - Windows Service (Kestrel :5050) mit FileSystemWatcher + SignalR - WPF Tray-App mit PendingChanges- und Projektverwaltungs-Fenster - Setup-Wizard (8-Schritte-Installer) - SQLite/EF Core Datenschicht (WAL-Modus) - SHA-256-basiertes Debouncing (2s Fenster) - Backup-System mit konfigurierbarer Aufbewahrung Bugfixes & Verbesserungen: - BUG-1: AppDbContext OnConfiguring invertierte Bedingung behoben - BUG-2: Event-Handler-Leak in TrayApp (Fenster-Singleton-Pattern) - BUG-3: ProjectConfigChanged SignalR-Signal in allen CRUD-Endpoints - BUG-5: Rename-Sync löscht alte Datei im Simulations-Ordner - BUG-6: Doppeltes Dispose von SignalR verhindert - BUG-7: Registry-Deinstallation nur EngineeringSync-Eintrag entfernt - S1: Path-Traversal-Schutz via SafeCombine() im SyncManager - E1: FSW Buffer 64KB + automatischer Re-Scan bei Overflow - E2: Retry-Logik (3x) für gesperrte Dateien mit exponentiellem Backoff - E4: Channel.Writer.TryComplete() beim Shutdown - C2: HubMethodNames-Konstanten statt Magic Strings - E3: Pagination in Changes-API (page/pageSize Query-Parameter) - A1: Fire-and-Forget mit try/catch + Logging Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
184 lines
6.5 KiB
C#
184 lines
6.5 KiB
C#
using System.Collections.ObjectModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using EngineeringSync.Domain.Entities;
|
|
using EngineeringSync.TrayApp.Services;
|
|
|
|
namespace EngineeringSync.TrayApp.ViewModels;
|
|
|
|
public partial class ProjectManagementViewModel(ApiClient api) : ObservableObject
|
|
{
|
|
[ObservableProperty] private ObservableCollection<ProjectConfig> _projects = [];
|
|
[ObservableProperty] private ProjectConfig? _selectedProject;
|
|
[ObservableProperty] private bool _isEditing;
|
|
[ObservableProperty] private string _editName = string.Empty;
|
|
[ObservableProperty] private string _editEngineeringPath = string.Empty;
|
|
[ObservableProperty] private string _editSimulationPath = string.Empty;
|
|
[ObservableProperty] private string _editFileExtensions = ".jt,.cojt,.xml";
|
|
[ObservableProperty] private bool _editIsActive = true;
|
|
[ObservableProperty] private bool _editBackupEnabled = true;
|
|
[ObservableProperty] private bool _editBackupUseCustomPath = false;
|
|
[ObservableProperty] private string _editBackupCustomPath = string.Empty;
|
|
[ObservableProperty] private int _editMaxBackupsPerFile = 0;
|
|
[ObservableProperty] private bool _isNewProject;
|
|
[ObservableProperty] private string _statusMessage = string.Empty;
|
|
[ObservableProperty] private string _scanStatus = string.Empty;
|
|
[ObservableProperty] private ObservableCollection<ScanResultDto> _scanResults = [];
|
|
public bool HasScanResults => ScanResults.Count > 0;
|
|
|
|
[RelayCommand]
|
|
public async Task LoadAsync()
|
|
{
|
|
var projects = await api.GetProjectsAsync() ?? [];
|
|
Projects = new ObservableCollection<ProjectConfig>(projects);
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void StartNewProject()
|
|
{
|
|
SelectedProject = null;
|
|
IsNewProject = true;
|
|
IsEditing = true;
|
|
EditName = string.Empty;
|
|
EditEngineeringPath = string.Empty;
|
|
EditSimulationPath = string.Empty;
|
|
EditFileExtensions = ".jt,.cojt,.xml";
|
|
EditIsActive = true;
|
|
EditBackupEnabled = true;
|
|
EditBackupUseCustomPath = false;
|
|
EditBackupCustomPath = string.Empty;
|
|
EditMaxBackupsPerFile = 0;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void EditProject(ProjectConfig? project)
|
|
{
|
|
if (project is null)
|
|
{
|
|
System.Windows.MessageBox.Show(
|
|
"Bitte zuerst ein Projekt auswählen.",
|
|
"EngineeringSync",
|
|
System.Windows.MessageBoxButton.OK,
|
|
System.Windows.MessageBoxImage.Information);
|
|
return;
|
|
}
|
|
SelectedProject = project;
|
|
IsNewProject = false;
|
|
IsEditing = true;
|
|
EditName = project.Name;
|
|
EditEngineeringPath = project.EngineeringPath;
|
|
EditSimulationPath = project.SimulationPath;
|
|
EditFileExtensions = project.FileExtensions;
|
|
EditIsActive = project.IsActive;
|
|
EditBackupEnabled = project.BackupEnabled;
|
|
EditBackupUseCustomPath = project.BackupPath is not null;
|
|
EditBackupCustomPath = project.BackupPath ?? string.Empty;
|
|
EditMaxBackupsPerFile = project.MaxBackupsPerFile;
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task SaveAsync()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(EditName))
|
|
{
|
|
StatusMessage = "Name darf nicht leer sein.";
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
if (IsNewProject)
|
|
await api.CreateProjectAsync(new CreateProjectDto(
|
|
EditName, EditEngineeringPath, EditSimulationPath, EditFileExtensions, EditIsActive,
|
|
EditBackupEnabled,
|
|
EditBackupUseCustomPath ? EditBackupCustomPath : null,
|
|
EditMaxBackupsPerFile));
|
|
else
|
|
await api.UpdateProjectAsync(SelectedProject!.Id, new UpdateProjectDto(
|
|
EditName, EditEngineeringPath, EditSimulationPath, EditFileExtensions, EditIsActive,
|
|
EditBackupEnabled,
|
|
EditBackupUseCustomPath ? EditBackupCustomPath : null,
|
|
EditMaxBackupsPerFile));
|
|
|
|
IsEditing = false;
|
|
await LoadAsync();
|
|
StatusMessage = IsNewProject ? "Projekt erstellt." : "Projekt aktualisiert.";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"[TrayApp] Save Fehler: {ex}");
|
|
StatusMessage = $"Fehler: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void Cancel() => IsEditing = false;
|
|
|
|
[RelayCommand]
|
|
public async Task DeleteAsync(ProjectConfig? project)
|
|
{
|
|
if (project is null)
|
|
{
|
|
System.Windows.MessageBox.Show(
|
|
"Bitte zuerst ein Projekt auswählen.",
|
|
"EngineeringSync",
|
|
System.Windows.MessageBoxButton.OK,
|
|
System.Windows.MessageBoxImage.Information);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
await api.DeleteProjectAsync(project.Id);
|
|
await LoadAsync();
|
|
StatusMessage = "Projekt gelöscht.";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine($"[TrayApp] Save Fehler: {ex}");
|
|
StatusMessage = $"Fehler: {ex.Message}";
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
public async Task ScanFoldersAsync()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(EditEngineeringPath) || string.IsNullOrWhiteSpace(EditSimulationPath))
|
|
{
|
|
ScanStatus = "Bitte beide Ordnerpfade angeben.";
|
|
return;
|
|
}
|
|
|
|
if (!System.IO.Directory.Exists(EditEngineeringPath))
|
|
{
|
|
ScanStatus = $"Engineering-Ordner existiert nicht: {EditEngineeringPath}";
|
|
return;
|
|
}
|
|
if (!System.IO.Directory.Exists(EditSimulationPath))
|
|
{
|
|
ScanStatus = $"Simulations-Ordner existiert nicht: {EditSimulationPath}";
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
ScanStatus = "Wird gescannt...";
|
|
ScanResults.Clear();
|
|
|
|
var results = await api.ScanFoldersAsync(EditEngineeringPath, EditSimulationPath, EditFileExtensions);
|
|
if (results is null || results.Count == 0)
|
|
{
|
|
ScanStatus = "Keine Unterschiede gefunden - Ordner sind synchron.";
|
|
}
|
|
else
|
|
{
|
|
ScanStatus = $"{results.Count} Unterschied(e) gefunden:";
|
|
foreach (var r in results)
|
|
ScanResults.Add(r);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ScanStatus = $"Scan-Fehler: {ex.Message}";
|
|
}
|
|
}
|
|
}
|