2
0

Export Library and notification connectors on deletion

Added logging
This commit is contained in:
glax 2023-09-20 14:11:31 +02:00
parent b3b1971dad
commit 4e5a6fe97b

View File

@ -54,11 +54,12 @@ public abstract class GlobalBase
protected void AddNotificationConnector(NotificationConnector notificationConnector) protected void AddNotificationConnector(NotificationConnector notificationConnector)
{ {
Log($"Adding {notificationConnector}"); Log($"Adding {notificationConnector}");
notificationConnectors.RemoveWhere(nc => nc.GetType() == notificationConnector.GetType()); notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == notificationConnector.notificationConnectorType);
notificationConnectors.Add(notificationConnector); notificationConnectors.Add(notificationConnector);
while(IsFileInUse(settings.notificationConnectorsFilePath)) while(IsFileInUse(settings.notificationConnectorsFilePath))
Thread.Sleep(100); Thread.Sleep(100);
Log("Exporting notificationConnectors");
File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors)); File.WriteAllText(settings.notificationConnectorsFilePath, JsonConvert.SerializeObject(notificationConnectors));
} }
@ -66,6 +67,10 @@ public abstract class GlobalBase
{ {
Log($"Removing {notificationConnectorType}"); Log($"Removing {notificationConnectorType}");
notificationConnectors.RemoveWhere(nc => nc.notificationConnectorType == 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() protected void UpdateLibraries()
@ -77,11 +82,12 @@ public abstract class GlobalBase
protected void AddLibraryConnector(LibraryConnector libraryConnector) protected void AddLibraryConnector(LibraryConnector libraryConnector)
{ {
Log($"Adding {libraryConnector}"); Log($"Adding {libraryConnector}");
libraryConnectors.RemoveWhere(lc => lc.GetType() == libraryConnector.GetType()); libraryConnectors.RemoveWhere(lc => lc.libraryType == libraryConnector.libraryType);
libraryConnectors.Add(libraryConnector); libraryConnectors.Add(libraryConnector);
while(IsFileInUse(settings.libraryConnectorsFilePath)) while(IsFileInUse(settings.libraryConnectorsFilePath))
Thread.Sleep(100); Thread.Sleep(100);
Log("Exporting libraryConnectors");
File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors)); File.WriteAllText(settings.libraryConnectorsFilePath, JsonConvert.SerializeObject(libraryConnectors));
} }
@ -89,6 +95,10 @@ public abstract class GlobalBase
{ {
Log($"Removing {libraryType}"); Log($"Removing {libraryType}");
libraryConnectors.RemoveWhere(lc => lc.libraryType == 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) protected bool IsFileInUse(string filePath)