From b97828ca6a6452e71884bfd6c26fe945fc6fdfb6 Mon Sep 17 00:00:00 2001 From: "jay.chang" Date: Fri, 25 Oct 2024 17:47:38 +0800 Subject: [PATCH] =?UTF-8?q?[BGService][WebApi]=E5=B0=87obix=E5=B8=B3?= =?UTF-8?q?=E5=AF=86=E5=AF=AB=E6=AD=BB=E7=9A=84=E5=9C=B0=E6=96=B9=E6=94=B9?= =?UTF-8?q?=E6=88=90DB=E6=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Quartz/Jobs/EmergencyRecordJob.cs | 7 +++++-- BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs | 7 +++++-- FrontendWebApi/ApiControllers/AlarmController.cs | 6 ++++-- .../ApiControllers/WarningValueController.cs | 13 +++++++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/BackendWorkerService/Quartz/Jobs/EmergencyRecordJob.cs b/BackendWorkerService/Quartz/Jobs/EmergencyRecordJob.cs index b06eb72..cc12895 100644 --- a/BackendWorkerService/Quartz/Jobs/EmergencyRecordJob.cs +++ b/BackendWorkerService/Quartz/Jobs/EmergencyRecordJob.cs @@ -1,6 +1,7 @@ using FrontendWebApi.Models; using Microsoft.Extensions.Logging; using Quartz; +using Repository.BackendRepository.Implement; using Repository.BackendRepository.Interface; using System; using System.Collections.Generic; @@ -52,8 +53,10 @@ namespace BackendWorkerService.Quartz.Jobs using (HttpClient client = new HttpClient()) { - string username = "stanGG"; - string password = "St12345678"; + var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; + var variableObix = backendRepository.GetAllAsync(sqlObix).Result; + string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); + string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); diff --git a/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs b/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs index d49c272..c230c8f 100644 --- a/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs +++ b/BackendWorkerService/Quartz/Jobs/WeatherAPIJob.cs @@ -42,8 +42,11 @@ namespace BackendWorkerService.Quartz.Jobs { try { - string username = "stanGG"; - string password = "St12345678"; + var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; + + var variableObix = backgroundServiceRepository.GetAllAsync(sqlObix).Result; + string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); + string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create(url); Postrequest.Method = "POST"; diff --git a/FrontendWebApi/ApiControllers/AlarmController.cs b/FrontendWebApi/ApiControllers/AlarmController.cs index 170053a..4a6c11c 100644 --- a/FrontendWebApi/ApiControllers/AlarmController.cs +++ b/FrontendWebApi/ApiControllers/AlarmController.cs @@ -61,8 +61,10 @@ namespace FrontendWebApi.ApiControllers using (HttpClient client = new HttpClient()) { - string username = "stanGG"; - string password = "St12345678"; + var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; + var variableObix = frontendRepository.GetAllAsync(sqlObix).Result; + string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); + string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); diff --git a/FrontendWebApi/ApiControllers/WarningValueController.cs b/FrontendWebApi/ApiControllers/WarningValueController.cs index 54111b9..e243490 100644 --- a/FrontendWebApi/ApiControllers/WarningValueController.cs +++ b/FrontendWebApi/ApiControllers/WarningValueController.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using Repository.BackendRepository.Implement; +using Repository.BackendRepository.Interface; using Repository.FrontendRepository.Interface; using System; using System.Collections.Generic; @@ -82,8 +83,10 @@ namespace FrontendWebApi.ApiControllers using (HttpClient client = new HttpClient()) { apiUrl = Path.Combine(baseApiUrl, "obix/config/", apiUrl); - string username = "stanGG"; - string password = "St12345678"; + var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; + var variableObix = frontendRepository.GetAllAsync(sqlObix).Result; + string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); + string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded); @@ -165,8 +168,10 @@ namespace FrontendWebApi.ApiControllers using (HttpClient client = new HttpClient()) { apiUrl = Path.Combine(baseApiUrl, "obix/config/", apiUrl); - string username = "stanGG"; - string password = "St12345678"; + var sqlObix = $@"SELECT system_value as Value, system_key as Name FROM variable WHERE deleted = 0 AND system_type = 'obixConfig'"; + var variableObix = frontendRepository.GetAllAsync(sqlObix).Result; + string username = variableObix.Where(x => x.Name == "UserName").Select(x => x.Value).FirstOrDefault(); + string password = variableObix.Where(x => x.Name == "Password").Select(x => x.Value).FirstOrDefault(); string encoded = Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)); client.DefaultRequestHeaders.Add("Authorization", "Basic " + encoded);