Compare commits

...

5 Commits

Author SHA1 Message Date
Kimdiego2098
1c52be8b47 添加停止线程等待时间 2023-11-16 22:32:22 +08:00
Kimdiego2098
bcd82055ca s7握手失败后,手动关闭连接 2023-11-11 10:26:05 +08:00
Kimdiego2098
c47d95d170 fix:修复线程阻塞检测触发重启时,后台变量列表不再刷新的问题! 2023-11-10 09:00:50 +08:00
Kimdiego2098
3e62f1ad51 历史数据上传成功后,才上传缓存数据 2023-11-09 18:55:56 +08:00
Kimdiego2098
8dcae973ef update 2023-11-08 16:19:46 +08:00
14 changed files with 85 additions and 119 deletions

View File

@@ -21,7 +21,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="7.0.96" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.WindowsForms" Version="7.0.100" />
</ItemGroup>

View File

@@ -459,6 +459,7 @@ namespace ThingsGateway.Foundation.Adapter.Siemens
if (!result1.IsSuccess)
{
Logger?.Warning($"{client.IP} : {client.Port}ISO_TP握手失败-{result1.Message}");
TcpClient.Close();
return;
}
var result2 = await SendThenResponseAsync(S7_PN);

View File

@@ -1,47 +0,0 @@
#region copyright
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
// 使用文档https://diego2098.gitee.io/thingsgateway-docs/
// QQ群605534569
//------------------------------------------------------------------------------
#endregion
//------------------------------------------------------------------------------
// 此代码版权除特别声明或在XREF结尾的命名空间的代码归作者本人若汝棋茗所有
// 源代码使用协议遵循本仓库的开源协议及附加协议若本仓库没有设置则按MIT开源协议授权
// CSDN博客https://blog.csdn.net/qq_40374647
// 哔哩哔哩视频https://space.bilibili.com/94253567
// Gitee源代码仓库https://gitee.com/RRQM_Home
// Github源代码仓库https://github.com/RRQM
// API首页http://rrqm_home.gitee.io/touchsocket/
// 交流QQ群234762506
// 感谢您的下载和使用
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
namespace ThingsGateway.Foundation.Core
{
/// <summary>
/// ConfigEventArgs
/// </summary>
public class ConfigEventArgs : PluginEventArgs
{
/// <summary>
/// ConfigEventArgs
/// </summary>
/// <param name="config"></param>
public ConfigEventArgs(TouchSocketConfig config)
{
this.Config = config;
}
/// <summary>
/// 具体配置
/// </summary>
public TouchSocketConfig Config { get; }
}
}

View File

@@ -111,6 +111,7 @@ namespace ThingsGateway.Foundation.Core
{
timeoutCancellationTokenSource.Cancel();
await task;
return;
}
throw new TimeoutException();
}

View File

@@ -48,10 +48,9 @@ public partial class OPCUAServer
else
{
var message = formatter(state, exception);
_log.Log((Foundation.Core.LogLevel)(byte)logLevel, state, message, exception);
if (logLevel > Microsoft.Extensions.Logging.LogLevel.Information)
if (logLevel > Microsoft.Extensions.Logging.LogLevel.Warning)
{
_log.Log((Foundation.Core.LogLevel)(byte)logLevel, state, message, exception);
}
}
}

View File

