From 4e5a6fe97b779dc4af68e82bf0214dd549666e25 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 20 Sep 2023 14:11:31 +0200 Subject: [PATCH] Export Library and notification connectors on deletion Added logging --- Tranga/GlobalBase.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Tranga/GlobalBase.cs b/Tranga/GlobalBase.cs index 89e66f0..bdc104e 100644 --- a/Tranga/GlobalBase.cs +++ b/Tranga/GlobalBase.cs @@ -54,11 +54,12 @@ public abstract class GlobalBase protected void AddNotificationConnector(NotificationConnector notificationConnector) { Log($"Adding {notificationConnector}"); - notificationConnectors.RemoveWhere(nc => nc.GetType() == notificationConnector.GetType()); + notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnector.notificationConnectorType); notificationConnectors.Add(notificationConnector); while(IsFileInUse(settings.notificationConnectorsFilePath)) Thread.Sleep(100); + Log("Exporting notificationConnectors"); File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors)); } @@ -66,6 +67,10 @@ public abstract class GlobalBase { Log($"Removing {notificationConnectorType}"); notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnectorType); + while(IsFileInUse(settings.notificationConnectorsFilePath)) + Thread.Sleep(100); + Log("Exporting notificationConnectors"); + File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors)); } protected void UpdateLibraries() @@ -77,11 +82,12 @@ public abstract class GlobalBase protected void AddLibraryConnector(LibraryConnector libraryConnector) { Log($"Adding {libraryConnector}"); - libraryConnectors.RemoveWhere(lc => lc.GetType() == libraryConnector.GetType()); + libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryConnector.libraryType); libraryConnectors.Add(libraryConnector); while(IsFileInUse(settings.libraryConnectorsFilePath)) Thread.Sleep(100); + Log("Exporting libraryConnectors"); File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors)); } @@ -89,6 +95,10 @@ public abstract class GlobalBase { Log($"Removing {libraryType}"); libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryType); + while(IsFileInUse(settings.libraryConnectorsFilePath)) + Thread.Sleep(100); + Log("Exporting libraryConnectors"); + File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors)); } protected bool IsFileInUse(string filePath)