Initial commit: EngineeringSync v1.0.0
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>
This commit is contained in:
59
EngineeringSync.TrayApp/Services/ApiClient.cs
Normal file
59
EngineeringSync.TrayApp/Services/ApiClient.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using EngineeringSync.Domain.Entities;
|
||||
|
||||
namespace EngineeringSync.TrayApp.Services;
|
||||
|
||||
public class ApiClient(HttpClient http)
|
||||
{
|
||||
private const string Base = "http://localhost:5050/api";
|
||||
|
||||
public Task<List<ProjectConfig>?> GetProjectsAsync() =>
|
||||
http.GetFromJsonAsync<List<ProjectConfig>>($"{Base}/projects");
|
||||
|
||||
public Task<List<PendingChange>?> GetChangesAsync(Guid projectId) =>
|
||||
http.GetFromJsonAsync<List<PendingChange>>($"{Base}/changes/{projectId}");
|
||||
|
||||
public Task<List<ScanResultDto>?> ScanFoldersAsync(string engineeringPath, string simulationPath, string fileExtensions) =>
|
||||
http.GetFromJsonAsync<List<ScanResultDto>>($"{Base}/projects/scan?engineeringPath={Uri.EscapeDataString(engineeringPath)}&simulationPath={Uri.EscapeDataString(simulationPath)}&fileExtensions={Uri.EscapeDataString(fileExtensions)}");
|
||||
|
||||
public async Task CreateProjectAsync(CreateProjectDto dto)
|
||||
{
|
||||
var resp = await http.PostAsJsonAsync($"{Base}/projects", dto);
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public async Task UpdateProjectAsync(Guid id, UpdateProjectDto dto)
|
||||
{
|
||||
var resp = await http.PutAsJsonAsync($"{Base}/projects/{id}", dto);
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public async Task DeleteProjectAsync(Guid id)
|
||||
{
|
||||
var resp = await http.DeleteAsync($"{Base}/projects/{id}");
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public async Task SyncChangesAsync(List<Guid> ids)
|
||||
{
|
||||
var resp = await http.PostAsJsonAsync($"{Base}/sync", new { ChangeIds = ids });
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
public async Task IgnoreChangesAsync(List<Guid> ids)
|
||||
{
|
||||
var resp = await http.PostAsJsonAsync($"{Base}/ignore", new { ChangeIds = ids });
|
||||
resp.EnsureSuccessStatusCode();
|
||||
}
|
||||
}
|
||||
|
||||
public record CreateProjectDto(string Name, string EngineeringPath, string SimulationPath,
|
||||
string FileExtensions, bool IsActive = true, bool BackupEnabled = true,
|
||||
string? BackupPath = null, int MaxBackupsPerFile = 0);
|
||||
|
||||
public record UpdateProjectDto(string Name, string EngineeringPath, string SimulationPath,
|
||||
string FileExtensions, bool IsActive, bool BackupEnabled = true,
|
||||
string? BackupPath = null, int MaxBackupsPerFile = 0);
|
||||
|
||||
public record ScanResultDto(string RelativePath, string ChangeType, long Size, DateTime LastModified);
|
||||
57
EngineeringSync.TrayApp/Services/SignalRService.cs
Normal file
57
EngineeringSync.TrayApp/Services/SignalRService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using EngineeringSync.Domain.Constants;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
|
||||
namespace EngineeringSync.TrayApp.Services;
|
||||
|
||||
public class SignalRService : IAsyncDisposable
|
||||
{
|
||||
private HubConnection? _connection;
|
||||
|
||||
public event Action<Guid, string, int>? ChangeNotificationReceived;
|
||||
public event Action? ProjectConfigChanged;
|
||||
|
||||
public async Task ConnectAsync(CancellationToken ct = default)
|
||||
{
|
||||
_connection = new HubConnectionBuilder()
|
||||
.WithUrl("http://localhost:5050/notifications")
|
||||
.WithAutomaticReconnect([TimeSpan.Zero, TimeSpan.FromSeconds(2),
|
||||
TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)])
|
||||
.Build();
|
||||
|
||||
// Register handlers on initial connection
|
||||
RegisterHandlers();
|
||||
|
||||
// Re-register handlers when reconnected after disconnection
|
||||
_connection.Reconnected += async (connectionId) =>
|
||||
{
|
||||
RegisterHandlers();
|
||||
await Task.CompletedTask;
|
||||
};
|
||||
|
||||
await _connection.StartAsync(ct);
|
||||
}
|
||||
|
||||
private void RegisterHandlers()
|
||||
{
|
||||
if (_connection is null)
|
||||
return;
|
||||
|
||||
// Remove existing handlers to prevent duplicates
|
||||
_connection.Remove(HubMethodNames.ReceiveChangeNotification);
|
||||
_connection.Remove(HubMethodNames.ProjectConfigChanged);
|
||||
|
||||
// Register handlers
|
||||
_connection.On<Guid, string, int>(HubMethodNames.ReceiveChangeNotification,
|
||||
(projectId, projectName, count) =>
|
||||
ChangeNotificationReceived?.Invoke(projectId, projectName, count));
|
||||
|
||||
_connection.On(HubMethodNames.ProjectConfigChanged,
|
||||
() => ProjectConfigChanged?.Invoke());
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_connection is not null)
|
||||
await _connection.DisposeAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user