修改代码

This commit is contained in:
cli 2024-10-08 15:06:08 +08:00
parent e45ada07a8
commit a481c1dc3e
4 changed files with 26 additions and 13 deletions

View File

@ -15,4 +15,8 @@
<Folder Include="Extensions\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
</ItemGroup>
</Project>

View File

@ -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<IProtocolPlugin>(protocolType);
client.Logger.Info($"{protocolPlugin?.Get().Name},{protocolPlugin?.Get().RegularExpression}");
//从客户端收到信息

View File

@ -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();
}

View File

@ -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()