diff --git a/.vs/hass-workstation-service/v16/.suo b/.vs/hass-workstation-service/v16/.suo index 2f5456d..cf4766f 100644 Binary files a/.vs/hass-workstation-service/v16/.suo and b/.vs/hass-workstation-service/v16/.suo differ diff --git a/hass-workstation-service/Data/ConfigurationService.cs b/hass-workstation-service/Data/ConfigurationService.cs index a8130c4..b352d6a 100644 --- a/hass-workstation-service/Data/ConfigurationService.cs +++ b/hass-workstation-service/Data/ConfigurationService.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.IsolatedStorage; using System.Linq; using System.Security; using System.Text.Json; @@ -27,23 +26,21 @@ namespace hass_workstation_service.Data public bool _brokerSettingsFileLocked { get; set; } public bool _sensorsSettingsFileLocked { get; set; } - private readonly IsolatedStorageFile _fileStorage; + private readonly string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hass Workstation Service"); public ConfigurationService() { - this._fileStorage = IsolatedStorageFile.GetUserStoreForApplication(); - - ConfiguredSensors = new List(); - - if (!this._fileStorage.FileExists("mqttbroker.json")) + if (!File.Exists(Path.Combine(path, "mqttbroker.json"))) { - this._fileStorage.CreateFile("mqttbroker.json"); + File.Create(Path.Combine(path, "mqttbroker.json")); } - if (!this._fileStorage.FileExists("configured-sensors.json")) + if (!File.Exists(Path.Combine(path, "configured-sensors.json"))) { - this._fileStorage.CreateFile("configured-sensors.json"); + File.Create(Path.Combine(path, "configured-sensors.json")); } + + ConfiguredSensors = new List(); } public async void ReadSensorSettings(MqttPublisher publisher) @@ -54,7 +51,7 @@ namespace hass_workstation_service.Data } this._sensorsSettingsFileLocked = true; List sensors = new List(); - using (var stream = this._fileStorage.OpenFile("configured-sensors.json", FileMode.Open)) + using (var stream = new FileStream(Path.Combine(path, "configured-sensors.json"), FileMode.Open)) { Log.Logger.Information($"reading configured sensors from: {stream.Name}"); if (stream.Length > 0) @@ -134,7 +131,7 @@ namespace hass_workstation_service.Data } this._brokerSettingsFileLocked = true; ConfiguredMqttBroker configuredBroker = null; - using (IsolatedStorageFileStream stream = this._fileStorage.OpenFile("mqttbroker.json", FileMode.Open)) + using (FileStream stream = new FileStream(Path.Combine(path, "mqttbroker.json"), FileMode.Open)) { Log.Logger.Information($"reading configured mqttbroker from: {stream.Name}"); if (stream.Length > 0) @@ -156,7 +153,7 @@ namespace hass_workstation_service.Data } this._sensorsSettingsFileLocked = true; List configuredSensorsToSave = new List(); - using (IsolatedStorageFileStream stream = this._fileStorage.OpenFile("configured-sensors.json", FileMode.Open)) + using (FileStream stream = new FileStream(Path.Combine(path, "configured-sensors.json"), FileMode.Open)) { stream.SetLength(0); Log.Logger.Information($"writing configured sensors to: {stream.Name}"); @@ -171,7 +168,7 @@ namespace hass_workstation_service.Data { configuredSensorsToSave.Add(new ConfiguredSensor() { Id = sensor.Id, Name = sensor.Name, Type = sensor.GetType().Name, UpdateInterval = sensor.UpdateInterval }); } - + } await JsonSerializer.SerializeAsync(stream, configuredSensorsToSave); @@ -220,7 +217,7 @@ namespace hass_workstation_service.Data await Task.Delay(500); } this._brokerSettingsFileLocked = true; - using (IsolatedStorageFileStream stream = this._fileStorage.OpenFile("mqttbroker.json", FileMode.Open)) + using (FileStream stream = new FileStream(Path.Combine(path, "mqttbroker.json"), FileMode.Open)) { stream.SetLength(0); Log.Logger.Information($"writing configured mqttbroker to: {stream.Name}"); diff --git a/hass-workstation-service/Program.cs b/hass-workstation-service/Program.cs index 8ee7285..3be2fbb 100644 --- a/hass-workstation-service/Program.cs +++ b/hass-workstation-service/Program.cs @@ -26,10 +26,15 @@ namespace hass_workstation_service { public static async Task Main(string[] args) { + string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hass Workstation Service", "logs"); + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() - .WriteTo.File(new RenderedCompactJsonFormatter(), "logs/log.ndjson") + .WriteTo.File(new RenderedCompactJsonFormatter(), Path.Combine(path, "log.txt"), rollingInterval: RollingInterval.Day) .CreateLogger(); // We do it this way because there is currently no way to pass an argument to a dotnet core app when using clickonce if (Process.GetProcessesByName("hass-workstation-service").Count() > 1) //bg service running diff --git a/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml b/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml index 0f34205..35da0ec 100644 --- a/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml +++ b/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - 23 + 25 1.0.0.* True Release diff --git a/hass-workstation-service/UserInterface.exe b/hass-workstation-service/UserInterface.exe index be08cbb..86049d1 100644 Binary files a/hass-workstation-service/UserInterface.exe and b/hass-workstation-service/UserInterface.exe differ