change - 添加退出事件,退出时断开设备连接

master^2
wenjy 2 weeks ago
parent 54151e8536
commit 9406431c72

@ -1,4 +1,5 @@
using System.Reflection; using System.Net.Sockets;
using System.Reflection;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using NeoSmart.Caching.Sqlite; using NeoSmart.Caching.Sqlite;
@ -11,6 +12,7 @@ using Sln.Imm.Daemon.Model.dto;
using Sln.Imm.Daemon.Opc; using Sln.Imm.Daemon.Opc;
using Sln.Imm.Daemon.Opc.Impl; using Sln.Imm.Daemon.Opc.Impl;
using Sln.Imm.Daemon.Repository; using Sln.Imm.Daemon.Repository;
using Sln.Imm.Daemon.Repository.service;
using Sln.Imm.Daemon.Serilog; using Sln.Imm.Daemon.Serilog;
using ZiggyCreatures.Caching.Fusion; using ZiggyCreatures.Caching.Fusion;
using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson; using ZiggyCreatures.Caching.Fusion.Serialization.NewtonsoftJson;
@ -32,13 +34,25 @@ namespace Sln.Imm.Daemon
var log = ServiceProvider.GetService<SerilogHelper>(); var log = ServiceProvider.GetService<SerilogHelper>();
log.Info($"系统启动成功,日志存放位置:{appConfig.logPath}"); log.Info($"系统启动成功,日志存放位置:{appConfig.logPath}");
//IOpcService _opcService = ServiceProvider.GetService<OpcUaService>(); AppDomain.CurrentDomain.ProcessExit += async (sender, e) =>
//var res = await _opcService.ConnectAsync("opc.tcp://10.10.63.102:4842"); {
log.Info("进程退出事件触发");
// 执行清理操作
var _dicts = ServiceProvider.GetService<Dictionary<BaseDeviceInfo, IOpcService>>();
foreach (var (item, opc) in _dicts)
{
await opc.DisconnectAsync();
log.Info($"{item.deviceName}断开连接");
}
};
var deviceCollectionBusiness = ServiceProvider.GetService<DeviceCollectionBusiness>(); var deviceCollectionBusiness = ServiceProvider.GetService<DeviceCollectionBusiness>();
deviceCollectionBusiness?.Handle(); deviceCollectionBusiness?.Handle();
//List<IOpcService> opcs = ServiceProvider.GetService<List<IOpcService>>(); //List<IOpcService> opcs = ServiceProvider.GetService<List<IOpcService>>();
//if( opcs != null ) //if( opcs != null )
@ -62,7 +76,7 @@ namespace Sln.Imm.Daemon
// } // }
//} //}
Task.Delay(-1).Wait(); Task.Delay(-1).Wait();
} }

@ -1,6 +1,6 @@
{ {
"AppConfig": { "AppConfig": {
"logPath": "/Users/wenxiansheng/Public/WorkSpace/Mesnac/项目资料/澳柯玛注塑车间MES项目/日志信息", "logPath": "F:/桌面/缓存文件/日志信息",
"SqlConfig": [ "SqlConfig": [
{ {
"configId": "mes", "configId": "mes",

Loading…
Cancel
Save