mirror of
https://gitee.com/ThingsGateway/ThingsGateway.git
synced 2025-10-21 03:01:28 +08:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f82c5f2f27 | ||
![]() |
a83c1c3899 | ||
![]() |
91d6aed109 | ||
![]() |
db8f8fe51d | ||
![]() |
4596004b17 | ||
![]() |
d5540906cb | ||
![]() |
90796a979d | ||
![]() |
2190a87772 | ||
![]() |
c5953b83f8 | ||
![]() |
24bc60abf0 | ||
![]() |
31eee6b009 | ||
![]() |
c5da565a8f | ||
![]() |
947cd712e1 |
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>3.0.0.2</Version>
|
||||
<Version>3.0.0.6</Version>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
|
||||
<Authors>Diego</Authors>
|
||||
|
@@ -13,3 +13,4 @@
|
||||
global using System;
|
||||
|
||||
global using ThingsGateway.Components;
|
||||
|
||||
|
@@ -12,6 +12,8 @@
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
using ThingsGateway.Components;
|
||||
|
||||
namespace ThingsGateway.Foundation.Demo;
|
||||
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
|
||||
/// <summary>
|
||||
@@ -69,7 +71,7 @@ public abstract class DriverDebugUIBase : ComponentBase, IDisposable
|
||||
_periodicTimer?.Dispose();
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
public void LogOut(ThingsGateway.Foundation.LogLevel logLevel, object source, string message, Exception exception)
|
||||
public void LogOut(ThingsGateway.Foundation.Core.LogLevel logLevel, object source, string message, Exception exception)
|
||||
{
|
||||
Messages.Add(((LogLevel)logLevel,
|
||||
$"{DateTimeExtensions.CurrentDateTime.ToDefaultDateTimeFormat(InitTimezone.TimezoneOffset)} - {message} {exception}"));
|
||||
|
@@ -13,7 +13,7 @@
|
||||
@using BlazorComponent;
|
||||
@using Microsoft.AspNetCore.Components.Web;
|
||||
@using Microsoft.JSInterop;
|
||||
@using ThingsGateway.Foundation;
|
||||
@using ThingsGateway.Foundation.Core;
|
||||
@using Masa.Blazor;
|
||||
@namespace ThingsGateway.Foundation.Demo
|
||||
@inherits DriverDebugUIBase
|
||||
|
@@ -15,7 +15,7 @@
|
||||
@using Microsoft.AspNetCore.Components.Web;
|
||||
@using System.IO.Ports;
|
||||
@using System.Collections.Concurrent;
|
||||
@using ThingsGateway.Foundation;
|
||||
@using ThingsGateway.Foundation.Core;
|
||||
@using Masa.Blazor
|
||||
<MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%">
|
||||
<div class="mb-4">通道配置</div>
|
||||
|
@@ -15,7 +15,7 @@
|
||||
@using Microsoft.AspNetCore.Components.Web;
|
||||
@using System.IO.Ports;
|
||||
@using System.Collections.Concurrent;
|
||||
@using ThingsGateway.Foundation;
|
||||
@using ThingsGateway.Foundation.Core;
|
||||
@using Masa.Blazor
|
||||
|
||||
<MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%">
|
||||
|
@@ -15,7 +15,7 @@
|
||||
@using Microsoft.AspNetCore.Components.Web;
|
||||
@using System.IO.Ports;
|
||||
@using System.Collections.Concurrent;
|
||||
@using ThingsGateway.Foundation;
|
||||
@using ThingsGateway.Foundation.Core;
|
||||
@using Masa.Blazor
|
||||
|
||||
<MCard Elevation="1" Rounded="false" Class="pa-2" Style="width:100%">
|
||||
|
@@ -15,5 +15,7 @@ global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
||||
global using ThingsGateway.Components;
|
||||
global using ThingsGateway.Foundation.Core;
|
||||
global using ThingsGateway.Foundation.Serial;
|
||||
global using ThingsGateway.Foundation.Sockets;
|
||||
|
||||
|
@@ -124,6 +124,15 @@ public partial class MainLayout
|
||||
"Title": "OPCUAClient"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"Title": "Mqtt",
|
||||
"Children": [
|
||||
{
|
||||
"Href": "/MqttClient",
|
||||
"Title": "MqttClient"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
|
@@ -45,6 +45,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007DebugPage.razor.cs" Link="Pages\DLT645\DLT645_2007DebugPage.razor.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\MqttRpcNameVaueWithId.cs" Link="Pages\Mqtt\MqttRpcNameVaueWithId.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientDebugPage.razor.cs" Link="Pages\Mqtt\MqttClientDebugPage.razor.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientPage.razor.cs" Link="Pages\Mqtt\MqttClientPage.razor.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\PrivateLogger.cs" Link="Pages\Mqtt\PrivateLogger.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\RpcClass\MqttRpcClient.cs" Link="Pages\Mqtt\MqttRpcClient.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\RpcClass\MqttRpcClientExtensions.cs" Link="Pages\Mqtt\MqttRpcClientExtensions.cs" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\RpcClass\MqttRpcTopicPair.cs" Link="Pages\Mqtt\MqttRpcTopicPair.cs" />
|
||||
<Content Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007DebugPage.razor" Link="Pages\DLT645\DLT645_2007DebugPage.razor" />
|
||||
<Compile Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007OverTcpDebugPage.razor.cs" Link="Pages\DLT645\DLT645_2007OverTcpDebugPage.razor.cs" />
|
||||
<Content Include="..\..\Plugin\ThingsGateway.Plugin.DLT645\Page\DLT645_2007OverTcpDebugPage.razor" Link="Pages\DLT645\DLT645_2007OverTcpDebugPage.razor" />
|
||||
@@ -117,5 +124,17 @@
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Pages\Mqtt\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientDebugPage.razor" Link="Pages\Mqtt\MqttClientDebugPage.razor" />
|
||||
<Content Include="..\..\Plugin\ThingsGateway.Plugin.Mqtt\Page\MqttClientPage.razor" Link="Pages\Mqtt\MqttClientPage.razor" />
|
||||
<PackageReference Include="MQTTnet" Version="4.3.1.873" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
|
||||
</Project>
|
||||
|
@@ -19,7 +19,7 @@
|
||||
@using BlazorComponent
|
||||
@using Masa.Blazor
|
||||
@using Masa.Blazor.Presets
|
||||
@using ThingsGateway.Foundation;
|
||||
@using ThingsGateway.Foundation.Core;
|
||||
@using ThingsGateway.Components;
|
||||
@using ThingsGateway.Core;
|
||||
@using System.Net.Http.Json
|
||||
|
@@ -1,6 +1,6 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<Version>3.0.0.2</Version>
|
||||
<Version>3.0.0.6</Version>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<TargetFrameworks>net45;netstandard2.0;net6.0;net7.0</TargetFrameworks>
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.DLT645;
|
||||
|
||||
|
@@ -11,9 +11,11 @@
|
||||
#endregion
|
||||
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
||||
global using ThingsGateway.Foundation.Core;
|
||||
global using ThingsGateway.Foundation.Serial;
|
||||
global using ThingsGateway.Foundation.Sockets;
|
||||
|
@@ -261,7 +261,7 @@
|
||||
DLT645_2007
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007BitConverter.#ctor(ThingsGateway.Foundation.EndianType)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007BitConverter.#ctor(ThingsGateway.Foundation.Core.EndianType)">
|
||||
<summary>
|
||||
DLT645_2007
|
||||
</summary>
|
||||
@@ -304,7 +304,7 @@
|
||||
DLT645_2007
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007OverTcp.#ctor(ThingsGateway.Foundation.TcpClient)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.DLT645.DLT645_2007OverTcp.#ctor(ThingsGateway.Foundation.Core.TcpClient)">
|
||||
<summary>
|
||||
DLT645_2007
|
||||
</summary>
|
||||
|
@@ -11,9 +11,11 @@
|
||||
#endregion
|
||||
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
||||
global using ThingsGateway.Foundation.Core;
|
||||
global using ThingsGateway.Foundation.Serial;
|
||||
global using ThingsGateway.Foundation.Sockets;
|
||||
|
@@ -91,9 +91,17 @@ internal class ModbusHelper
|
||||
|
||||
if (response[1] >= 0x80)//错误码
|
||||
return new OperResult<byte[], FilterResult>(GetDescriptionByErrorCode(response[2])) { Content2 = FilterResult.Success };
|
||||
if ((response.Length < response[2] + 3))
|
||||
return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache };
|
||||
if (response[1] <= 0x05)
|
||||
{
|
||||
if ((response.Length < response[2] + 3))
|
||||
return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache };
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((response.Length < 6))
|
||||
return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache };
|
||||
|
||||
}
|
||||
|
||||
if (send.Length == 0)
|
||||
{
|
||||
@@ -126,15 +134,20 @@ internal class ModbusHelper
|
||||
|
||||
if (response[1] >= 0x80)//错误码
|
||||
return new OperResult<byte[], FilterResult>(GetDescriptionByErrorCode(response[2])) { Content2 = FilterResult.Success };
|
||||
if ((response.Length < response[2] + 5))
|
||||
return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache };
|
||||
if (response[1] <= 0x05)
|
||||
{
|
||||
if ((response.Length < response[2] + 5))
|
||||
return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache };
|
||||
|
||||
if (response[2] == 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((response.Length < 8))
|
||||
return new OperResult<byte[], FilterResult>("数据长度不足" + response.ToHexString()) { Content2 = FilterResult.Cache };
|
||||
|
||||
}
|
||||
|
||||
|
||||
var data = response.SelectMiddle(0, response[2] != 0 ? response[2] + 5 : 8);
|
||||
if (crcCheck && !EasyCRC16.CheckCRC16(data))
|
||||
return new OperResult<byte[], FilterResult>("Crc校验失败" + DataTransUtil.ByteToHexString(data, ' ')) { Content2 = FilterResult.Success };
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Modbus;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Modbus;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Modbus;
|
||||
|
@@ -11,7 +11,6 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Bool;
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Modbus;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Modbus;
|
||||
|
@@ -11,7 +11,6 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Bool;
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Modbus;
|
||||
|
@@ -10,8 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
using ThingsGateway.Foundation.Extension.String;
|
||||
|
||||
|
@@ -406,7 +406,7 @@
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusServer.WriteAsync(System.String,System.Boolean[],System.Threading.CancellationToken)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusServer.Received(ThingsGateway.Foundation.Sockets.SocketClient,ThingsGateway.Foundation.IRequestInfo)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.ModbusServer.Received(ThingsGateway.Foundation.Sockets.SocketClient,ThingsGateway.Foundation.Core.IRequestInfo)">
|
||||
<inheritdoc/>
|
||||
</member>
|
||||
<member name="T:ThingsGateway.Foundation.Adapter.Modbus.ModbusServerDataHandleAdapter">
|
||||
@@ -598,7 +598,7 @@
|
||||
PackHelper
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.PackHelper.ModbusLoadSourceRead``2(ThingsGateway.Foundation.IReadWrite,System.Collections.Generic.List{``1},System.Int32)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Modbus.PackHelper.ModbusLoadSourceRead``2(ThingsGateway.Foundation.Core.IReadWrite,System.Collections.Generic.List{``1},System.Int32)">
|
||||
<summary>
|
||||
打包变量,添加到<see href="deviceVariableSourceReads"></see>
|
||||
</summary>
|
||||
|
@@ -441,7 +441,7 @@
|
||||
当前保存的需订阅列表
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCDA.OPCDAClient.#ctor(ThingsGateway.Foundation.ILog)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCDA.OPCDAClient.#ctor(ThingsGateway.Foundation.Core.ILog)">
|
||||
<summary>
|
||||
<inheritdoc/>
|
||||
</summary>
|
||||
|
@@ -304,7 +304,7 @@
|
||||
SessionReconnectHandler
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.#ctor(ThingsGateway.Foundation.ILog)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.OPCUA.OPCUAClient.#ctor(ThingsGateway.Foundation.Core.ILog)">
|
||||
<summary>
|
||||
默认的构造函数,实例化一个新的OPC UA类
|
||||
</summary>
|
||||
|
@@ -11,8 +11,10 @@
|
||||
#endregion
|
||||
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Linq;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
||||
global using ThingsGateway.Foundation.Core;
|
||||
global using ThingsGateway.Foundation.Sockets;
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using ThingsGateway.Foundation.Extension.String;
|
||||
using ThingsGateway.Foundation.Extension;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Siemens;
|
||||
/// <summary>
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Siemens;
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Siemens;
|
||||
|
||||
|
@@ -10,7 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
@@ -10,8 +10,6 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation.Adapter.Siemens;
|
||||
|
@@ -222,7 +222,7 @@
|
||||
相关命令含义源自网络资料/Shrap7/s7netplus
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Siemens.SiemensS7PLC.#ctor(ThingsGateway.Foundation.TcpClient,ThingsGateway.Foundation.Adapter.Siemens.SiemensEnum)">
|
||||
<member name="M:ThingsGateway.Foundation.Adapter.Siemens.SiemensS7PLC.#ctor(ThingsGateway.Foundation.Core.TcpClient,ThingsGateway.Foundation.Adapter.Siemens.SiemensEnum)">
|
||||
<summary>
|
||||
传入PLC类型,程序内会改变相应PLC类型的S7协议LocalTSAP, RemoteTSAP等
|
||||
</summary>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 设备地址数据的信息,对每个协议都建立其变量地址的表示类
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 打包读取变量
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
/// <summary>
|
||||
/// 打包读取变量
|
||||
/// </summary>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 设备读写接口
|
||||
|
@@ -15,7 +15,7 @@ using System.Text;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.String;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
|
||||
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 读写扩展方法
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// TCP读写设备
|
||||
@@ -25,7 +25,7 @@ public abstract class ReadWriteDevicesSerialSessionBase : ReadWriteDevicesBase
|
||||
{
|
||||
SerialSession = serialSession;
|
||||
WaitingClientEx = SerialSession.GetWaitingClientEx(new() { BreakTrigger = true });
|
||||
SerialSession.Received += Received;
|
||||
SerialSession.Received -= Received;
|
||||
SerialSession.Connecting -= Connecting;
|
||||
SerialSession.Connected -= Connected;
|
||||
SerialSession.Disconnecting -= Disconnecting;
|
||||
@@ -34,6 +34,7 @@ public abstract class ReadWriteDevicesSerialSessionBase : ReadWriteDevicesBase
|
||||
SerialSession.Connected += Connected;
|
||||
SerialSession.Disconnecting += Disconnecting;
|
||||
SerialSession.Disconnected += Disconnected;
|
||||
SerialSession.Received += Received;
|
||||
Logger = SerialSession.Logger;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -86,11 +87,12 @@ public abstract class ReadWriteDevicesSerialSessionBase : ReadWriteDevicesBase
|
||||
/// <inheritdoc/>
|
||||
public override void Dispose()
|
||||
{
|
||||
Disconnect();
|
||||
SerialSession.Received -= Received;
|
||||
SerialSession.Connecting -= Connecting;
|
||||
SerialSession.Connected -= Connected;
|
||||
SerialSession.Disconnecting -= Disconnecting;
|
||||
SerialSession.Disconnected -= Disconnected;
|
||||
Disconnect();
|
||||
if (CascadeDisposal)
|
||||
SerialSession.SafeDispose();
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// TCP读写设备
|
||||
@@ -72,11 +72,11 @@ public abstract class ReadWriteDevicesTcpClientBase : ReadWriteDevicesBase
|
||||
/// <inheritdoc/>
|
||||
public override void Dispose()
|
||||
{
|
||||
Disconnect();
|
||||
TcpClient.Connecting -= Connecting;
|
||||
TcpClient.Connected -= Connected;
|
||||
TcpClient.Disconnecting -= Disconnecting;
|
||||
TcpClient.Disconnected -= Disconnected;
|
||||
Disconnect();
|
||||
if (CascadeDisposal)
|
||||
TcpClient.SafeDispose();
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 服务设备
|
||||
@@ -23,9 +23,14 @@ public abstract class ReadWriteDevicesTcpServerBase : ReadWriteDevicesBase
|
||||
public ReadWriteDevicesTcpServerBase(TcpService tcpService)
|
||||
{
|
||||
TcpService = tcpService;
|
||||
TcpService.Received -= Received;
|
||||
TcpService.Connecting -= Connecting;
|
||||
TcpService.Connected -= Connected;
|
||||
TcpService.Disconnecting -= Disconnecting;
|
||||
TcpService.Disconnected -= Disconnected;
|
||||
TcpService.Received += Received;
|
||||
TcpService.Connecting += Connecting;
|
||||
TcpService.Connected += Connected;
|
||||
TcpService.Received += Received;
|
||||
TcpService.Disconnecting += Disconnecting;
|
||||
TcpService.Disconnected += Disconnected;
|
||||
Logger = TcpService.Logger;
|
||||
@@ -63,11 +68,12 @@ public abstract class ReadWriteDevicesTcpServerBase : ReadWriteDevicesBase
|
||||
/// <inheritdoc/>
|
||||
public override void Dispose()
|
||||
{
|
||||
Disconnect();
|
||||
TcpService.Received -= Received;
|
||||
TcpService.Connecting -= Connecting;
|
||||
TcpService.Connected -= Connected;
|
||||
TcpService.Disconnecting -= Disconnecting;
|
||||
TcpService.Disconnected -= Disconnected;
|
||||
Disconnect();
|
||||
if (CascadeDisposal)
|
||||
TcpService.SafeDispose();
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// UDP读写设备
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 线程安全的LinkedList
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// HSL摘录,用于CRC16验证的类
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 自增
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// EasyLock,使用轻量级SemaphoreSlim锁,只允许一个并发量,并记录并发信息
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// TimerTick
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 常量
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// TCP/Serial适配器基类
|
||||
|
@@ -14,7 +14,7 @@ using System.Net;
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// UDP适配器基类
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 数据类型
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public static class ByteExtensions
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 对象拓展
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Method Info 拓展
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <inheritdoc cref="IMessage"/>
|
||||
public abstract class MessageBase : OperResult<byte[]>, IMessage
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 采集返回消息
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public class OperResult<T> : OperResult, IOperResult<T>
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// BCD格式化值
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 应用于多字节数据的解析或是生成格式<br />
|
||||
|
@@ -21,7 +21,7 @@ using Newtonsoft.Json.Converters;
|
||||
#endif
|
||||
using System.Text;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
|
||||
|
||||
|
@@ -18,7 +18,7 @@ using Newtonsoft.Json;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 类型转换
|
||||
|
@@ -15,7 +15,7 @@ using System.Text;
|
||||
using ThingsGateway.Foundation.Extension.Bool;
|
||||
using ThingsGateway.Foundation.Extension.Generic;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 将基数据类型转换为指定端的一个字节数组,
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 所有数据转换类的静态辅助方法
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
|
||||
/// <summary>
|
||||
/// 常用转换
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#endregion
|
||||
|
||||
using System.Text;
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
/// <summary>
|
||||
/// FileUtil
|
||||
/// </summary>
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#endregion
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
namespace ThingsGateway.Foundation;
|
||||
namespace ThingsGateway.Foundation.Core;
|
||||
/// <summary>
|
||||
/// JTokenUtil
|
||||
/// </summary>
|
||||
|
@@ -17,7 +17,7 @@ global using System.Linq;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
||||
global using ThingsGateway.Foundation;
|
||||
global using ThingsGateway.Foundation.Core;
|
||||
global using ThingsGateway.Foundation.Http;
|
||||
global using ThingsGateway.Foundation.Rpc;
|
||||
global using ThingsGateway.Foundation.Serial;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 注册为消息
|
||||
|
@@ -23,7 +23,9 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息通知类。内部全为弱引用。
|
||||
@@ -31,8 +33,7 @@ namespace ThingsGateway.Foundation
|
||||
public class AppMessenger
|
||||
{
|
||||
private static AppMessenger m_instance;
|
||||
private readonly ReaderWriterLockSlim m_lockSlim = new ReaderWriterLockSlim();
|
||||
private readonly Dictionary<string, List<MessageInstance>> m_tokenAndInstance = new Dictionary<string, List<MessageInstance>>();
|
||||
private readonly ConcurrentDictionary<string, List<MessageInstance>> m_tokenAndInstance = new ConcurrentDictionary<string, List<MessageInstance>>();
|
||||
|
||||
/// <summary>
|
||||
/// 默认单例实例
|
||||
@@ -65,42 +66,38 @@ namespace ThingsGateway.Foundation
|
||||
/// <summary>
|
||||
/// 添加
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="messageInstance"></param>
|
||||
/// <exception cref="MessageRegisteredException"></exception>
|
||||
public void Add(string cancellationToken, MessageInstance messageInstance)
|
||||
public void Add(string token, MessageInstance messageInstance)
|
||||
{
|
||||
using (var writeLock = new WriteLock(this.m_lockSlim))
|
||||
|
||||
if (this.m_tokenAndInstance.TryGetValue(token, out var value))
|
||||
{
|
||||
if (this.m_tokenAndInstance.ContainsKey(cancellationToken))
|
||||
if (!this.AllowMultiple)
|
||||
{
|
||||
if (!this.AllowMultiple)
|
||||
{
|
||||
throw new MessageRegisteredException(TouchSocketCoreResource.TokenExisted.GetDescription(cancellationToken));
|
||||
}
|
||||
this.m_tokenAndInstance[cancellationToken].Add(messageInstance);
|
||||
throw new MessageRegisteredException(TouchSocketCoreResource.TokenExisted.GetDescription(token));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_tokenAndInstance.Add(cancellationToken, new List<MessageInstance>()
|
||||
|
||||
value.Add(messageInstance);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.m_tokenAndInstance.TryAdd(token, new List<MessageInstance>()
|
||||
{
|
||||
messageInstance
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断能否触发该消息,意味着该消息是否已经注册。
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
public bool CanSendMessage(string cancellationToken)
|
||||
public bool CanSendMessage(string token)
|
||||
{
|
||||
using (var readLock = new ReadLock(this.m_lockSlim))
|
||||
{
|
||||
return this.m_tokenAndInstance.ContainsKey(cancellationToken);
|
||||
}
|
||||
return this.m_tokenAndInstance.ContainsKey(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,34 +105,25 @@ namespace ThingsGateway.Foundation
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
using (var writeLock = new WriteLock(this.m_lockSlim))
|
||||
{
|
||||
this.m_tokenAndInstance.Clear();
|
||||
}
|
||||
this.m_tokenAndInstance.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有消息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string[] GetAllMessage()
|
||||
public IEnumerable<string> GetAllMessage()
|
||||
{
|
||||
using (var readLock = new ReadLock(this.m_lockSlim))
|
||||
{
|
||||
return this.m_tokenAndInstance.Keys.ToArray();
|
||||
}
|
||||
return this.m_tokenAndInstance.Keys;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
public void Remove(string cancellationToken)
|
||||
/// <param name="token"></param>
|
||||
public void Remove(string token)
|
||||
{
|
||||
using (var writeLock = new WriteLock(this.m_lockSlim))
|
||||
{
|
||||
this.m_tokenAndInstance.Remove(cancellationToken);
|
||||
}
|
||||
this.m_tokenAndInstance.TryRemove(token, out _);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -144,132 +132,105 @@ namespace ThingsGateway.Foundation
|
||||
/// <param name="messageObject"></param>
|
||||
public void Remove(IMessageObject messageObject)
|
||||
{
|
||||
using (var writeLock = new WriteLock(this.m_lockSlim))
|
||||
{
|
||||
var key = new List<string>();
|
||||
var key = new List<string>();
|
||||
|
||||
foreach (var item in this.m_tokenAndInstance.Keys)
|
||||
foreach (var item in this.m_tokenAndInstance.Keys)
|
||||
{
|
||||
foreach (var item2 in this.m_tokenAndInstance[item].ToArray())
|
||||
{
|
||||
foreach (var item2 in this.m_tokenAndInstance[item].ToArray())
|
||||
if (messageObject == item2.MessageObject)
|
||||
{
|
||||
if (messageObject == item2.MessageObject)
|
||||
this.m_tokenAndInstance[item].Remove(item2);
|
||||
if (this.m_tokenAndInstance[item].Count == 0)
|
||||
{
|
||||
this.m_tokenAndInstance[item].Remove(item2);
|
||||
if (this.m_tokenAndInstance[item].Count == 0)
|
||||
{
|
||||
key.Add(item);
|
||||
}
|
||||
key.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in key)
|
||||
{
|
||||
this.m_tokenAndInstance.Remove(item);
|
||||
}
|
||||
foreach (var item in key)
|
||||
{
|
||||
this.m_tokenAndInstance.TryRemove(item, out _);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <exception cref="MessageNotFoundException"></exception>
|
||||
public Task SendAsync(string cancellationToken, params object[] parameters)
|
||||
public async Task SendAsync(string token, params object[] parameters)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
using (var readLock = new ReadLock(this.m_lockSlim))
|
||||
{
|
||||
if (this.m_tokenAndInstance.TryGetValue(cancellationToken, out var list))
|
||||
{
|
||||
var clear = new List<MessageInstance>();
|
||||
if (this.m_tokenAndInstance.TryGetValue(token, out var list))
|
||||
{
|
||||
var clear = new List<MessageInstance>();
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (!item.Info.IsStatic && !item.WeakReference.TryGetTarget(out _))
|
||||
{
|
||||
clear.Add(item);
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
item.Invoke(item.MessageObject, parameters);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (!item.Info.IsStatic && !item.WeakReference.TryGetTarget(out _))
|
||||
{
|
||||
clear.Add(item);
|
||||
continue;
|
||||
}
|
||||
await item.InvokeAsync(item.MessageObject, parameters);
|
||||
}
|
||||
|
||||
foreach (var item in clear)
|
||||
{
|
||||
list.Remove(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessageNotFoundException(TouchSocketCoreResource.MessageNotFound.GetDescription(cancellationToken));
|
||||
}
|
||||
}
|
||||
});
|
||||
foreach (var item in clear)
|
||||
{
|
||||
list.Remove(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessageNotFoundException(TouchSocketCoreResource.MessageNotFound.GetDescription(token));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息,当多播时,只返回最后一个返回值
|
||||
/// </summary>
|
||||
/// <typeparam name="T">返回值类型</typeparam>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="MessageNotFoundException"></exception>
|
||||
public Task<T> SendAsync<T>(string cancellationToken, params object[] parameters)
|
||||
public async Task<T> SendAsync<T>(string token, params object[] parameters)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
using (var readLock = new ReadLock(this.m_lockSlim))
|
||||
{
|
||||
if (this.m_tokenAndInstance.TryGetValue(cancellationToken, out var list))
|
||||
{
|
||||
T result = default;
|
||||
var clear = new List<MessageInstance>();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
if (!item.Info.IsStatic && !item.WeakReference.TryGetTarget(out _))
|
||||
{
|
||||
clear.Add(item);
|
||||
continue;
|
||||
}
|
||||
if (this.m_tokenAndInstance.TryGetValue(token, out var list))
|
||||
{
|
||||
T result = default;
|
||||
var clear = new List<MessageInstance>();
|
||||
for (var i = 0; i < list.Count; i++)
|
||||
{
|
||||
var item = list[i];
|
||||
if (!item.Info.IsStatic && !item.WeakReference.TryGetTarget(out _))
|
||||
{
|
||||
clear.Add(item);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (i == list.Count - 1)
|
||||
{
|
||||
result = (T)item.Invoke(item.MessageObject, parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Invoke(item.MessageObject, parameters);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
if (i == list.Count - 1)
|
||||
{
|
||||
result = await item.InvokeAsync<T>(item.MessageObject, parameters);
|
||||
}
|
||||
else
|
||||
{
|
||||
await item.InvokeAsync<T>(item.MessageObject, parameters);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var item in clear)
|
||||
{
|
||||
list.Remove(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessageNotFoundException(TouchSocketCoreResource.MessageNotFound.GetDescription(cancellationToken));
|
||||
}
|
||||
}
|
||||
});
|
||||
foreach (var item in clear)
|
||||
{
|
||||
list.Remove(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MessageNotFoundException(TouchSocketCoreResource.MessageNotFound.GetDescription(token));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Reflection;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// AppMessengerExtensions
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 限定消息的接口
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Reflection;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// MessageInstance
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存实体
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// CacheExtensions
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存键值
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存实体接口
|
||||
|
@@ -25,7 +25,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 一个简单的内存缓存
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 安全双向字典
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 线程安全的List,其基本操作和List一致。
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 三元组合
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 智能安全队列
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 队列数据
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 触发器队列
|
||||
|
@@ -25,7 +25,7 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// IgnoreCaseNameValueCollection
|
||||
|
@@ -25,7 +25,7 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// NameValueCollectionDebugView
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行配置类
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="decimal"/>与字节数组转换
|
||||
|
@@ -24,7 +24,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 具有释放的对象。
|
||||
|
@@ -10,7 +10,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
#endregion
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态构建类型
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 大小端类型
|
||||
|
@@ -23,7 +23,7 @@
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ThingsGateway.Foundation
|
||||
namespace ThingsGateway.Foundation.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果类型
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user