diff --git a/JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj b/JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj index 310b9fe..a83352b 100644 --- a/JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj +++ b/JiShe.CollectBus.Core/JiShe.CollectBus.Core.csproj @@ -15,4 +15,8 @@ + + + + diff --git a/JiShe.CollectBus.Core/Plugins/TcpServiceReceivedPlugin.cs b/JiShe.CollectBus.Core/Plugins/TcpServiceReceivedPlugin.cs index 6083990..cda19df 100644 --- a/JiShe.CollectBus.Core/Plugins/TcpServiceReceivedPlugin.cs +++ b/JiShe.CollectBus.Core/Plugins/TcpServiceReceivedPlugin.cs @@ -1,9 +1,11 @@ using JiShe.CollectBus.Core.Exceptions; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using JiShe.CollectBus.Protocol.Contracts.Interfaces; using TouchSocket.Core; using TouchSocket.Sockets; @@ -11,23 +13,30 @@ namespace JiShe.CollectBus.Core.Plugins { public class TcpServiceReceivedPlugin : PluginBase, ITcpReceivedPlugin, ITcpConnectingPlugin, ITcpConnectedPlugin, ITcpClosedPlugin { + private readonly IServiceProvider _serviceProvider; + + public TcpServiceReceivedPlugin(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e) { //TODO:根据指令区别是376还是645协议 - var protocolType = ""; + var protocolType = "TestProtocol"; + IProtocolPlugin? protocolPlugin; switch (protocolType) { - case "376": - //todo:登录拿到设备信息,根据设备信息使用不同的协议解析服务 - - break; - case "645": - //todo: 直接拿设备信息,根据设备信息使用不同的协议解析服务 - break; - default: - break; + //case "376": + // //todo:登录拿到设备信息,根据设备信息使用不同的协议解析服务 + // break; + //case "645": + // //todo: 直接拿设备信息,根据设备信息使用不同的协议解析服务 + // break; } + protocolPlugin = _serviceProvider.GetKeyedService(protocolType); + client.Logger.Info($"{protocolPlugin?.Get().Name},{protocolPlugin?.Get().RegularExpression}"); //从客户端收到信息 diff --git a/JiShe.CollectBus.Core/Plugins/UdpServiceReceivedPlugin.cs b/JiShe.CollectBus.Core/Plugins/UdpServiceReceivedPlugin.cs index 3f1ddfa..e98000c 100644 --- a/JiShe.CollectBus.Core/Plugins/UdpServiceReceivedPlugin.cs +++ b/JiShe.CollectBus.Core/Plugins/UdpServiceReceivedPlugin.cs @@ -10,8 +10,8 @@ namespace JiShe.CollectBus.Core.Plugins { var udpSession = client as UdpSession; - udpSession?.Logger.Info($"[TCP] 收到:{e.ByteBlock.Span.ToString(Encoding.UTF8)}"); - await udpSession.SendAsync("[TCP] 收到"); + udpSession?.Logger.Info($"[UDP] 收到:{e.ByteBlock.Span.ToString(Encoding.UTF8)}"); + await udpSession.SendAsync("[UDP] 收到"); await e.InvokeNext(); } diff --git a/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs b/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs index c2639c2..592c719 100644 --- a/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs +++ b/JiShe.CollectBus.Protocol.Test/TestProtocolPlugin.cs @@ -6,7 +6,7 @@ using Microsoft.Extensions.Caching.Distributed; namespace JiShe.CollectBus.Protocol.Test { - [ProtocolName("StandardProtocol")] + [ProtocolName("TestProtocol")] public class TestProtocolPlugin(IDistributedCache cache) : BaseProtocolPlugin(cache), ISingletonDependency { public override ProtocolInfo Get()