From bf1b890449701c9a46026dc01dc007d8271a07cd Mon Sep 17 00:00:00 2001 From: Thomas Schissler Date: Tue, 3 Oct 2023 22:17:20 +0200 Subject: [PATCH] Reading service endpoingts from env variables --- Shared.Contracts/Configuration/Common.cs | 1 + Smarthome.Web/Pages/Charge.razor | 8 ++++---- Smarthome.Web/Pages/ConsumptionM1.razor | 2 ++ Smarthome.Web/Pages/Index.razor | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Shared.Contracts/Configuration/Common.cs b/Shared.Contracts/Configuration/Common.cs index b0ae80e..adbd043 100644 --- a/Shared.Contracts/Configuration/Common.cs +++ b/Shared.Contracts/Configuration/Common.cs @@ -11,6 +11,7 @@ public class Common { public static string SyncfusionLicenseKey { get; set; } public static string PVServiceUrl { get; set; } + public static string ChargingServiceUrl { get; set; } static Common() { diff --git a/Smarthome.Web/Pages/Charge.razor b/Smarthome.Web/Pages/Charge.razor index 0b14025..c911fab 100644 --- a/Smarthome.Web/Pages/Charge.razor +++ b/Smarthome.Web/Pages/Charge.razor @@ -109,9 +109,9 @@ public ChargingDataPoints ChargingDataPoints = new ChargingDataPoints(); - private Timer refreshTimer; private ChargingSettingsData settings = new(); + private string chargingServiceEndpoint = $"{SharedContracts.Configuration.Common.ChargingServiceUrl}"; protected override void OnInitialized() { @@ -133,7 +133,7 @@ // minimumPVShare = ChargingControlDataPoints.MinimumPVShare.CurrentValue, // manualCurrency = ChargingControlDataPoints.ManualChargingCurrency.CurrentValue // }; - Http.PostAsJsonAsync("http://localhost:5004/applychargingsettings", settings); + Http.PostAsJsonAsync($"{chargingServiceEndpoint}/applychargingsettings", settings); } private void Refresh(object? state) @@ -144,7 +144,7 @@ { using (HttpClient Http = new HttpClient()) { - var jsonString = Http.GetStringAsync("http://localhost:5004/readchargingsettings").Result; + var jsonString = Http.GetStringAsync($"{chargingServiceEndpoint}/readchargingsettings").Result; settings = JsonConvert.DeserializeObject(jsonString); settings.isInitialized = true; } @@ -159,7 +159,7 @@ { using (HttpClient Http = new HttpClient()) { - var jsonString = Http.GetStringAsync("http://localhost:5004/readdata").Result; + var jsonString = Http.GetStringAsync($"{chargingServiceEndpoint}/readdata").Result; ChargingDataPoints = JsonConvert.DeserializeObject(jsonString); InvokeAsync(StateHasChanged); } diff --git a/Smarthome.Web/Pages/ConsumptionM1.razor b/Smarthome.Web/Pages/ConsumptionM1.razor index 6a89bff..7e53c05 100644 --- a/Smarthome.Web/Pages/ConsumptionM1.razor +++ b/Smarthome.Web/Pages/ConsumptionM1.razor @@ -90,6 +90,8 @@ { private Timer refreshTimer; private ConsumptionDataPoints dataPoints = new(); + private string pvServiceEndpoint = $"{SharedContracts.Configuration.Common.PVServiceUrl}/readSensorsdata"; + private string chargingServiceEndpoint = $"{SharedContracts.Configuration.Common.ChargingServiceUrl}/readdata"; public HistoryChartDataSeries PowerDevice1Data; public HistoryChartDataSeries PowerDevice2Data; diff --git a/Smarthome.Web/Pages/Index.razor b/Smarthome.Web/Pages/Index.razor index 1eb0bee..9b546dc 100644 --- a/Smarthome.Web/Pages/Index.razor +++ b/Smarthome.Web/Pages/Index.razor @@ -74,6 +74,7 @@ private Timer refreshTimer; private string pvServiceEndpoint = $"{SharedContracts.Configuration.Common.PVServiceUrl}/readSensorsdata"; + private string chargingServiceEndpoint = $"{SharedContracts.Configuration.Common.ChargingServiceUrl}/readdata"; public HistoryChartDataSeries PVProduction; public HistoryChartDataSeries GridSupply; @@ -110,7 +111,7 @@ { using (HttpClient Http = new HttpClient()) { - var jsonString = Http.GetStringAsync("http://localhost:5004/readdata").Result; + var jsonString = Http.GetStringAsync(chargingServiceEndpoint).Result; ChargingDataPoints = JsonConvert.DeserializeObject(jsonString); Cleanup(ChargingDataPoints.CurrentChargingPower); }