修改代码
This commit is contained in:
parent
e45ada07a8
commit
a481c1dc3e
@ -15,4 +15,8 @@
|
|||||||
<Folder Include="Extensions\" />
|
<Folder Include="Extensions\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\JiShe.CollectBus.Protocol.Contracts\JiShe.CollectBus.Protocol.Contracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
using JiShe.CollectBus.Core.Exceptions;
|
using JiShe.CollectBus.Core.Exceptions;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||||
using TouchSocket.Core;
|
using TouchSocket.Core;
|
||||||
using TouchSocket.Sockets;
|
using TouchSocket.Sockets;
|
||||||
|
|
||||||
@ -11,23 +13,30 @@ namespace JiShe.CollectBus.Core.Plugins
|
|||||||
{
|
{
|
||||||
public class TcpServiceReceivedPlugin : PluginBase, ITcpReceivedPlugin, ITcpConnectingPlugin, ITcpConnectedPlugin, ITcpClosedPlugin
|
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)
|
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
||||||
{
|
{
|
||||||
//TODO:根据指令区别是376还是645协议
|
//TODO:根据指令区别是376还是645协议
|
||||||
|
|
||||||
var protocolType = "";
|
var protocolType = "TestProtocol";
|
||||||
|
IProtocolPlugin? protocolPlugin;
|
||||||
switch (protocolType)
|
switch (protocolType)
|
||||||
{
|
{
|
||||||
case "376":
|
//case "376":
|
||||||
//todo:登录拿到设备信息,根据设备信息使用不同的协议解析服务
|
// //todo:登录拿到设备信息,根据设备信息使用不同的协议解析服务
|
||||||
|
// break;
|
||||||
break;
|
//case "645":
|
||||||
case "645":
|
// //todo: 直接拿设备信息,根据设备信息使用不同的协议解析服务
|
||||||
//todo: 直接拿设备信息,根据设备信息使用不同的协议解析服务
|
// break;
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>(protocolType);
|
||||||
|
client.Logger.Info($"{protocolPlugin?.Get().Name},{protocolPlugin?.Get().RegularExpression}");
|
||||||
|
|
||||||
|
|
||||||
//从客户端收到信息
|
//从客户端收到信息
|
||||||
|
|||||||
@ -10,8 +10,8 @@ namespace JiShe.CollectBus.Core.Plugins
|
|||||||
{
|
{
|
||||||
|
|
||||||
var udpSession = client as UdpSession;
|
var udpSession = client as UdpSession;
|
||||||
udpSession?.Logger.Info($"[TCP] 收到:{e.ByteBlock.Span.ToString(Encoding.UTF8)}");
|
udpSession?.Logger.Info($"[UDP] 收到:{e.ByteBlock.Span.ToString(Encoding.UTF8)}");
|
||||||
await udpSession.SendAsync("[TCP] 收到");
|
await udpSession.SendAsync("[UDP] 收到");
|
||||||
|
|
||||||
await e.InvokeNext();
|
await e.InvokeNext();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ using Microsoft.Extensions.Caching.Distributed;
|
|||||||
|
|
||||||
namespace JiShe.CollectBus.Protocol.Test
|
namespace JiShe.CollectBus.Protocol.Test
|
||||||
{
|
{
|
||||||
[ProtocolName("StandardProtocol")]
|
[ProtocolName("TestProtocol")]
|
||||||
public class TestProtocolPlugin(IDistributedCache cache) : BaseProtocolPlugin(cache), ISingletonDependency
|
public class TestProtocolPlugin(IDistributedCache cache) : BaseProtocolPlugin(cache), ISingletonDependency
|
||||||
{
|
{
|
||||||
public override ProtocolInfo Get()
|
public override ProtocolInfo Get()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user