From 03ca1b5e4589481564ce20a5d138ad6329c2c010 Mon Sep 17 00:00:00 2001 From: liushoushan_notebook Date: Sat, 23 Jul 2022 08:44:35 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E7=9B=AE=E5=BD=95=E5=92=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E4=BC=98=E5=85=88=E4=BB=8E=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E4=B8=AD=E8=8E=B7=E5=8F=96=EF=BC=88?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=B8=8D=E5=AD=98=E5=9C=A8=EF=BC=8C=E5=88=99?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8E=9F=E6=9C=89=E7=9A=84=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=89=E3=80=82=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=90=8D=E7=A7=B0=E5=A6=82=E4=B8=8B=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IoTGateway_DB IoTGateway_DBType IOT_DriverPath --- Plugins/Plugin/DrvierService.cs | 6 ++++- Plugins/Plugin/IoTBackgroundService.cs | 32 ++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Plugins/Plugin/DrvierService.cs b/Plugins/Plugin/DrvierService.cs index a1db1b8..9a87bb6 100644 --- a/Plugins/Plugin/DrvierService.cs +++ b/Plugins/Plugin/DrvierService.cs @@ -26,7 +26,11 @@ namespace Plugin _logger = logger; try { - _logger.LogInformation("LoadDriverFiles Start"); + var env_DriverPath = Environment.GetEnvironmentVariable("IOT_DriverPath"); + if (!string.IsNullOrEmpty(env_DriverPath) && Directory.Exists(env_DriverPath)) + DriverPath = env_DriverPath; + + _logger.LogInformation($"LoadDriverFiles Start,Path:{DriverPath}"); driverFiles = Directory.GetFiles(DriverPath).Where(x => Path.GetExtension(x) == ".dll").ToArray(); _logger.LogInformation($"LoadDriverFiles End,Count{driverFiles.Count()}"); } diff --git a/Plugins/Plugin/IoTBackgroundService.cs b/Plugins/Plugin/IoTBackgroundService.cs index 6cc9c58..e8e6fe4 100644 --- a/Plugins/Plugin/IoTBackgroundService.cs +++ b/Plugins/Plugin/IoTBackgroundService.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; @@ -12,35 +13,52 @@ namespace Plugin { public class IoTBackgroundService : BackgroundService { + private readonly ILogger _logger; public static DBTypeEnum DBType; public static string connnectSetting; public static Guid? VariableSelectDeviceId, ConfigSelectDeviceId; - public IoTBackgroundService(IConfiguration ConfigRoot) + public IoTBackgroundService(IConfiguration ConfigRoot, ILogger logger) { + _logger= logger; var connnectSettings = new List(); ConfigRoot.Bind("Connections", connnectSettings); connnectSetting = connnectSettings[0].Value; + DBType = GetDBType(connnectSettings[0].DBType); + //read from Environment + var IoTGateway_DB = Environment.GetEnvironmentVariable("IoTGateway_DB"); + var IoTGateway_DBType = Environment.GetEnvironmentVariable("IoTGateway_DBType"); + if (!string.IsNullOrEmpty(IoTGateway_DB) && !string.IsNullOrEmpty(IoTGateway_DBType)) + { + connnectSetting = IoTGateway_DB; + DBType = GetDBType(IoTGateway_DBType); + } + _logger.LogInformation($"IoTBackgroundService connnectSetting:{connnectSetting},DBType:{DBType}"); + } - switch (connnectSettings[0].DBType.Trim().ToLower()) + private DBTypeEnum GetDBType(string dbtypeStr) + { + DBTypeEnum dbType = DBTypeEnum.SQLite; + switch (dbtypeStr.Trim().ToLower()) { case "oracle": - DBType = DBTypeEnum.Oracle; + dbType = DBTypeEnum.Oracle; break; case "mysql": - DBType = DBTypeEnum.MySql; + dbType = DBTypeEnum.MySql; break; case "pgsql": - DBType = DBTypeEnum.PgSql; + dbType = DBTypeEnum.PgSql; break; case "sqlite": - DBType = DBTypeEnum.SQLite; + dbType = DBTypeEnum.SQLite; break; case "memory": - DBType = DBTypeEnum.Memory; + dbType = DBTypeEnum.Memory; break; default: break; } + return dbType; } protected override Task ExecuteAsync(CancellationToken stoppingToken) {