From 2e804ff3f8df638aea968b84bd2d0cd53b2f058c Mon Sep 17 00:00:00 2001 From: Wen JY Date: Thu, 12 Oct 2023 14:24:06 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E5=A2=9E=E5=8A=A0.net=20core=20?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ems.CollectService.Console/App.json | 10 ++++ Ems.CollectService.Entity/config/AppConfig.cs | 52 ++++++++++++------- .../SqlSugarHelper.cs | 18 +++---- Ems.CollectService.Timer/DeleteLogFile.cs | 7 ++- .../Ems.CollectService.Timer.csproj | 1 + Ems.CollectService.sln | 6 +++ 6 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 Ems.CollectService.Console/App.json diff --git a/Ems.CollectService.Console/App.json b/Ems.CollectService.Console/App.json new file mode 100644 index 0000000..6674eea --- /dev/null +++ b/Ems.CollectService.Console/App.json @@ -0,0 +1,10 @@ +{ + "SystemConfig": { + "listenerPort": 6001, + "mysqlConnStr": "Data Source=43.143.98.48;Port=3306;Initial Catalog=hw_ems;uid=root; pwd=yq@123456;min pool size=1;SslMode=none;Charset=utf8", + "virtualValue": 109999, + "virtualFlag": "是", + "logFilePath": "/Users/wenxiansheng/Desktop/日常代码/SF.Ems.CollectService/Ems.CollectService.Console/bin/Debug/net7.0/Log", + "deleteLogTimer": 3600000 + } +} \ No newline at end of file diff --git a/Ems.CollectService.Entity/config/AppConfig.cs b/Ems.CollectService.Entity/config/AppConfig.cs index fbad0f2..f8c0170 100644 --- a/Ems.CollectService.Entity/config/AppConfig.cs +++ b/Ems.CollectService.Entity/config/AppConfig.cs @@ -1,9 +1,6 @@ using Ems.CollectService.Common; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; namespace Ems.CollectService.Entity.config { @@ -12,10 +9,6 @@ namespace Ems.CollectService.Entity.config private static readonly Lazy lazy = new Lazy(() => new AppConfig()); - - private static StringChange stringChange = StringChange.Instance; - - public static AppConfig Instance { get @@ -23,18 +16,19 @@ namespace Ems.CollectService.Entity.config return lazy.Value; } } + + private IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory) + .AddJsonFile("App.json").Build(); - private AppConfig() { } + private AppConfig() {} - private static INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/config/App.InI"); /// /// 监听端口 /// public int listenerPort { - get { return stringChange.ParseToInt(iNIFile.IniReadValue("SystemConfig", "listenerPort")); } - set { iNIFile.IniWriteValue("SystemConfig", "listenerPort", value.ToString()); } + get { return _configuration.GetValue("SystemConfig:listenerPort"); } } /// @@ -42,20 +36,42 @@ namespace Ems.CollectService.Entity.config /// public string mysqlStr { - get { return iNIFile.IniReadValue("SystemConfig", "mysqlConnStr"); } - set { iNIFile.IniWriteValue("SystemConfig", "mysqlConnStr", value.ToString()); } + get + { + return _configuration.GetValue("SystemConfig:mysqlConnStr"); + } } + /// + /// 将FFFF虚拟赋值进行过滤 + /// public decimal virtualValue { - get { return Convert.ToDecimal(iNIFile.IniReadValue("SystemConfig", "virtualValue")); } - set { iNIFile.IniWriteValue("SystemConfig", "virtualValue", value.ToString()); } + get { return _configuration.GetValue("SystemConfig:virtualValue"); } } + /// + /// 是否启用FFFF过滤 + /// public bool virtualFlag { - get { return iNIFile.IniReadValue("SystemConfig", "virtualFlag") == "是" ? true : false; } - set { iNIFile.IniWriteValue("SystemConfig", "virtualFlag", value == true ? "是" : "否"); } + get { return _configuration.GetValue("SystemConfig:virtualFlag") == "是" ? true : false;} + } + + /// + /// 日志文件路径 + /// + public string logFilePath + { + get { return _configuration.GetValue("SystemConfig:logFilePath"); } + } + + /// + /// 日志删除周期 + /// + public long deleteLogTimer + { + get { return _configuration.GetValue("SystemConfig:deleteLogTimer"); } } } } diff --git a/Ems.CollectService.SqlSugarCore/SqlSugarHelper.cs b/Ems.CollectService.SqlSugarCore/SqlSugarHelper.cs index 74e6254..b26ee4d 100644 --- a/Ems.CollectService.SqlSugarCore/SqlSugarHelper.cs +++ b/Ems.CollectService.SqlSugarCore/SqlSugarHelper.cs @@ -3,26 +3,22 @@ using SqlSugar; using System; using System.Collections.Generic; using System.Text; +using Microsoft.Extensions.Configuration; namespace Ems.CollectService.SqlSugarCore { public class SqlSugarHelper //不能是泛型类 { - private static INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/config/App.InI"); - - private static string ConnectionString = "Data Source=nyfw-m.db.sfcloud.local;Port=3306;Initial Catalog=sfemsrefactor;uid=highwayiot; pwd=Administrator@;min pool size=1;SslMode=none;Charset=utf8"; - + //private static string ConnectionString = "Data Source=nyfw-m.db.sfcloud.local;Port=3306;Initial Catalog=sfemsrefactor;uid=highwayiot; pwd=Administrator@;min pool size=1;SslMode=none;Charset=utf8"; //private static string ConnectionString = "Data Source=43.143.98.48;Port=3306;Initial Catalog=hw_ems;uid=root; pwd=yq@123456;min pool size=1;SslMode=none;Charset=utf8"; - - //多库情况下使用说明: - //如果是固定多库可以传 new SqlSugarScope(List,db=>{}) 文档:多租户 - //如果是不固定多库 可以看文档Saas分库 - - + + private static IConfiguration _configuration = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory) + .AddJsonFile("App.json").Build(); + //用单例模式 public static SqlSugarScope Db = new SqlSugarScope(new ConnectionConfig() { - ConnectionString = iNIFile.IniReadValue("SystemConfig", "mysqlConnStr"),//连接符字串 + ConnectionString = _configuration.GetValue("SystemConfig:mysqlConnStr"),//连接符字串 DbType = DbType.MySql,//数据库类型 IsAutoCloseConnection = true //不设成true要手动close }, diff --git a/Ems.CollectService.Timer/DeleteLogFile.cs b/Ems.CollectService.Timer/DeleteLogFile.cs index aa3a1cd..a00da1e 100644 --- a/Ems.CollectService.Timer/DeleteLogFile.cs +++ b/Ems.CollectService.Timer/DeleteLogFile.cs @@ -2,6 +2,7 @@ using NLog; using System; using System.IO; +using Ems.CollectService.Entity.config; namespace Ems.CollectService.Timer { @@ -11,7 +12,8 @@ namespace Ems.CollectService.Timer public sealed class DeleteLogFile { private Logger logger = LogManager.GetCurrentClassLogger(); - private System.Timers.Timer timer = new System.Timers.Timer(1000*60*60); + //private System.Timers.Timer timer = new System.Timers.Timer(1000*60*60); + private AppConfig _appConfig = AppConfig.Instance; private static readonly Lazy lazy = new Lazy(() => new DeleteLogFile()); @@ -30,6 +32,7 @@ namespace Ems.CollectService.Timer /// public void DeleteLogFileTimer() { + System.Timers.Timer timer = new System.Timers.Timer(_appConfig.deleteLogTimer); try { if (!timer.Enabled) @@ -56,7 +59,7 @@ namespace Ems.CollectService.Timer { try { - string fileDirect = "C:\\能源项目文件夹\\采集服务\\Log"; + string fileDirect = _appConfig.logFilePath; int saveDay = 1; logger.Info($"定时删除路径:{fileDirect};下超过:{saveDay}天的日志文件夹"); DateTime nowTime = DateTime.Now; diff --git a/Ems.CollectService.Timer/Ems.CollectService.Timer.csproj b/Ems.CollectService.Timer/Ems.CollectService.Timer.csproj index 71f27a2..7f1745f 100644 --- a/Ems.CollectService.Timer/Ems.CollectService.Timer.csproj +++ b/Ems.CollectService.Timer/Ems.CollectService.Timer.csproj @@ -6,6 +6,7 @@ + diff --git a/Ems.CollectService.sln b/Ems.CollectService.sln index 3094926..24104ff 100644 --- a/Ems.CollectService.sln +++ b/Ems.CollectService.sln @@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ems.CollectService.Analysis EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ems.CollectService.Timer", "Ems.CollectService.Timer\Ems.CollectService.Timer.csproj", "{68E1353B-AF61-4DBA-A956-90BA2D8FE8F5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ems.CollectService.Console", "Ems.CollectService.Console\Ems.CollectService.Console.csproj", "{B1F71EE9-86AA-49F1-BBA9-FBD5132B92F6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +59,10 @@ Global {68E1353B-AF61-4DBA-A956-90BA2D8FE8F5}.Debug|Any CPU.Build.0 = Debug|Any CPU {68E1353B-AF61-4DBA-A956-90BA2D8FE8F5}.Release|Any CPU.ActiveCfg = Release|Any CPU {68E1353B-AF61-4DBA-A956-90BA2D8FE8F5}.Release|Any CPU.Build.0 = Release|Any CPU + {B1F71EE9-86AA-49F1-BBA9-FBD5132B92F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B1F71EE9-86AA-49F1-BBA9-FBD5132B92F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1F71EE9-86AA-49F1-BBA9-FBD5132B92F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B1F71EE9-86AA-49F1-BBA9-FBD5132B92F6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE