From 7bd702f207188941c3c0d2a8a7db85137151ae36 Mon Sep 17 00:00:00 2001 From: Matt Kniller Date: Wed, 15 Apr 2020 22:52:34 -0400 Subject: [PATCH] Changed how the path of the appseting settings file is determined. --- .gitignore | 2 ++ .../ExtraLifeStreamLabelService.cs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 876d9e4..85475c0 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ obj/ *.sqlite-journal *.v2 +*.pubxml +*.user diff --git a/WJS.ExtraLifeStreamLabelsCore/WJS.ExtraLifeStreamLabelsService/ExtraLifeStreamLabelService.cs b/WJS.ExtraLifeStreamLabelsCore/WJS.ExtraLifeStreamLabelsService/ExtraLifeStreamLabelService.cs index 5ec9be0..32cc2aa 100644 --- a/WJS.ExtraLifeStreamLabelsCore/WJS.ExtraLifeStreamLabelsService/ExtraLifeStreamLabelService.cs +++ b/WJS.ExtraLifeStreamLabelsCore/WJS.ExtraLifeStreamLabelsService/ExtraLifeStreamLabelService.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Net.Http; +using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -26,10 +27,21 @@ public class ExtraLifeStreamLabelService : BackgroundService private static ParticipantDataModel _previousParticipantData; private static IConfigurationRoot _config; + private static string GetAssemblyDirectory + { + get + { + string codeBase = Assembly.GetExecutingAssembly().CodeBase; + UriBuilder uri = new UriBuilder(codeBase); + string path = Uri.UnescapeDataString(uri.Path); + return Path.GetDirectoryName(path); + } + } + public ExtraLifeStreamLabelService(ILogger logger) { _logger = logger; - var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json"); + var builder = new ConfigurationBuilder().SetBasePath(GetAssemblyDirectory).AddJsonFile("appsettings.json"); _config = builder.Build(); _participantEndpoint = $"participants/{_config.GetSection("ExtraLifeData").Get().ParticipantId}"; @@ -37,7 +49,6 @@ public ExtraLifeStreamLabelService(ILogger logger) _donationsEndpoint = $"{_participantEndpoint}/donations"; _teamEndpoint = $"teams/{_config.GetSection("ExtraLifeData").Get().TeamId}"; _previousParticipantData = new ParticipantDataModel(); - } protected override async Task ExecuteAsync(CancellationToken stoppingToken)