From b4d245b62e743445452be7c3c129f9d7e3e49326 Mon Sep 17 00:00:00 2001 From: trembon Date: Mon, 16 Dec 2024 18:27:11 +0100 Subject: [PATCH] read json file from connection string --- HomeAutomation.Core/Services/JsonDatabaseService.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/HomeAutomation.Core/Services/JsonDatabaseService.cs b/HomeAutomation.Core/Services/JsonDatabaseService.cs index 484f8a8..5d33ae8 100644 --- a/HomeAutomation.Core/Services/JsonDatabaseService.cs +++ b/HomeAutomation.Core/Services/JsonDatabaseService.cs @@ -1,6 +1,7 @@ using HomeAutomation.Entities; using HomeAutomation.Entities.Devices; using HomeAutomation.Entities.Triggers; +using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System.Text; @@ -35,7 +36,7 @@ public interface IJsonDatabaseService public class JsonDatabaseService : IJsonDatabaseService { - private const string DATABASE_FILE = "database.json"; + private string DATABASE_FILE = "database.json"; private static readonly object readMemoryEntitiesLock = new(); private static readonly object writeMemoryEntitiesLock = new(); @@ -43,6 +44,7 @@ public class JsonDatabaseService : IJsonDatabaseService private FileSystemWatcher configurationWatcher; private MemoryEntities memoryEntities; + public MemoryEntities MemoryEntities { get @@ -70,8 +72,9 @@ public MemoryEntities MemoryEntities public IEnumerable StateTriggers => MemoryEntities.Triggers.OfType(); - public JsonDatabaseService() + public JsonDatabaseService(IConfiguration configuration) { + DATABASE_FILE = configuration.GetConnectionString("Json") ?? DATABASE_FILE; } public void Initialize() @@ -140,4 +143,4 @@ private void LoadConfiguration() } } } -} +} \ No newline at end of file