mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-24 04:17:08 +08:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8d6ae203a0 | ||
![]() |
4353479a5c | ||
![]() |
34d7687f9e | ||
![]() |
b1dc3cf4af | ||
![]() |
6a58b95933 | ||
![]() |
d3badfd02b | ||
![]() |
0098be057b |
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<Version>2.0.5.0</Version>
|
||||
<Version>2.0.6.0</Version>
|
||||
<Authors>Diego</Authors>
|
||||
<Product>ThingsGateway</Product>
|
||||
<Copyright>© 2023-present Diego</Copyright>
|
||||
|
@@ -52,8 +52,8 @@ public class OpenApiSessionService : DbRepository<OpenApiUser>, IOpenApiSessionS
|
||||
//获取该用户的verificat信息
|
||||
List<VerificatInfo> verificatInfos = await _verificatService.GetOpenApiVerificatIdAsync(input.Id);
|
||||
//当前需要踢掉用户的verificat
|
||||
var deleteVerificats = verificatInfos.Where(it => input.VerificatIds.Contains(it.Id)).ToList();
|
||||
await _verificatService.SetOpenApiVerificatIdAsync(input.Id, deleteVerificats);//如果还有verificat则更新verificat
|
||||
var setVerificats = verificatInfos.Where(it => !input.VerificatIds.Contains(it.Id)).ToList();
|
||||
await _verificatService.SetOpenApiVerificatIdAsync(input.Id, setVerificats);//如果还有verificat则更新verificat
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -52,12 +52,11 @@ public class SessionService : DbRepository<SysUser>, ISessionService
|
||||
{
|
||||
//获取该用户的verificat信息
|
||||
List<VerificatInfo> verificatInfos = await _verificatService.GetVerificatIdAsync(input.Id);
|
||||
//当前需要踢掉用户的verificat
|
||||
List<VerificatInfo> deleteVerificats = new();
|
||||
|
||||
//踢掉包含verificat列表的verificat信息
|
||||
deleteVerificats = verificatInfos.Where(it => input.VerificatIds.Contains(it.Id)).ToList();
|
||||
await _verificatService.SetVerificatIdAsync(input.Id, deleteVerificats);//如果还有verificat则更新verificat
|
||||
var setVerificats = verificatInfos.Where(it => !input.VerificatIds.Contains(it.Id)).ToList();
|
||||
var deleteVerificats = verificatInfos.Where(it => input.VerificatIds.Contains(it.Id)).ToList();
|
||||
await _verificatService.SetVerificatIdAsync(input.Id, setVerificats);//如果还有verificat则更新verificat
|
||||
|
||||
var message = "您已被强制下线!";
|
||||
await _noticeService.LogoutAsync(input.Id, deleteVerificats, message);//通知下线
|
||||
|
@@ -15,7 +15,7 @@
|
||||
<ItemGroup>
|
||||
|
||||
<PackageReference Include="Masa.Blazor" Version="1.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.10" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
|
@@ -12,10 +12,10 @@
|
||||
<PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.8.8.40" />
|
||||
<PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.8.8.40" />
|
||||
<PackageReference Include="Furion.Pure" Version="4.8.8.40" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.94" />
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.96" />
|
||||
<PackageReference Include="UAParser" Version="3.1.47" />
|
||||
<PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
|
||||
<PackageReference Include="MiniExcel" Version="1.31.0" />
|
||||
<PackageReference Include="MiniExcel" Version="1.31.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@@ -445,7 +445,7 @@ public class VariableService : DbRepository<DeviceVariable>, IVariableService
|
||||
try
|
||||
{
|
||||
var variable = ((ExpandoObject)item).ConvertToEntity<DeviceVariable>(true);
|
||||
|
||||
variable.IsMemoryVariable = true;
|
||||
//变量ID都需要手动补录
|
||||
variables.Add(variable);
|
||||
if (dbVariableDicts.TryGetValue(variable.Name, out var dbvar1))
|
||||
|
@@ -66,7 +66,7 @@ public class AlarmWorker : BackgroundService
|
||||
/// </summary>
|
||||
public OperResult StatuString { get; set; } = new OperResult("初始化");
|
||||
private ConcurrentQueue<DeviceVariableRunTime> DeviceVariables { get; set; } = new();
|
||||
private ConcurrentQueue<DeviceVariableRunTime> HisAlarmDeviceVariables { get; set; } = new();
|
||||
private ConcurrentQueue<HistoryAlarm> HisAlarmDeviceVariables { get; set; } = new();
|
||||
/// <summary>
|
||||
/// 获取数据库链接
|
||||
/// </summary>
|
||||
@@ -465,7 +465,7 @@ public class AlarmWorker : BackgroundService
|
||||
OnAlarmChanged?.Invoke(item.Adapt<DeviceVariableRunTime>());
|
||||
if (!IsExited)
|
||||
{
|
||||
HisAlarmDeviceVariables.Enqueue(item);
|
||||
HisAlarmDeviceVariables.Enqueue(item.Adapt<HistoryAlarm>());
|
||||
}
|
||||
|
||||
if (eventEnum == EventEnum.Alarm)
|
||||
@@ -586,18 +586,20 @@ public class AlarmWorker : BackgroundService
|
||||
|
||||
//缓存值
|
||||
var cacheData = await CacheDb.GetCacheData();
|
||||
var data = cacheData.SelectMany(a => a.CacheStr.FromJson<List<HistoryAlarm>>()).ToList();
|
||||
try
|
||||
if (cacheData.Count > 0)
|
||||
{
|
||||
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken.Token);
|
||||
await CacheDb.DeleteCacheData(cacheData.Select(a => a.Id).ToArray());
|
||||
var data = cacheData.SelectMany(a => a.CacheStr.FromJson<List<HistoryAlarm>>()).ToList();
|
||||
try
|
||||
{
|
||||
var count = await sqlSugarClient.Insertable(data).ExecuteCommandAsync(stoppingToken.Token);
|
||||
await CacheDb.DeleteCacheData(cacheData.Select(a => a.Id).ToArray());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (isSuccess)
|
||||
_logger.LogWarning(ex, "写入历史报警失败");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (isSuccess)
|
||||
_logger.LogWarning(ex, "写入历史报警失败");
|
||||
}
|
||||
|
||||
if (stoppingToken.Token.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
@@ -605,16 +607,15 @@ public class AlarmWorker : BackgroundService
|
||||
var list = HisAlarmDeviceVariables.ToListWithDequeue();
|
||||
if (list.Count != 0)
|
||||
{
|
||||
var hisalarm = list.Adapt<List<HistoryAlarm>>();
|
||||
////Sql保存
|
||||
hisalarm.ForEach(it =>
|
||||
list.ForEach(it =>
|
||||
{
|
||||
it.Id = YitIdHelper.NextId();
|
||||
});
|
||||
//插入
|
||||
try
|
||||
{
|
||||
await sqlSugarClient.Insertable(hisalarm).ExecuteCommandAsync(stoppingToken.Token);
|
||||
await sqlSugarClient.Insertable(list).ExecuteCommandAsync(stoppingToken.Token);
|
||||
isSuccess = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -622,7 +623,7 @@ public class AlarmWorker : BackgroundService
|
||||
if (isSuccess)
|
||||
_logger.LogWarning(ex, "写入历史报警失败");
|
||||
|
||||
var cacheDatas = hisalarm.ChunkTrivialBetter(500);
|
||||
var cacheDatas = list.ChunkTrivialBetter(500);
|
||||
foreach (var a in cacheDatas)
|
||||
{
|
||||
await CacheDb.AddCacheData("", a.ToJson(), 50000);
|
||||
|
@@ -29,6 +29,7 @@ using System.Runtime.InteropServices;
|
||||
using ThingsGateway.Foundation;
|
||||
|
||||
using TouchSocket.Resources;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
|
||||
@@ -159,7 +160,7 @@ public class TcpClientBaseEx : BaseSocket, ITcpClient
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectedPlguin.OnTcpDisconnected), this, e);
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectedPlugin.OnTcpDisconnected), this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -13,6 +13,7 @@
|
||||
using System.IO.Ports;
|
||||
|
||||
using TouchSocket.Resources;
|
||||
using TouchSocket.Sockets;
|
||||
|
||||
namespace ThingsGateway.Foundation.Serial;
|
||||
|
||||
@@ -172,7 +173,7 @@ public class SerialClientBase : BaseSerial, ISerialClient
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectedPlguin.OnTcpDisconnected), this, e);
|
||||
this.PluginsManager.Raise(nameof(ITcpDisconnectedPlugin.OnTcpDisconnected), this, e);
|
||||
}
|
||||
private void PrivateOnDisconnecting(DisconnectEventArgs e)
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="TouchSocket" Version="2.0.0-beta.120" />
|
||||
<PackageReference Include="TouchSocket" Version="2.0.0-beta.135" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetFramework)'!='net45'">
|
||||
<PackageReference Include="System.IO.Ports" Version="7.0.0" />
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<Version>2.0.5.0</Version>
|
||||
<Version>2.0.6.0</Version>
|
||||
<Authors>Diego</Authors>
|
||||
<Product>ThingsGateway</Product>
|
||||
<Copyright>© 2023-present Diego</Copyright>
|
||||
|
@@ -205,9 +205,9 @@ public class OPCUAClient : DisposableObject
|
||||
#region 订阅
|
||||
|
||||
/// <summary>
|
||||
/// 新增订阅,需要指定订阅的关键字,订阅的tag名数组,以及回调方法
|
||||
/// 新增订阅,需要指定订阅组名称,订阅的tag名数组
|
||||
/// </summary>
|
||||
public void AddSubscription(string subscriptionName, string[] items)
|
||||
public async Task AddSubscriptionAsync(string subscriptionName, string[] items)
|
||||
{
|
||||
Subscription m_subscription = new(m_session.DefaultSubscription)
|
||||
{
|
||||
@@ -222,16 +222,26 @@ public class OPCUAClient : DisposableObject
|
||||
List<MonitoredItem> monitoredItems = new();
|
||||
for (int i = 0; i < items.Length; i++)
|
||||
{
|
||||
var item = new MonitoredItem
|
||||
try
|
||||
{
|
||||
StartNodeId = new NodeId(items[i]),
|
||||
AttributeId = Attributes.Value,
|
||||
DisplayName = items[i],
|
||||
Filter = new DataChangeFilter() { DeadbandValue = OPCNode.DeadBand, DeadbandType = (int)DeadbandType.Absolute, Trigger = DataChangeTrigger.StatusValue },
|
||||
SamplingInterval = OPCNode?.UpdateRate ?? 1000,
|
||||
};
|
||||
item.Notification += Callback;
|
||||
monitoredItems.Add(item);
|
||||
var variableNode = (VariableNode)ReadNode(items[i], false);
|
||||
var item = new MonitoredItem
|
||||
{
|
||||
StartNodeId = variableNode.NodeId,
|
||||
AttributeId = Attributes.Value,
|
||||
DisplayName = items[i],
|
||||
Filter = new DataChangeFilter() { DeadbandValue = OPCNode.DeadBand, DeadbandType = (int)DeadbandType.Absolute, Trigger = DataChangeTrigger.StatusValue },
|
||||
SamplingInterval = OPCNode?.UpdateRate ?? 1000,
|
||||
};
|
||||
await typeSystem.LoadType(variableNode.DataType, true, true);
|
||||
|
||||
item.Notification += Callback;
|
||||
monitoredItems.Add(item);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error($"初始化{items[i]}变量订阅失败" + ex.Message);
|
||||
}
|
||||
}
|
||||
m_subscription.AddItems(monitoredItems);
|
||||
|
||||
@@ -511,15 +521,12 @@ public class OPCUAClient : DisposableObject
|
||||
NodeId = new NodeId(tag),
|
||||
AttributeId = Attributes.Value,
|
||||
};
|
||||
var node = (VariableNode)ReadNode(tag.ToString(), false);
|
||||
//var expandedNodeId = NodeId.ToExpandedNodeId(node.DataType, m_session.NamespaceUris);
|
||||
//var type = m_session.Factory.GetSystemType(expandedNodeId);
|
||||
//var data = value.ToObject(type);
|
||||
//var dataValue = new DataValue(new Variant(data));
|
||||
var variableNode = (VariableNode)ReadNode(tag.ToString(), false);
|
||||
await typeSystem.LoadType(variableNode.DataType, true, true);
|
||||
var dataValue = JsonUtils.Decode(
|
||||
m_session.MessageContext,
|
||||
node.DataType,
|
||||
TypeInfo.GetBuiltInType(node.DataType, m_session.SystemContext.TypeTable),
|
||||
variableNode.DataType,
|
||||
TypeInfo.GetBuiltInType(variableNode.DataType, m_session.SystemContext.TypeTable),
|
||||
value.CalculateActualValueRank(),
|
||||
value
|
||||
);
|
||||
@@ -560,6 +567,8 @@ public class OPCUAClient : DisposableObject
|
||||
ReadValueIdCollection nodesToRead = new();
|
||||
for (int i = 0; i < nodeIds.Length; i++)
|
||||
{
|
||||
var variableNode = (VariableNode)ReadNode(nodeIds[i].ToString(), false);
|
||||
await typeSystem.LoadType(variableNode.DataType, true, true);
|
||||
nodesToRead.Add(new ReadValueId()
|
||||
{
|
||||
NodeId = nodeIds[i],
|
||||
@@ -581,10 +590,10 @@ public class OPCUAClient : DisposableObject
|
||||
List<(string, DataValue, JToken)> jTokens = new();
|
||||
for (int i = 0; i < results.Count; i++)
|
||||
{
|
||||
var node = (VariableNode)ReadNode(nodeIds[i].ToString(), false);
|
||||
var type = TypeInfo.GetBuiltInType(node.DataType, m_session.SystemContext.TypeTable);
|
||||
var variableNode = (VariableNode)ReadNode(nodeIds[i].ToString(), false);
|
||||
var type = TypeInfo.GetBuiltInType(variableNode.DataType, m_session.SystemContext.TypeTable);
|
||||
var jToken = JsonUtils.Encode(m_session.MessageContext, type, results[i].Value);
|
||||
jTokens.Add((node.NodeId.ToString(), results[i], jToken));
|
||||
jTokens.Add((variableNode.NodeId.ToString(), results[i], jToken));
|
||||
}
|
||||
return jTokens.ToList();
|
||||
}
|
||||
@@ -860,7 +869,7 @@ public class OPCUAClient : DisposableObject
|
||||
else
|
||||
throw new Exception(string.Format("验证证书失败,错误代码:{0}: {1}", eventArgs.Error.Code, eventArgs.Error.AdditionalInfo));
|
||||
}
|
||||
|
||||
private ComplexTypeSystem typeSystem;
|
||||
/// <summary>
|
||||
/// Creates a new session.
|
||||
/// </summary>
|
||||
@@ -897,7 +906,8 @@ public class OPCUAClient : DisposableObject
|
||||
60000,
|
||||
userIdentity,
|
||||
Array.Empty<string>());
|
||||
await new ComplexTypeSystem(m_session).Load(false, true).ConfigureAwait(false);
|
||||
|
||||
typeSystem = new ComplexTypeSystem(m_session);
|
||||
Log.Debug("连接成功");
|
||||
|
||||
m_session.KeepAliveInterval = OPCNode.KeepAliveInterval == 0 ? 60000 : OPCNode.KeepAliveInterval;
|
||||
@@ -905,7 +915,7 @@ public class OPCUAClient : DisposableObject
|
||||
|
||||
//如果是订阅模式,连接时添加订阅组
|
||||
if (OPCNode.ActiveSubscribe)
|
||||
AddSubscription(Guid.NewGuid().ToString(), Variables.ToArray());
|
||||
await AddSubscriptionAsync(Guid.NewGuid().ToString(), Variables.ToArray());
|
||||
return m_session;
|
||||
}
|
||||
|
||||
|
@@ -316,9 +316,9 @@
|
||||
当前活动会话。
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.AddSubscription(System.String,System.String[])">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.AddSubscriptionAsync(System.String,System.String[])">
|
||||
<summary>
|
||||
新增订阅,需要指定订阅的关键字,订阅的tag名数组,以及回调方法
|
||||
新增订阅,需要指定订阅组名称,订阅的tag名数组
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.RemoveAllSubscription">
|
||||
|
@@ -77,10 +77,10 @@ public partial class OPCUAClientDebugDriverPage
|
||||
|
||||
base.OnAfterRender(firstRender);
|
||||
}
|
||||
private void Add()
|
||||
private async Task Add()
|
||||
{
|
||||
if (_plc.Connected)
|
||||
_plc.AddSubscription(YitIdHelper.NextId().ToString(), new[] { defalutDebugDriverPage.Address });
|
||||
await _plc.AddSubscriptionAsync(YitIdHelper.NextId().ToString(), new[] { defalutDebugDriverPage.Address });
|
||||
else
|
||||
{
|
||||
defalutDebugDriverPage.Messages.Add((Microsoft.Extensions.Logging.LogLevel.Debug, SysDateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset) + " - " + "δ<><CEB4><EFBFBD><EFBFBD>"));
|
||||
|
Reference in New Issue
Block a user