change - 增加.net core 启动项

master
Wen JY 11 months ago
parent 9afa918010
commit 2e804ff3f8

@ -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
}
}

@ -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<AppConfig> lazy = new Lazy<AppConfig>(() => 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");
/// <summary>
/// 监听端口
/// </summary>
public int listenerPort
{
get { return stringChange.ParseToInt(iNIFile.IniReadValue("SystemConfig", "listenerPort")); }
set { iNIFile.IniWriteValue("SystemConfig", "listenerPort", value.ToString()); }
get { return _configuration.GetValue<int>("SystemConfig:listenerPort"); }
}
/// <summary>
@ -42,20 +36,42 @@ namespace Ems.CollectService.Entity.config
/// </summary>
public string mysqlStr
{
get { return iNIFile.IniReadValue("SystemConfig", "mysqlConnStr"); }
set { iNIFile.IniWriteValue("SystemConfig", "mysqlConnStr", value.ToString()); }
get
{
return _configuration.GetValue<string>("SystemConfig:mysqlConnStr");
}
}
/// <summary>
/// 将FFFF虚拟赋值进行过滤
/// </summary>
public decimal virtualValue
{
get { return Convert.ToDecimal(iNIFile.IniReadValue("SystemConfig", "virtualValue")); }
set { iNIFile.IniWriteValue("SystemConfig", "virtualValue", value.ToString()); }
get { return _configuration.GetValue<decimal>("SystemConfig:virtualValue"); }
}
/// <summary>
/// 是否启用FFFF过滤
/// </summary>
public bool virtualFlag
{
get { return iNIFile.IniReadValue("SystemConfig", "virtualFlag") == "是" ? true : false; }
set { iNIFile.IniWriteValue("SystemConfig", "virtualFlag", value == true ? "是" : "否"); }
get { return _configuration.GetValue<string>("SystemConfig:virtualFlag") == "是" ? true : false;}
}
/// <summary>
/// 日志文件路径
/// </summary>
public string logFilePath
{
get { return _configuration.GetValue<string>("SystemConfig:logFilePath"); }
}
/// <summary>
/// 日志删除周期
/// </summary>
public long deleteLogTimer
{
get { return _configuration.GetValue<long>("SystemConfig:deleteLogTimer"); }
}
}
}

@ -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<ConnectionConfig>,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<string>("SystemConfig:mysqlConnStr"),//连接符字串
DbType = DbType.MySql,//数据库类型
IsAutoCloseConnection = true //不设成true要手动close
},

@ -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<DeleteLogFile> lazy = new Lazy<DeleteLogFile>(() => new DeleteLogFile());
@ -30,6 +32,7 @@ namespace Ems.CollectService.Timer
/// </summary>
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;

@ -6,6 +6,7 @@
<ItemGroup>
<ProjectReference Include="..\Ems.CollectService.Common\Ems.CollectService.Common.csproj" />
<ProjectReference Include="..\Ems.CollectService.Entity\Ems.CollectService.Entity.csproj" />
</ItemGroup>
</Project>

@ -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

Loading…
Cancel
Save