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) {