Skip to content

Commit

Permalink
read json file from connection string
Browse files Browse the repository at this point in the history
  • Loading branch information
trembon committed Dec 16, 2024
1 parent 87a6bff commit b4d245b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions HomeAutomation.Core/Services/JsonDatabaseService.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -35,14 +36,15 @@ 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();

private FileSystemWatcher configurationWatcher;

private MemoryEntities memoryEntities;

public MemoryEntities MemoryEntities
{
get
Expand Down Expand Up @@ -70,8 +72,9 @@ public MemoryEntities MemoryEntities

public IEnumerable<DeviceTrigger> StateTriggers => MemoryEntities.Triggers.OfType<DeviceTrigger>();

public JsonDatabaseService()
public JsonDatabaseService(IConfiguration configuration)
{
DATABASE_FILE = configuration.GetConnectionString("Json") ?? DATABASE_FILE;
}

public void Initialize()
Expand Down Expand Up @@ -140,4 +143,4 @@ private void LoadConfiguration()
}
}
}
}
}

0 comments on commit b4d245b

Please sign in to comment.