[#60] SyncService: Do not use App.Config inside service

This commit is contained in:
lorenz.stechauner committed 2026-11-26 17:06:56 +01:00
1 parent cc6da2f257
commit f1eb26d01d
4 files changed
+19 -19

No files matched your search

+1 -1
View File
@@ -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 () => {
+1 -1
View File
@@ -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 () => {
+10 -10
View File
@@ -18,7 +18,7 @@ namespace Elwig.Services {
public static readonly Expression<Func<AreaCmtContract, bool>> ChangedAreaCmtContracts = (c) => ((c.XTime == null && c.MTime > 1751328000) || c.MTime > c.XTime) && (c.ITime == null || c.MTime > c.ITime);
public static readonly Expression<Func<Delivery, bool>> 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<char> password, IQueryable<Member> query, IEnumerable<string> filterNames) {
public static async Task Upload(string url, string username, ReadOnlyMemory<char> password, IQueryable<Member> query, IEnumerable<string> filterNames, ReadOnlyMemory<char> 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<char> password, IQueryable<DeliveryPart> query, IEnumerable<string> filterNames) {
public static async Task Upload(string url, string username, ReadOnlyMemory<char> password, IQueryable<DeliveryPart> query, IEnumerable<string> filterNames, ReadOnlyMemory<char> 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<char> password) {
public static async Task UploadModified(string url, string username, ReadOnlyMemory<char> password, ReadOnlyMemory<char> key = default) {
try {
var path = Path.Combine(App.TempPath, $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}_{App.ZwstId}.elwig.zip");
List<Member> 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<char> password, int? year = null) {
public static async Task UploadBranchDeliveries(string url, string username, ReadOnlyMemory<char> password, int? year = null, ReadOnlyMemory<char> 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<char> password, bool confirmImports) {
public static async Task Download(string url, string username, ReadOnlyMemory<char> password, bool confirmImports, IEnumerable<ReadOnlyMemory<char>>? keys = null) {
try {
var import = await GetFilesToImport(url, username, password);
var paths = new List<string>();
@@ -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) {
+7 -7
View File
@@ -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;
}