@@ -113,18 +113,13 @@ public abstract class Siemens : CollectBase
return new(await _plc?.WriteAsync(address, value, cancellationToken));
}
/// <inheritdoc/>
protected override void Dispose(bool disposing)
{
_plc?.Disconnect();
base.Dispose(disposing);
}
/// <inheritdoc/>
protected override async Task<OperResult<byte[]>> ReadAsync(string address, int length, CancellationToken cancellationToken)
{

View File

@@ -8,8 +8,8 @@
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.8.8.50" />
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.8.8.50" />
<PackageReference Include="Furion.Pure" Version="4.8.8.50" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.112" />
<PackageReference Include="SqlSugar.TDengineCore" Version="2.9.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.114" />
<PackageReference Include="SqlSugar.TDengineCore" Version="3.0.0" />
<PackageReference Include="UAParser" Version="3.1.47" />
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
</ItemGroup>

View File

@@ -369,6 +369,10 @@ public class AlarmWorker : BackgroundService
cancellationToken.SafeDispose();
}
StoppingTokens.Clear();
HisAlarmDeviceVariables.Clear();
DeviceVariables.Clear();
RealAlarmDeviceVariables.Clear();
}
catch (Exception ex)
{
@@ -521,6 +525,7 @@ public class AlarmWorker : BackgroundService
if (stoppingToken.IsCancellationRequested)
break;
if (!item.AlarmEnable) continue;
if (!item.IsOnline) continue;
AlarmAnalysis(item);
}
if (stoppingToken.IsCancellationRequested)
@@ -601,26 +606,6 @@ public class AlarmWorker : BackgroundService
if (stoppingToken.IsCancellationRequested)
break;
//缓存值
var cacheData = await CacheDb.GetCacheData();
if (cacheData.Count > 0)
{
var data = cacheData.SelectMany(a => a.CacheStr.FromJsonString<List<HistoryAlarm>>()).ToList();
try
{
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken);
await CacheDb.DeleteCacheData(cacheData.Select(a => a.Id).ToArray());
}
catch (Exception ex)
{
if (isSuccess)
_logger.LogWarning(ex, "写入历史报警失败");
}
}
if (stoppingToken.IsCancellationRequested)
break;
if (list.Count != 0)
{
////Sql保存
@@ -642,13 +627,34 @@ public class AlarmWorker : BackgroundService
var cacheDatas = list.ChunkTrivialBetter(500);
foreach (var a in cacheDatas)
{
await CacheDb.AddCacheData("", a.ToJsonString(), 50000);
await CacheDb.AddCacheData("", a.ToJsonString(), 5000);
}
isSuccess = false;
}
}
if (isSuccess)
{
//缓存值
var cacheData = await CacheDb.GetCacheData();
if (cacheData.Count > 0)
{
var data = cacheData.SelectMany(a => a.CacheStr.FromJsonString<List<HistoryAlarm>>()).ToList();
try
{
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken);
await CacheDb.DeleteCacheData(cacheData.Select(a => a.Id).ToArray());
}
catch (Exception ex)
{
if (isSuccess)
_logger.LogWarning(ex, "写入历史报警失败");
}
}
}
if (stoppingToken.IsCancellationRequested)
break;
}
catch (TaskCanceledException)
{

View File

@@ -269,7 +269,10 @@ public class CollectDeviceCore
finally
{
isInitSuccess = false;
GlobalDeviceData.CollectDevices.RemoveWhere(it => it.Id == Device.Id);
lock (GlobalDeviceData.CollectDevices)
{
GlobalDeviceData.CollectDevices.RemoveWhere(it => it.Id == Device.Id);
}
}
}
@@ -292,12 +295,19 @@ public class CollectDeviceCore
_logger = App.GetService<ILoggerFactory>().CreateLogger("采集设备:" + _device.Name);
//全局数据更新
if (isUpDevice || upDevice)
//if (isUpDevice || upDevice)
{
lock (GlobalDeviceData.CollectDevices)
{
GlobalDeviceData.CollectDevices.RemoveWhere(it => it.Id == device.Id);
GlobalDeviceData.CollectDevices.Add(device);
if (GlobalDeviceData.CollectDevices.Any(a => a.Id == device.Id))
{
GlobalDeviceData.CollectDevices.RemoveWhere(it => it.Id == device.Id);
GlobalDeviceData.CollectDevices.Add(device);
}
else
{
GlobalDeviceData.CollectDevices.Add(device);
}
}
}
//更新插件信息

View File

