Updated DBSyncWatcher

Changed delegate to pass string instead of object.
Now instead of attempting to deserialize the data in DBSyncWatcher,
deserialization happens in th Syncer class.
This commit is contained in:
Mario Steele 2025-07-24 04:24:45 -05:00
parent 5675ea116d
commit b2b4eeff05

View file

@ -10,7 +10,7 @@ public class DBSyncWatcher
private FileSystemWatcher _watcher;
public Dictionary<string, Type> WatchFiles { get; set; } = [];
public delegate void DatabaseChange(string db, object value);
public delegate void DatabaseChange(string db, string value);
public event DatabaseChange OnDatabaseChange;
public DBSyncWatcher(string path)
@ -43,9 +43,7 @@ public class DBSyncWatcher
{
if (line == "") continue;
var type = WatchFiles[dbName];
var item = JsonSerializer.Deserialize(line, type);
if (item == null) continue;
OnDatabaseChange?.Invoke(dbName, item);
OnDatabaseChange?.Invoke(dbName, line);
}
}
@ -58,9 +56,7 @@ public class DBSyncWatcher
foreach (var line in data.Split('\n'))
{
var type = WatchFiles[dbName];
var item = JsonSerializer.Deserialize(line, type);
if (item == null) continue;
OnDatabaseChange?.Invoke(dbName, item);
OnDatabaseChange?.Invoke(dbName, line);
}
}