diff --git a/src/Directory.Build.props b/src/Directory.Build.props index dc6a6f675..cfb4dceb5 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,9 +1,9 @@ - 10.11.75 - 10.11.75 - 10.11.75 + 10.11.76 + 10.11.76 + 10.11.76 10.11.6 10.11.6 8.0.20 diff --git a/src/Foundation/ThingsGateway.Foundation/Logger/TextFileLogger.cs b/src/Foundation/ThingsGateway.Foundation/Logger/TextFileLogger.cs index 92e8924a3..22c771747 100644 --- a/src/Foundation/ThingsGateway.Foundation/Logger/TextFileLogger.cs +++ b/src/Foundation/ThingsGateway.Foundation/Logger/TextFileLogger.cs @@ -145,6 +145,7 @@ public class TextFileLogger : ThingsGateway.NewLife.Log.TextFileLog, TouchSocket } WriteLog(logLevel, source, message, exception); } + protected override void Dispose(bool disposing) { cache.Remove(CacheKey); diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Driver/DriverBase.cs b/src/Gateway/ThingsGateway.Gateway.Application/Driver/DriverBase.cs index 2bffa50ff..4f316419d 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Driver/DriverBase.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Driver/DriverBase.cs @@ -378,6 +378,8 @@ public abstract class DriverBase : AsyncDisposableObject, IDriver // 记录设备线程已停止的信息 LogMessage?.LogInformation(string.Format(AppResource.DeviceTaskStop, DeviceName)); + await Task.Delay(1000).ConfigureAwait(false); + // 执行资源释放操作 await this.SafeDisposeAsync().ConfigureAwait(false); diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/Channel/ChannelRuntimeService.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/Channel/ChannelRuntimeService.cs index abd6c8736..0f44019f5 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/Channel/ChannelRuntimeService.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/Channel/ChannelRuntimeService.cs @@ -176,8 +176,8 @@ public class ChannelRuntimeService : IChannelRuntimeService if (restart) { await GlobalData.ChannelThreadManage.RestartChannelAsync(newChannelRuntimes).ConfigureAwait(false); - - await RuntimeServiceHelper.ChangedDriverAsync(_logger).ConfigureAwait(false); + + await RuntimeServiceHelper.ChangedDriverAsync(GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a=> !newDeviceRuntimes.Contains(a)).ToArray(),_logger).ConfigureAwait(false); } return true; @@ -209,7 +209,7 @@ public class ChannelRuntimeService : IChannelRuntimeService { await GlobalData.ChannelThreadManage.RestartChannelAsync(newChannelRuntimes).ConfigureAwait(false); - await RuntimeServiceHelper.ChangedDriverAsync(_logger).ConfigureAwait(false); + await RuntimeServiceHelper.ChangedDriverAsync(GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => !newDeviceRuntimes.Contains(a)).ToArray(),_logger).ConfigureAwait(false); } return true; @@ -241,7 +241,7 @@ public class ChannelRuntimeService : IChannelRuntimeService { await GlobalData.ChannelThreadManage.RestartChannelAsync(newChannelRuntimes).ConfigureAwait(false); - await RuntimeServiceHelper.ChangedDriverAsync(_logger).ConfigureAwait(false); + await RuntimeServiceHelper.ChangedDriverAsync(GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => !newDeviceRuntimes.Contains(a)).ToArray(),_logger).ConfigureAwait(false); } return true; diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/Device/DeviceRuntimeService.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/Device/DeviceRuntimeService.cs index d98400558..4399d3af7 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/Device/DeviceRuntimeService.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/Device/DeviceRuntimeService.cs @@ -205,7 +205,7 @@ public class DeviceRuntimeService : IDeviceRuntimeService if (restart) { await RuntimeServiceHelper.RestartDeviceAsync(newDeviceRuntimes).ConfigureAwait(false); - await RuntimeServiceHelper.ChangedDriverAsync(_logger).ConfigureAwait(false); + await RuntimeServiceHelper.ChangedDriverAsync(GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => !newDeviceRuntimes.Contains(a)).ToArray(),_logger).ConfigureAwait(false); } return true; diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/RuntimeServiceHelper.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/RuntimeServiceHelper.cs index 4fcbf6fa5..b54a7477f 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/RuntimeServiceHelper.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/RuntimeServiceHelper.cs @@ -239,7 +239,7 @@ internal static class RuntimeServiceHelper if (group.Key != null) await group.Key.RestartDeviceAsync(group.Value, false).ConfigureAwait(false); } - foreach (var group in GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => a.Driver?.DeviceThreadManage != null).GroupBy(a => a.Driver.DeviceThreadManage)) + foreach (var group in GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a=>!newDeviceRuntimes.Contains(a)).Where(a => a.Driver?.DeviceThreadManage != null).GroupBy(a => a.Driver.DeviceThreadManage)) { if (group.Key != null) await group.Key.RestartDeviceAsync(group.ToArray(), false).ConfigureAwait(false); @@ -260,7 +260,7 @@ internal static class RuntimeServiceHelper await group.Key.RemoveDeviceAsync(group.Value.Select(a => a.Id).ToArray()).ConfigureAwait(false); } - foreach (var group in GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => a.Driver?.DeviceThreadManage != null).GroupBy(a => a.Driver.DeviceThreadManage)) + foreach (var group in GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => !deviceRuntimes.Contains(a)).Where(a => a.Driver?.DeviceThreadManage != null).GroupBy(a => a.Driver.DeviceThreadManage)) { if (group.Key != null) await group.Key.RestartDeviceAsync(group.ToArray(), false).ConfigureAwait(false); @@ -268,9 +268,9 @@ internal static class RuntimeServiceHelper } - public static async Task ChangedDriverAsync(ILogger logger) + public static async Task ChangedDriverAsync(DeviceRuntime[] channelDevice, ILogger logger) { - var channelDevice = GlobalData.GetAllVariableBusinessDeviceRuntime(); + await channelDevice.ParallelForEachAsync(async (item, token) => { diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/Variable/VariableRuntimeService.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/Variable/VariableRuntimeService.cs index cd264e856..b2c9a70d0 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/Variable/VariableRuntimeService.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/Variable/VariableRuntimeService.cs @@ -398,22 +398,22 @@ public class VariableRuntimeService : IVariableRuntimeService //批量修改之后,需要重新加载通道 RuntimeServiceHelper.Init(newChannelRuntimes); - { - var newDeviceRuntimes = datas.Item2.AdaptListDeviceRuntime(); - RuntimeServiceHelper.Init(newDeviceRuntimes); - } - { - var newVariableRuntimes = datas.Item3.AdaptListVariableRuntime(); - RuntimeServiceHelper.Init(newVariableRuntimes); - } + var newDeviceRuntimes = datas.Item2.AdaptListDeviceRuntime(); + + RuntimeServiceHelper.Init(newDeviceRuntimes); + + + var newVariableRuntimes = datas.Item3.AdaptListVariableRuntime(); + RuntimeServiceHelper.Init(newVariableRuntimes); + //根据条件重启通道线程 if (restart) { await GlobalData.ChannelThreadManage.RestartChannelAsync(newChannelRuntimes).ConfigureAwait(false); - await RuntimeServiceHelper.ChangedDriverAsync(_logger).ConfigureAwait(false); + await RuntimeServiceHelper.ChangedDriverAsync(GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => !newDeviceRuntimes.Contains(a)).ToArray(), _logger).ConfigureAwait(false); } } } @@ -437,22 +437,21 @@ public class VariableRuntimeService : IVariableRuntimeService //批量修改之后,需要重新加载通道 RuntimeServiceHelper.Init(newChannelRuntimes); - { - var newDeviceRuntimes = datas.Item2.AdaptListDeviceRuntime(); - RuntimeServiceHelper.Init(newDeviceRuntimes); - } - { - var newVariableRuntimes = datas.Item3.AdaptListVariableRuntime(); - RuntimeServiceHelper.Init(newVariableRuntimes); - } + var newDeviceRuntimes = datas.Item2.AdaptListDeviceRuntime(); + + RuntimeServiceHelper.Init(newDeviceRuntimes); + + var newVariableRuntimes = datas.Item3.AdaptListVariableRuntime(); + RuntimeServiceHelper.Init(newVariableRuntimes); + //根据条件重启通道线程 if (restart) { await GlobalData.ChannelThreadManage.RestartChannelAsync(newChannelRuntimes).ConfigureAwait(false); - await RuntimeServiceHelper.ChangedDriverAsync(_logger).ConfigureAwait(false); + await RuntimeServiceHelper.ChangedDriverAsync(GlobalData.GetAllVariableBusinessDeviceRuntime().Where(a => !newDeviceRuntimes.Contains(a)).ToArray(), _logger).ConfigureAwait(false); } } }