diff --git a/Elwig/Services/DeliveryService.cs b/Elwig/Services/DeliveryService.cs index 64feb66..69bc62e 100644 --- a/Elwig/Services/DeliveryService.cs +++ b/Elwig/Services/DeliveryService.cs @@ -833,7 +833,7 @@ namespace Elwig.Services { } } else if (mode == ExportMode.Upload && App.Config.SyncUrl != null) { await Utils.RunForeground(async () => { - await SyncService.Upload(App.Config.SyncUrl, App.Config.SyncUrl, App.Config.SyncPassword, query, filterNames); + await SyncService.Upload(App.Config.SyncUrl, App.Config.SyncUrl, App.Config.SyncPassword, query, filterNames, App.Config.SyncEncryptionKey); }); } else { await Utils.RunForeground(async () => { diff --git a/Elwig/Services/MemberService.cs b/Elwig/Services/MemberService.cs index 415abfc..470c3ba 100644 --- a/Elwig/Services/MemberService.cs +++ b/Elwig/Services/MemberService.cs @@ -599,7 +599,7 @@ namespace Elwig.Services { } } else if (mode == ExportMode.Upload && App.Config.SyncUrl != null) { await Utils.RunForeground(async () => { - await SyncService.Upload(App.Config.SyncUrl, App.Config.SyncUrl, App.Config.SyncPassword, query, filterNames); + await SyncService.Upload(App.Config.SyncUrl, App.Config.SyncUrl, App.Config.SyncPassword, query, filterNames, App.Config.SyncEncryptionKey); }); } else { await Utils.RunForeground(async () => { diff --git a/Elwig/Services/SyncService.cs b/Elwig/Services/SyncService.cs index ec57089..df28661 100644 --- a/Elwig/Services/SyncService.cs +++ b/Elwig/Services/SyncService.cs @@ -18,7 +18,7 @@ namespace Elwig.Services { public static readonly Expression> ChangedAreaCmtContracts = (c) => ((c.XTime == null && c.MTime > 1751328000) || c.MTime > c.XTime) && (c.ITime == null || c.MTime > c.ITime); public static readonly Expression> ChangedDeliveries = (d) => ((d.XTime == null && d.MTime > 1751328000) || d.MTime > d.XTime) && (d.ITime == null || d.MTime > d.ITime); - public static async Task Upload(string url, string username, ReadOnlyMemory password, IQueryable query, IEnumerable filterNames) { + public static async Task Upload(string url, string username, ReadOnlyMemory password, IQueryable query, IEnumerable filterNames, ReadOnlyMemory key = default) { try { var filename = $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip"; var path = Path.Combine(App.TempPath, filename); @@ -54,7 +54,7 @@ namespace Elwig.Services { InteractionService.ShowError("Mitglieder hochladen", "Es wurden keine Mitglieder zum Hochladen ausgewählt!"); } else { var exportedAt = DateTime.Now; - await ElwigData.Export(path, members, history, areaCmts, wbKgs, filterNames, App.Config.SyncEncryptionKey); + await ElwigData.Export(path, members, history, areaCmts, wbKgs, filterNames, key); await Utils.UploadExportData(path, url, username, password); await UpdateExportedAt(members, areaCmts, [], exportedAt); InteractionService.ShowInformation("Mitglieder hochgeladen", $"Hochladen von {members.Count:N0} Mitgliedern erfolgreich!"); @@ -68,7 +68,7 @@ namespace Elwig.Services { } } - public static async Task Upload(string url, string username, ReadOnlyMemory password, IQueryable query, IEnumerable filterNames) { + public static async Task Upload(string url, string username, ReadOnlyMemory password, IQueryable query, IEnumerable filterNames, ReadOnlyMemory key = default) { try { var filename = $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip"; var path = Path.Combine(App.TempPath, filename); @@ -88,7 +88,7 @@ namespace Elwig.Services { InteractionService.ShowError("Lieferungen hochladen", "Es wurden keine Lieferungen zum Hochladen ausgewählt!"); } else { var exportedAt = DateTime.Now; - await ElwigData.Export(path, list, wbKgs, filterNames, App.Config.SyncEncryptionKey); + await ElwigData.Export(path, list, wbKgs, filterNames, key); await Utils.UploadExportData(path, url, username, password); await UpdateExportedAt([], [], list, exportedAt); InteractionService.ShowInformation("Lieferungen hochgeladen", $"Hochladen von {list.Count:N0} Lieferungen erfolgreich!"); @@ -102,7 +102,7 @@ namespace Elwig.Services { } } - public static async Task UploadModified(string url, string username, ReadOnlyMemory password) { + public static async Task UploadModified(string url, string username, ReadOnlyMemory password, ReadOnlyMemory key = default) { try { var path = Path.Combine(App.TempPath, $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip"); List members; @@ -145,7 +145,7 @@ namespace Elwig.Services { AreaCmts = (areaCmts, ["geändert seit letztem Export"]), Deliveries = (deliveries, ["geändert seit letzem Export"]), WbKgs = (wbKgs, ["von exportierten Mitgliedern, Flächenbindungen und Lieferungen"]), - }).Export(path, App.Config.SyncEncryptionKey); + }).Export(path, key); await Utils.UploadExportData(path, url, username, password); await UpdateExportedAt(members, areaCmts, deliveries, exportedAt); InteractionService.ShowInformation("Mitglieder und Lieferungen hochladen", $"Hochladen von {members.Count:N0} Mitgliedern, {areaCmts.Count:N0} Flächenbindungsverträgen, und {deliveries.Count:N0} Lieferungen erfolgreich!"); @@ -159,7 +159,7 @@ namespace Elwig.Services { } } - public static async Task UploadBranchDeliveries(string url, string username, ReadOnlyMemory password, int? year = null) { + public static async Task UploadBranchDeliveries(string url, string username, ReadOnlyMemory password, int? year = null, ReadOnlyMemory key = default) { try { year ??= Utils.CurrentLastSeason; var path = Path.Combine(App.TempPath, $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip"); @@ -179,7 +179,7 @@ namespace Elwig.Services { InteractionService.ShowError("Lieferungen hochladen", "Es gibt keine Lieferungen, die hochgeladen werden können!"); } else { var exportedAt = DateTime.Now; - await ElwigData.Export(path, deliveries, wbKgs, [$"{year}", $"Zweigstelle {App.BranchName}"], App.Config.SyncEncryptionKey); + await ElwigData.Export(path, deliveries, wbKgs, [$"{year}", $"Zweigstelle {App.BranchName}"], key); await Utils.UploadExportData(path, url, username, password); await UpdateExportedAt([], [], deliveries, exportedAt); InteractionService.ShowInformation("Lieferungen hochladen", $"Hochladen von {deliveries.Count:N0} Lieferungen erfolgreich!"); @@ -214,7 +214,7 @@ namespace Elwig.Services { ]; } - public static async Task Download(string url, string username, ReadOnlyMemory password, bool confirmImports) { + public static async Task Download(string url, string username, ReadOnlyMemory password, bool confirmImports, IEnumerable>? keys = null) { try { var import = await GetFilesToImport(url, username, password); var paths = new List(); @@ -226,7 +226,7 @@ namespace Elwig.Services { paths.Add(filename); } } - await ElwigData.Import(paths, confirmImports ? ElwigData.ImportMode.Interactively : ElwigData.ImportMode.FromBranches, App.Config.SyncDecryptionKeys); + await ElwigData.Import(paths, confirmImports ? ElwigData.ImportMode.Interactively : ElwigData.ImportMode.FromBranches, keys); } catch (HttpRequestException exc) { InteractionService.ShowException("Daten herunterladen", "Eventuell Internetverbindung prüfen!", exc); } catch (TaskCanceledException exc) { diff --git a/Elwig/Windows/MainWindow.xaml.cs b/Elwig/Windows/MainWindow.xaml.cs index 2da82be..53079b1 100644 --- a/Elwig/Windows/MainWindow.xaml.cs +++ b/Elwig/Windows/MainWindow.xaml.cs @@ -187,11 +187,11 @@ namespace Elwig.Windows { Mouse.OverrideCursor = Cursors.Wait; await Task.Run(async () => { if (App.Config.SyncMain) { - await SyncService.Download(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, true); - await SyncService.UploadModified(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword); + await SyncService.Download(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, true, App.Config.SyncDecryptionKeys); + await SyncService.UploadModified(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, App.Config.SyncEncryptionKey); } else { - await SyncService.Download(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, false); - await SyncService.UploadBranchDeliveries(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword); + await SyncService.Download(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, false, App.Config.SyncDecryptionKeys); + await SyncService.UploadBranchDeliveries(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, key: App.Config.SyncEncryptionKey); } }); Mouse.OverrideCursor = null; @@ -202,7 +202,7 @@ namespace Elwig.Windows { return; Mouse.OverrideCursor = Cursors.Wait; await Task.Run(async () => { - await SyncService.Download(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, App.Config.SyncMain); + await SyncService.Download(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, App.Config.SyncMain, App.Config.SyncDecryptionKeys); }); Mouse.OverrideCursor = null; } @@ -212,7 +212,7 @@ namespace Elwig.Windows { return; Mouse.OverrideCursor = Cursors.Wait; await Task.Run(async () => { - await SyncService.UploadBranchDeliveries(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword); + await SyncService.UploadBranchDeliveries(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, key: App.Config.SyncEncryptionKey); }); Mouse.OverrideCursor = null; } @@ -226,7 +226,7 @@ namespace Elwig.Windows { } Mouse.OverrideCursor = Cursors.Wait; await Task.Run(async () => { - await SyncService.UploadModified(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword); + await SyncService.UploadModified(App.Config.SyncUrl, App.Config.SyncUsername, App.Config.SyncPassword, App.Config.SyncEncryptionKey); }); Mouse.OverrideCursor = null; }