@@ -124,7 +124,7 @@ public class CollectDeviceThread : IAsyncDisposable
}
try
{
await DeviceTask.WaitAsync(CancellationToken.None);
await DeviceTask.WaitAsync(TimeSpan.FromMinutes(3));
}
catch (ObjectDisposedException)
{

View File

@@ -329,6 +329,9 @@ public class HistoryValueWorker : BackgroundService
cancellationToken.SafeDispose();
}
StoppingTokens.Clear();
ChangeDeviceVariables.Clear();
DeviceVariables.Clear();
}
catch (Exception ex)
{
@@ -418,27 +421,12 @@ public class HistoryValueWorker : BackgroundService
{
await Task.Delay(500, stoppingToken);
if (stoppingToken.IsCancellationRequested)
break;
//缓存值
var cacheData = await CacheDb.GetCacheData();
var data = cacheData.SelectMany(a => a.CacheStr.FromJsonString<List<HistoryValue>>()).ToList();
try
{
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken);
await CacheDb.DeleteCacheData(cacheData.Select(a => a.Id).ToArray());
}
catch (Exception ex)
{
if (LastIsSuccess)
_logger.LogWarning(ex, "写入历史数据失败");
}
if (stoppingToken.IsCancellationRequested)
break;
var collectList = DeviceVariables.ToListWithDequeue();
var changeList = ChangeDeviceVariables.ToListWithDequeue();
if (collectList.Count != 0)
{
////Sql保存
@@ -457,15 +445,14 @@ public class HistoryValueWorker : BackgroundService
var cacheDatas = collecthis.ChunkTrivialBetter(500);
foreach (var a in cacheDatas)
{
await CacheDb.AddCacheData("", a.ToJsonString(), 50000);
await CacheDb.AddCacheData("", a.ToJsonString(), 5000);
}
LastIsSuccess = false;
}
}
if (stoppingToken.IsCancellationRequested)
break;
var changeList = ChangeDeviceVariables.ToListWithDequeue();
if (changeList.Count != 0)
{
////Sql保存
@@ -484,12 +471,31 @@ public class HistoryValueWorker : BackgroundService
var cacheDatas = changehis.ChunkTrivialBetter(500);
foreach (var a in cacheDatas)
{
await CacheDb.AddCacheData("", a.ToJsonString(), 50000);
await CacheDb.AddCacheData("", a.ToJsonString(), 5000);
}
LastIsSuccess = false;
}
}
if (LastIsSuccess)
{
//缓存值
var cacheData = await CacheDb.GetCacheData();
var data = cacheData.SelectMany(a => a.CacheStr.FromJsonString<List<HistoryValue>>()).ToList();
try
{
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken);
await CacheDb.DeleteCacheData(cacheData.Select(a => a.Id).ToArray());
}
catch (Exception ex)
{
if (LastIsSuccess)
_logger.LogWarning(ex, "写入历史数据失败");
}
}
if (stoppingToken.IsCancellationRequested)
break;
}
catch (TaskCanceledException)
{

View File

@@ -113,7 +113,7 @@ public class UploadDeviceThread : IAsyncDisposable
}
try
{
await DeviceTask.WaitAsync(CancellationToken.None);
await DeviceTask.WaitAsync(TimeSpan.FromMinutes(3));
}
catch (ObjectDisposedException)
{

View File

@@ -34,13 +34,5 @@
<ProjectReference Include="..\ThingsGateway.Gateway.Blazor\ThingsGateway.Gateway.Blazor.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro - AF2021'">
<ProjectReference Include="..\..\PluginProAF2021\ThingsGateway.Gateway.LK\ThingsGateway.Gateway.LK.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro' AND '$(Configuration)' == 'Debug'">
<ProjectReference Include="..\..\PluginProAF2021\ThingsGateway.Gateway.LK\ThingsGateway.Gateway.LK.csproj" />
</ItemGroup>
</Project>

View File

@@ -47,10 +47,13 @@
<ProjectReference Include="..\ThingsGateway.Web.Core\ThingsGateway.Web.Core.csproj" />
</ItemGroup>
<PropertyGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro - AF2021'">
<DefineConstants>AF2021</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro' AND '$(Configuration)' == 'Debug'">
<DefineConstants>AF2021</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="'$(SolutionName)'=='ThingsGateway - Pro - AF2021'">
<ProjectReference Include="..\..\PluginProAF2021\ThingsGateway.Gateway.LK\ThingsGateway.Gateway.LK.csproj" />
<PackageReference Include="MQTTnet.AspNetCore" Version="4.3.1.873" />
</ItemGroup>
</Project>