@@ -2,6 +2,7 @@ | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Session; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -13,7 +14,7 @@ namespace JT808.DotNetty.SimpleServer.Handlers | |||
{ | |||
public JT808MsgIdTcpSimpleHandler( | |||
ILoggerFactory loggerFactory, | |||
JT808TcpSessionManager sessionManager) : base(sessionManager) | |||
JT808SessionManager sessionManager) : base(sessionManager) | |||
{ | |||
logger = loggerFactory.CreateLogger<JT808MsgIdTcpSimpleHandler>(); | |||
} | |||
@@ -25,29 +25,21 @@ | |||
/// </summary> | |||
public static string SessionTcpGetAll = $"{RouteTablePrefix}/{TcpPrefix}/{SessionPrefix}/GetAll"; | |||
/// <summary> | |||
/// 基于Tcp的会话服务-通过设备终端号移除对应会话 | |||
/// 会话服务-通过设备终端号移除对应会话 | |||
/// </summary> | |||
public static string SessionTcpRemoveByTerminalPhoneNo = $"{RouteTablePrefix}/{TcpPrefix}/{SessionPrefix}/RemoveByTerminalPhoneNo"; | |||
public static string SessionRemoveByTerminalPhoneNo = $"{RouteTablePrefix}/{SessionPrefix}/RemoveByTerminalPhoneNo"; | |||
/// <summary> | |||
/// 基于Tcp的统一下发信息 | |||
/// 统一下发信息 | |||
/// </summary> | |||
public static string UnificationTcpSend = $"{RouteTablePrefix}/{TcpPrefix}/UnificationSend"; | |||
public static string UnificationSend = $"{RouteTablePrefix}/UnificationSend"; | |||
/// <summary> | |||
/// 获取Udp包计数器 | |||
/// </summary> | |||
public static string GetUdpAtomicCounter = $"{RouteTablePrefix}/{UdpPrefix}/GetAtomicCounter"; | |||
/// <summary> | |||
/// 基于Udp的统一下发信息 | |||
/// </summary> | |||
public static string UnificationUdpSend = $"{RouteTablePrefix}/{UdpPrefix}/UnificationSend"; | |||
/// <summary> | |||
/// 基于Udp的会话服务集合 | |||
/// </summary> | |||
public static string SessionUdpGetAll = $"{RouteTablePrefix}/{UdpPrefix}/{SessionPrefix}/GetAll"; | |||
/// <summary> | |||
/// 基于Udp的会话服务-通过设备终端号移除对应会话 | |||
/// </summary> | |||
public static string SessionUdpRemoveByTerminalPhoneNo = $"{RouteTablePrefix}/{UdpPrefix}/{SessionPrefix}/RemoveByTerminalPhoneNo"; | |||
} | |||
} | |||
} |
@@ -2,6 +2,7 @@ | |||
using System.Collections.Generic; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Session; | |||
using JT808.Protocol.Enums; | |||
using JT808.Protocol.Extensions; | |||
using JT808.Protocol.MessageBody; | |||
@@ -18,11 +19,11 @@ namespace JT808.DotNetty.Core.Handlers | |||
/// </summary> | |||
public abstract class JT808MsgIdTcpHandlerBase | |||
{ | |||
protected JT808TcpSessionManager sessionManager { get; } | |||
protected JT808SessionManager sessionManager { get; } | |||
/// <summary> | |||
/// 初始化消息处理业务 | |||
/// </summary> | |||
protected JT808MsgIdTcpHandlerBase(JT808TcpSessionManager sessionManager) | |||
protected JT808MsgIdTcpHandlerBase(JT808SessionManager sessionManager) | |||
{ | |||
this.sessionManager = sessionManager; | |||
HandlerDict = new Dictionary<ushort, Func<JT808Request, IJT808Reply>> | |||
@@ -2,6 +2,7 @@ | |||
using System.Collections.Generic; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Session; | |||
using JT808.Protocol.Enums; | |||
using JT808.Protocol.Extensions; | |||
using JT808.Protocol.MessageBody; | |||
@@ -18,11 +19,11 @@ namespace JT808.DotNetty.Core.Handlers | |||
/// </summary> | |||
public abstract class JT808MsgIdUdpHandlerBase | |||
{ | |||
protected JT808UdpSessionManager sessionManager { get; } | |||
protected JT808SessionManager sessionManager { get; } | |||
/// <summary> | |||
/// 初始化消息处理业务 | |||
/// </summary> | |||
protected JT808MsgIdUdpHandlerBase(JT808UdpSessionManager sessionManager) | |||
protected JT808MsgIdUdpHandlerBase(JT808SessionManager sessionManager) | |||
{ | |||
this.sessionManager = sessionManager; | |||
HandlerDict = new Dictionary<ushort, Func<JT808Request, IJT808Reply>> | |||
@@ -6,7 +6,7 @@ namespace JT808.DotNetty.Core.Interfaces | |||
/// <summary> | |||
/// 基于udp的创建发送包 | |||
/// </summary> | |||
interface IJT808DatagramPacket | |||
public interface IJT808DatagramPacket | |||
{ | |||
DatagramPacket Create(byte[] message, EndPoint recipient); | |||
} | |||
@@ -6,15 +6,20 @@ using System.Text; | |||
namespace JT808.DotNetty.Core.Interfaces | |||
{ | |||
/// <summary> | |||
/// JT808 Tcp会话服务 | |||
/// JT808会话服务 | |||
/// </summary> | |||
public interface IJT808TcpSessionService | |||
public interface IJT808SessionService | |||
{ | |||
/// <summary> | |||
/// 获取会话集合 | |||
/// 获取udp会话集合 | |||
/// </summary> | |||
/// <returns></returns> | |||
JT808ResultDto<List<JT808TcpSessionInfoDto>> GetAll(); | |||
JT808ResultDto<List<JT808UdpSessionInfoDto>> GetUdpAll(); | |||
/// <summary> | |||
/// 获取tcp会话集合 | |||
/// </summary> | |||
/// <returns></returns> | |||
JT808ResultDto<List<JT808TcpSessionInfoDto>> GetTcpAll(); | |||
/// <summary> | |||
/// 通过设备终端号移除对应会话 | |||
/// </summary> |
@@ -9,7 +9,5 @@ namespace JT808.DotNetty.Core.Interfaces | |||
{ | |||
IJT808NettyBuilder Instance { get; } | |||
IJT808NettyBuilder Builder(); | |||
IJT808TcpNettyBuilder ReplaceSessionService<T>() where T : IJT808TcpSessionService; | |||
IJT808TcpNettyBuilder ReplaceUnificationSendService<T>() where T : IJT808UnificationTcpSendService; | |||
} | |||
} |
@@ -9,7 +9,5 @@ namespace JT808.DotNetty.Core.Interfaces | |||
{ | |||
IJT808NettyBuilder Instance { get; } | |||
IJT808NettyBuilder Builder(); | |||
IJT808UdpNettyBuilder ReplaceSessionService<T>() where T : IJT808UdpSessionService; | |||
IJT808UdpNettyBuilder ReplaceUnificationSendService<T>() where T : IJT808UnificationUdpSendService; | |||
} | |||
} |
@@ -1,25 +0,0 @@ | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Text; | |||
namespace JT808.DotNetty.Core.Interfaces | |||
{ | |||
/// <summary> | |||
/// JT808 Udp会话服务 | |||
/// </summary> | |||
public interface IJT808UdpSessionService | |||
{ | |||
/// <summary> | |||
/// 获取会话集合 | |||
/// </summary> | |||
/// <returns></returns> | |||
JT808ResultDto<List<JT808UdpSessionInfoDto>> GetAll(); | |||
/// <summary> | |||
/// 通过设备终端号移除对应会话 | |||
/// </summary> | |||
/// <param name="terminalPhoneNo"></param> | |||
/// <returns></returns> | |||
JT808ResultDto<bool> RemoveByTerminalPhoneNo(string terminalPhoneNo); | |||
} | |||
} |
@@ -3,9 +3,9 @@ | |||
namespace JT808.DotNetty.Core.Interfaces | |||
{ | |||
/// <summary> | |||
/// JT808基于tcp的统一下发命令服务 | |||
/// JT808统一下发命令服务 | |||
/// </summary> | |||
public interface IJT808UnificationTcpSendService | |||
public interface IJT808UnificationSendService | |||
{ | |||
JT808ResultDto<bool> Send(string terminalPhoneNo, byte[] data); | |||
} |
@@ -1,12 +0,0 @@ | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
namespace JT808.DotNetty.Core.Interfaces | |||
{ | |||
/// <summary> | |||
/// JT808基于udp的统一下发命令服务 | |||
/// </summary> | |||
public interface IJT808UnificationUdpSendService | |||
{ | |||
JT808ResultDto<bool> Send(string terminalPhoneNo, byte[] data); | |||
} | |||
} |
@@ -4,6 +4,7 @@ using JT808.DotNetty.Core.Converters; | |||
using JT808.DotNetty.Core.Impls; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Services; | |||
using JT808.DotNetty.Core.Session; | |||
using JT808.DotNetty.Internal; | |||
using JT808.Protocol; | |||
using Microsoft.Extensions.Configuration; | |||
@@ -59,6 +60,9 @@ namespace JT808.DotNetty.Core | |||
IJT808NettyBuilder nettyBuilder = new JT808NettyBuilderDefault(jt808Builder); | |||
nettyBuilder.JT808Builder.Services.Configure<JT808Configuration>(configuration.GetSection("JT808Configuration")); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<JT808AtomicCounterServiceFactory>(); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<JT808SessionManager>(); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808UnificationSendService, JT808UnificationSendService>(); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808SessionService, JT808SessionService>(); | |||
return nettyBuilder; | |||
} | |||
@@ -78,6 +82,9 @@ namespace JT808.DotNetty.Core | |||
IJT808NettyBuilder nettyBuilder = new JT808NettyBuilderDefault(jt808Builder); | |||
nettyBuilder.JT808Builder.Services.Configure(jt808Options); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<JT808AtomicCounterServiceFactory>(); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<JT808SessionManager>(); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808UnificationSendService, JT808UnificationSendService>(); | |||
nettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808SessionService, JT808SessionService>(); | |||
return nettyBuilder; | |||
} | |||
} |
@@ -3,20 +3,21 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Session; | |||
namespace JT808.DotNetty.Core.Services | |||
{ | |||
internal class JT808TcpSessionService : IJT808TcpSessionService | |||
internal class JT808SessionService : IJT808SessionService | |||
{ | |||
private readonly JT808TcpSessionManager jT808SessionManager; | |||
private readonly JT808SessionManager jT808SessionManager; | |||
public JT808TcpSessionService( | |||
JT808TcpSessionManager jT808SessionManager) | |||
public JT808SessionService( | |||
JT808SessionManager jT808SessionManager) | |||
{ | |||
this.jT808SessionManager = jT808SessionManager; | |||
} | |||
public JT808ResultDto<List<JT808TcpSessionInfoDto>> GetAll() | |||
public JT808ResultDto<List<JT808TcpSessionInfoDto>> GetTcpAll() | |||
{ | |||
JT808ResultDto<List<JT808TcpSessionInfoDto>> resultDto = new JT808ResultDto<List<JT808TcpSessionInfoDto>>(); | |||
try | |||
@@ -39,6 +40,29 @@ namespace JT808.DotNetty.Core.Services | |||
return resultDto; | |||
} | |||
public JT808ResultDto<List<JT808UdpSessionInfoDto>> GetUdpAll() | |||
{ | |||
JT808ResultDto<List<JT808UdpSessionInfoDto>> resultDto = new JT808ResultDto<List<JT808UdpSessionInfoDto>>(); | |||
try | |||
{ | |||
resultDto.Data = jT808SessionManager.GetUdpAll().Select(s => new JT808UdpSessionInfoDto | |||
{ | |||
LastActiveTime = s.LastActiveTime, | |||
StartTime = s.StartTime, | |||
TerminalPhoneNo = s.TerminalPhoneNo, | |||
RemoteAddressIP = s.Sender.ToString() | |||
}).ToList(); | |||
resultDto.Code = JT808ResultCode.Ok; | |||
} | |||
catch (Exception ex) | |||
{ | |||
resultDto.Data = null; | |||
resultDto.Code = JT808ResultCode.Error; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
return resultDto; | |||
} | |||
public JT808ResultDto<bool> RemoveByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>(); |
@@ -1,73 +0,0 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
using JT808.DotNetty.Core.Interfaces; | |||
namespace JT808.DotNetty.Core.Services | |||
{ | |||
internal class JT808UdpSessionService : IJT808UdpSessionService | |||
{ | |||
private readonly JT808UdpSessionManager jT808SessionManager; | |||
public JT808UdpSessionService( | |||
JT808UdpSessionManager jT808SessionManager) | |||
{ | |||
this.jT808SessionManager = jT808SessionManager; | |||
} | |||
public JT808ResultDto<List<JT808UdpSessionInfoDto>> GetAll() | |||
{ | |||
JT808ResultDto<List<JT808UdpSessionInfoDto>> resultDto = new JT808ResultDto<List<JT808UdpSessionInfoDto>>(); | |||
try | |||
{ | |||
resultDto.Data = jT808SessionManager.GetAll().Select(s => new JT808UdpSessionInfoDto | |||
{ | |||
LastActiveTime = s.LastActiveTime, | |||
StartTime = s.StartTime, | |||
TerminalPhoneNo = s.TerminalPhoneNo, | |||
RemoteAddressIP = s.Sender.ToString() | |||
}).ToList(); | |||
resultDto.Code = JT808ResultCode.Ok; | |||
} | |||
catch (Exception ex) | |||
{ | |||
resultDto.Data = null; | |||
resultDto.Code = JT808ResultCode.Error; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
return resultDto; | |||
} | |||
public JT808ResultDto<bool> RemoveByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>(); | |||
try | |||
{ | |||
var session = jT808SessionManager.RemoveSession(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
if(session.Channel.Open) | |||
{ | |||
session.Channel.CloseAsync(); | |||
} | |||
} | |||
resultDto.Code = JT808ResultCode.Ok; | |||
resultDto.Data = true; | |||
} | |||
catch (AggregateException ex) | |||
{ | |||
resultDto.Data = false; | |||
resultDto.Code = 500; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
catch (Exception ex) | |||
{ | |||
resultDto.Data = false; | |||
resultDto.Code = JT808ResultCode.Error; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
return resultDto; | |||
} | |||
} | |||
} |
@@ -1,20 +1,16 @@ | |||
using DotNetty.Buffers; | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Services; | |||
using JT808.DotNetty.Core.Session; | |||
using System; | |||
using System.Linq; | |||
namespace JT808.DotNetty.Internal | |||
{ | |||
internal class JT808UnificationTcpSendService : IJT808UnificationTcpSendService | |||
internal class JT808UnificationSendService : IJT808UnificationSendService | |||
{ | |||
private readonly JT808TcpSessionManager jT808SessionManager; | |||
private readonly JT808SessionManager jT808SessionManager; | |||
public JT808UnificationTcpSendService( | |||
JT808TcpSessionManager jT808SessionManager) | |||
public JT808UnificationSendService( | |||
JT808SessionManager jT808SessionManager) | |||
{ | |||
this.jT808SessionManager = jT808SessionManager; | |||
} |
@@ -1,54 +0,0 @@ | |||
using DotNetty.Buffers; | |||
using DotNetty.Transport.Channels.Sockets; | |||
using JT808.DotNetty.Abstractions.Dtos; | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Services; | |||
using System; | |||
namespace JT808.DotNetty.Internal | |||
{ | |||
internal class JT808UnificationUdpSendService : IJT808UnificationUdpSendService | |||
{ | |||
private readonly JT808UdpSessionManager jT808SessionManager; | |||
private readonly IJT808DatagramPacket jT808DatagramPacket; | |||
public JT808UnificationUdpSendService( | |||
IJT808DatagramPacket jT808DatagramPacket, | |||
JT808UdpSessionManager jT808SessionManager) | |||
{ | |||
this.jT808DatagramPacket = jT808DatagramPacket; | |||
this.jT808SessionManager = jT808SessionManager; | |||
} | |||
public JT808ResultDto<bool> Send(string terminalPhoneNo, byte[] data) | |||
{ | |||
JT808ResultDto<bool> resultDto = new JT808ResultDto<bool>(); | |||
try | |||
{ | |||
var session = jT808SessionManager.GetSession(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
session.Channel.WriteAndFlushAsync(jT808DatagramPacket.Create(data, session.Sender)); | |||
resultDto.Code = JT808ResultCode.Ok; | |||
resultDto.Data = true; | |||
resultDto.Message = "Ok"; | |||
} | |||
else | |||
{ | |||
resultDto.Code = JT808ResultCode.Ok; | |||
resultDto.Data = false; | |||
resultDto.Message = "offline"; | |||
} | |||
} | |||
catch (Exception ex) | |||
{ | |||
resultDto.Data = false; | |||
resultDto.Code = JT808ResultCode.Error; | |||
resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); | |||
} | |||
return resultDto; | |||
} | |||
} | |||
} |
@@ -0,0 +1,288 @@ | |||
using DotNetty.Transport.Channels; | |||
using JT808.DotNetty.Abstractions; | |||
using JT808.DotNetty.Abstractions.Enums; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Net; | |||
using System.Text; | |||
namespace JT808.DotNetty.Core.Session | |||
{ | |||
public class JT808SessionManager | |||
{ | |||
private readonly ILogger<JT808SessionManager> logger; | |||
private readonly IJT808DatagramPacket jT808DatagramPacket; | |||
public IJT808SessionPublishing JT808SessionPublishing { get; } | |||
public ConcurrentDictionary<string, IJT808Session> Sessions { get; } | |||
public JT808SessionManager( | |||
IJT808SessionPublishing jT808SessionPublishing, | |||
ILoggerFactory loggerFactory | |||
) | |||
{ | |||
Sessions = new ConcurrentDictionary<string, IJT808Session>(StringComparer.OrdinalIgnoreCase); | |||
JT808SessionPublishing = jT808SessionPublishing; | |||
logger = loggerFactory.CreateLogger<JT808SessionManager>(); | |||
} | |||
public JT808SessionManager( | |||
IJT808SessionPublishing jT808SessionPublishing, | |||
ILoggerFactory loggerFactory, | |||
IJT808DatagramPacket jT808DatagramPacket) | |||
{ | |||
Sessions = new ConcurrentDictionary<string, IJT808Session>(StringComparer.OrdinalIgnoreCase); | |||
JT808SessionPublishing = jT808SessionPublishing; | |||
logger = loggerFactory.CreateLogger<JT808SessionManager>(); | |||
this.jT808DatagramPacket = jT808DatagramPacket; | |||
} | |||
public int SessionCount | |||
{ | |||
get | |||
{ | |||
return Sessions.Count; | |||
} | |||
} | |||
public IJT808Session GetSessionByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) | |||
return default; | |||
if (Sessions.TryGetValue(terminalPhoneNo, out IJT808Session targetSession)) | |||
{ | |||
return targetSession; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
public JT808TcpSession GetTcpSessionByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
return (JT808TcpSession)GetSessionByTerminalPhoneNo(terminalPhoneNo); | |||
} | |||
public JT808UdpSession GetUdpSessionByTerminalPhoneNo(string terminalPhoneNo) | |||
{ | |||
return (JT808UdpSession)GetSessionByTerminalPhoneNo(terminalPhoneNo); | |||
} | |||
public void Heartbeat(string terminalPhoneNo) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return; | |||
if (Sessions.TryGetValue(terminalPhoneNo, out IJT808Session oldjT808Session)) | |||
{ | |||
oldjT808Session.LastActiveTime = DateTime.Now; | |||
Sessions.TryUpdate(terminalPhoneNo, oldjT808Session, oldjT808Session); | |||
} | |||
} | |||
public bool TrySend(string terminalPhoneNo, byte[] data, out string message) | |||
{ | |||
bool isSuccessed; | |||
var session = GetSessionByTerminalPhoneNo(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
//判断转发数据是下发不了消息的 | |||
if (Sessions.Select(s => s.Value).Count(c => c.Channel.Id == session.Channel.Id) > 1) | |||
{ | |||
isSuccessed = false; | |||
message = "not support transmit data send."; | |||
} | |||
else | |||
{ | |||
if(session.TransportProtocolType== JT808TransportProtocolType.tcp) | |||
{ | |||
session.Channel.WriteAndFlushAsync(new JT808Response(data)); | |||
isSuccessed = true; | |||
message = "ok"; | |||
} | |||
else if (session.TransportProtocolType == JT808TransportProtocolType.udp) | |||
{ | |||
isSuccessed = true; | |||
message = "ok"; | |||
session.Channel.WriteAndFlushAsync(jT808DatagramPacket.Create(data, ((JT808UdpSession)session).Sender)); | |||
} | |||
else | |||
{ | |||
isSuccessed = false; | |||
message = "unknow type"; | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
isSuccessed = false; | |||
message = "offline"; | |||
} | |||
return isSuccessed; | |||
} | |||
public bool TrySend(string terminalPhoneNo, IJT808Reply reply, out string message) | |||
{ | |||
bool isSuccessed; | |||
var session = GetSessionByTerminalPhoneNo(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
//判断转发数据是下发不了消息的 | |||
if (Sessions.Select(s => s.Value).Count(c => c.Channel.Id == session.Channel.Id) > 1) | |||
{ | |||
isSuccessed = false; | |||
message = "not support transmit data send."; | |||
} | |||
else | |||
{ | |||
if (session.TransportProtocolType == JT808TransportProtocolType.tcp) | |||
{ | |||
isSuccessed = true; | |||
message = "ok"; | |||
session.Channel.WriteAndFlushAsync(reply); | |||
} | |||
else if (session.TransportProtocolType == JT808TransportProtocolType.udp) | |||
{ | |||
isSuccessed = true; | |||
message = "ok"; | |||
session.Channel.WriteAndFlushAsync(jT808DatagramPacket.Create(reply.HexData, ((JT808UdpSession)session).Sender)); | |||
} | |||
else | |||
{ | |||
isSuccessed = false; | |||
message = "unknow type"; | |||
} | |||
} | |||
} | |||
else | |||
{ | |||
isSuccessed = false; | |||
message = "offline"; | |||
} | |||
return isSuccessed; | |||
} | |||
public void TryAdd(string terminalPhoneNo, IChannel channel) | |||
{ | |||
// 解决了设备号跟通道绑定到一起,不需要用到通道本身的SessionId | |||
// 不管设备下发更改了设备终端号,只要是没有在内存中就当是新的 | |||
// 存在的问题: | |||
// 1.原先老的如何销毁 | |||
// 2.这时候用的通道是相同的,设备终端是不同的 | |||
// 当设备主动或者服务器断开以后,可以释放,这点内存忽略不计,况且更改设备号不是很频繁。 | |||
//修复第一次通过转发过来的数据,再次通过直连后通道没有改变导致下发不成功,所以每次进行通道的更新操作。 | |||
if (Sessions.TryGetValue(terminalPhoneNo, out IJT808Session oldJT808Session)) | |||
{ | |||
oldJT808Session.LastActiveTime = DateTime.Now; | |||
oldJT808Session.Channel = channel; | |||
Sessions.TryUpdate(terminalPhoneNo, oldJT808Session, oldJT808Session); | |||
} | |||
else | |||
{ | |||
JT808TcpSession jT808TcpSession = new JT808TcpSession(channel, terminalPhoneNo); | |||
if (Sessions.TryAdd(terminalPhoneNo, jT808TcpSession)) | |||
{ | |||
//使用场景: | |||
//部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接, | |||
//这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。 | |||
//有设备关联上来可以进行通知 例如:使用Redis发布订阅 | |||
JT808SessionPublishing.PublishAsync(JT808Constants.SessionOnline, jT808TcpSession.TerminalPhoneNo); | |||
} | |||
} | |||
} | |||
public void TryAdd(IChannel channel, EndPoint sender, string terminalPhoneNo) | |||
{ | |||
//1.先判断是否在缓存里面 | |||
if (Sessions.TryGetValue(terminalPhoneNo, out IJT808Session jT808UdpSession)) | |||
{ | |||
if(jT808UdpSession is JT808UdpSession convertSession) | |||
{ | |||
convertSession.LastActiveTime = DateTime.Now; | |||
convertSession.Sender = sender; | |||
convertSession.Channel = channel; | |||
Sessions.TryUpdate(terminalPhoneNo, convertSession, convertSession); | |||
} | |||
} | |||
else | |||
{ | |||
//添加缓存 | |||
//使用场景: | |||
//部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接, | |||
//这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。 | |||
//有设备关联上来可以进行通知 例如:使用Redis发布订阅 | |||
Sessions.TryAdd(terminalPhoneNo, new JT808UdpSession(channel, sender, terminalPhoneNo)); | |||
} | |||
//移动是个大的内网,不跟随下发,根本就发不出来 | |||
//移动很多卡,存储的那个socket地址端口,有效期非常短 | |||
//不速度快点下发,那个socket地址端口就可能映射到别的对应卡去了 | |||
//所以此处采用跟随设备消息下发指令 | |||
JT808SessionPublishing.PublishAsync(JT808Constants.SessionOnline, terminalPhoneNo); | |||
} | |||
public IJT808Session RemoveSession(string terminalPhoneNo) | |||
{ | |||
//设备离线可以进行通知 | |||
//使用Redis 发布订阅 | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return default; | |||
if (!Sessions.TryGetValue(terminalPhoneNo, out IJT808Session jT808Session)) | |||
{ | |||
return default; | |||
} | |||
// 处理转发过来的是数据 这时候通道对设备是1对多关系,需要清理垃圾数据 | |||
//1.用当前会话的通道Id找出通过转发过来的其他设备的终端号 | |||
var terminalPhoneNos = Sessions.Where(w => w.Value.Channel.Id == jT808Session.Channel.Id).Select(s => s.Key).ToList(); | |||
//2.存在则一个个移除 | |||
if (terminalPhoneNos.Count > 1) | |||
{ | |||
//3.移除包括当前的设备号 | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
Sessions.TryRemove(key, out IJT808Session jT808SessionRemove); | |||
} | |||
string nos = string.Join(",", terminalPhoneNos); | |||
logger.LogInformation($">>>{terminalPhoneNo}-{nos} 1-n Session Remove."); | |||
JT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline, nos); | |||
return jT808Session; | |||
} | |||
else | |||
{ | |||
if (Sessions.TryRemove(terminalPhoneNo, out IJT808Session jT808SessionRemove)) | |||
{ | |||
logger.LogInformation($">>>{terminalPhoneNo} Session Remove."); | |||
JT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline, terminalPhoneNo); | |||
return jT808SessionRemove; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
} | |||
public void RemoveSessionByChannel(IChannel channel) | |||
{ | |||
//设备离线可以进行通知 | |||
//使用Redis 发布订阅 | |||
var terminalPhoneNos = Sessions.Where(w => w.Value.Channel.Id == channel.Id).Select(s => s.Key).ToList(); | |||
if (terminalPhoneNos.Count > 0) | |||
{ | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
Sessions.TryRemove(key, out IJT808Session jT808SessionRemove); | |||
} | |||
string nos = string.Join(",", terminalPhoneNos); | |||
logger.LogInformation($">>>{nos} Channel Remove."); | |||
JT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline, nos); | |||
} | |||
} | |||
public IEnumerable<IJT808Session> GetAll() | |||
{ | |||
return Sessions.Select(s => s.Value).ToList(); | |||
} | |||
public IEnumerable<JT808TcpSession> GetTcpAll() | |||
{ | |||
return Sessions.Select(s => (JT808TcpSession)s.Value).Where(w => w.TransportProtocolType == JT808TransportProtocolType.tcp).ToList(); | |||
} | |||
public IEnumerable<JT808UdpSession> GetUdpAll() | |||
{ | |||
return Sessions.Select(s => (JT808UdpSession)s.Value).Where(w => w.TransportProtocolType == JT808TransportProtocolType.udp).ToList(); | |||
} | |||
} | |||
} |
@@ -1,211 +0,0 @@ | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using DotNetty.Transport.Channels; | |||
using JT808.DotNetty.Abstractions; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Interfaces; | |||
namespace JT808.DotNetty.Core | |||
{ | |||
/// <summary> | |||
/// JT808 Tcp会话管理 | |||
/// </summary> | |||
public class JT808TcpSessionManager | |||
{ | |||
private readonly ILogger<JT808TcpSessionManager> logger; | |||
private readonly IJT808SessionPublishing jT808SessionPublishing; | |||
public JT808TcpSessionManager( | |||
IJT808SessionPublishing jT808SessionPublishing, | |||
ILoggerFactory loggerFactory) | |||
{ | |||
this.jT808SessionPublishing = jT808SessionPublishing; | |||
logger = loggerFactory.CreateLogger<JT808TcpSessionManager>(); | |||
} | |||
private ConcurrentDictionary<string, JT808TcpSession> SessionIdDict = new ConcurrentDictionary<string, JT808TcpSession>(StringComparer.OrdinalIgnoreCase); | |||
public int SessionCount | |||
{ | |||
get | |||
{ | |||
return SessionIdDict.Count; | |||
} | |||
} | |||
public JT808TcpSession GetSession(string terminalPhoneNo) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) | |||
return default; | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808TcpSession targetSession)) | |||
{ | |||
return targetSession; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
public void Heartbeat(string terminalPhoneNo) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return; | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808TcpSession oldjT808Session)) | |||
{ | |||
oldjT808Session.LastActiveTime = DateTime.Now; | |||
SessionIdDict.TryUpdate(terminalPhoneNo, oldjT808Session, oldjT808Session); | |||
} | |||
} | |||
public bool TrySend(string terminalPhoneNo, byte[] data, out string message) | |||
{ | |||
bool isSuccessed; | |||
var session = GetSession(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
//判断转发数据是下发不了消息的 | |||
if (SessionIdDict.Select(s=>s.Value).Count(c => c.Channel.Id == session.Channel.Id) > 1) | |||
{ | |||
isSuccessed = false; | |||
message = "not support transmit data send."; | |||
} | |||
else | |||
{ | |||
session.Channel.WriteAndFlushAsync(new JT808Response(data)); | |||
isSuccessed = true; | |||
message = "ok"; | |||
} | |||
} | |||
else | |||
{ | |||
isSuccessed = false; | |||
message = "offline"; | |||
} | |||
return isSuccessed; | |||
} | |||
public bool TrySend(string terminalPhoneNo, IJT808Reply reply, out string message) | |||
{ | |||
bool isSuccessed; | |||
var session = GetSession(terminalPhoneNo); | |||
if (session != null) | |||
{ | |||
//判断转发数据是下发不了消息的 | |||
if (SessionIdDict.Select(s => s.Value).Count(c => c.Channel.Id == session.Channel.Id) > 1) | |||
{ | |||
isSuccessed = false; | |||
message = "not support transmit data send."; | |||
} | |||
else | |||
{ | |||
session.Channel.WriteAndFlushAsync(reply); | |||
isSuccessed = true; | |||
message = "ok"; | |||
} | |||
} | |||
else | |||
{ | |||
isSuccessed = false; | |||
message = "offline"; | |||
} | |||
return isSuccessed; | |||
} | |||
public void TryAdd(string terminalPhoneNo,IChannel channel) | |||
{ | |||
// 解决了设备号跟通道绑定到一起,不需要用到通道本身的SessionId | |||
// 不管设备下发更改了设备终端号,只要是没有在内存中就当是新的 | |||
// 存在的问题: | |||
// 1.原先老的如何销毁 | |||
// 2.这时候用的通道是相同的,设备终端是不同的 | |||
// 当设备主动或者服务器断开以后,可以释放,这点内存忽略不计,况且更改设备号不是很频繁。 | |||
//修复第一次通过转发过来的数据,再次通过直连后通道没有改变导致下发不成功,所以每次进行通道的更新操作。 | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808TcpSession oldJT808Session)) | |||
{ | |||
oldJT808Session.LastActiveTime = DateTime.Now; | |||
oldJT808Session.Channel = channel; | |||
SessionIdDict.TryUpdate(terminalPhoneNo, oldJT808Session, oldJT808Session); | |||
} | |||
else | |||
{ | |||
JT808TcpSession jT808TcpSession = new JT808TcpSession(channel, terminalPhoneNo); | |||
if (SessionIdDict.TryAdd(terminalPhoneNo, jT808TcpSession)) | |||
{ | |||
//使用场景: | |||
//部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接, | |||
//这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。 | |||
//有设备关联上来可以进行通知 例如:使用Redis发布订阅 | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOnline, jT808TcpSession.TerminalPhoneNo); | |||
} | |||
} | |||
} | |||
public JT808TcpSession RemoveSession(string terminalPhoneNo) | |||
{ | |||
//设备离线可以进行通知 | |||
//使用Redis 发布订阅 | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return default; | |||
if (!SessionIdDict.TryGetValue(terminalPhoneNo, out JT808TcpSession jT808Session)) | |||
{ | |||
return default; | |||
} | |||
// 处理转发过来的是数据 这时候通道对设备是1对多关系,需要清理垃圾数据 | |||
//1.用当前会话的通道Id找出通过转发过来的其他设备的终端号 | |||
var terminalPhoneNos = SessionIdDict.Where(w => w.Value.Channel.Id == jT808Session.Channel.Id).Select(s => s.Key).ToList(); | |||
//2.存在则一个个移除 | |||
if (terminalPhoneNos.Count > 1) | |||
{ | |||
//3.移除包括当前的设备号 | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
SessionIdDict.TryRemove(key, out JT808TcpSession jT808SessionRemove); | |||
} | |||
string nos = string.Join(",", terminalPhoneNos); | |||
logger.LogInformation($">>>{terminalPhoneNo}-{nos} 1-n Session Remove."); | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline, nos); | |||
return jT808Session; | |||
} | |||
else | |||
{ | |||
if (SessionIdDict.TryRemove(terminalPhoneNo, out JT808TcpSession jT808SessionRemove)) | |||
{ | |||
logger.LogInformation($">>>{terminalPhoneNo} Session Remove."); | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline,terminalPhoneNo); | |||
return jT808SessionRemove; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
} | |||
public void RemoveSessionByChannel(IChannel channel) | |||
{ | |||
//设备离线可以进行通知 | |||
//使用Redis 发布订阅 | |||
var terminalPhoneNos = SessionIdDict.Where(w => w.Value.Channel.Id == channel.Id).Select(s => s.Key).ToList(); | |||
if (terminalPhoneNos.Count > 0) | |||
{ | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
SessionIdDict.TryRemove(key, out JT808TcpSession jT808SessionRemove); | |||
} | |||
string nos = string.Join(",", terminalPhoneNos); | |||
logger.LogInformation($">>>{nos} Channel Remove."); | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline, nos); | |||
} | |||
} | |||
public IEnumerable<JT808TcpSession> GetAll() | |||
{ | |||
return SessionIdDict.Select(s => s.Value).ToList(); | |||
} | |||
} | |||
} | |||
@@ -1,139 +0,0 @@ | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Concurrent; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using JT808.DotNetty.Abstractions; | |||
using JT808.DotNetty.Core.Metadata; | |||
using DotNetty.Transport.Channels; | |||
using JT808.DotNetty.Core.Configurations; | |||
using Microsoft.Extensions.Options; | |||
using System.Net; | |||
namespace JT808.DotNetty.Core | |||
{ | |||
/// <summary> | |||
/// JT808 udp会话管理 | |||
/// 估计要轮询下 | |||
/// </summary> | |||
public class JT808UdpSessionManager | |||
{ | |||
private readonly ILogger<JT808UdpSessionManager> logger; | |||
private readonly IJT808SessionPublishing jT808SessionPublishing; | |||
private readonly IOptionsMonitor<JT808Configuration> jT808ConfigurationAccessor; | |||
public JT808UdpSessionManager( | |||
IJT808SessionPublishing jT808SessionPublishing, | |||
IOptionsMonitor<JT808Configuration> jT808ConfigurationAccessor, | |||
ILoggerFactory loggerFactory) | |||
{ | |||
this.jT808SessionPublishing = jT808SessionPublishing; | |||
logger = loggerFactory.CreateLogger<JT808UdpSessionManager>(); | |||
this.jT808ConfigurationAccessor = jT808ConfigurationAccessor; | |||
} | |||
private ConcurrentDictionary<string, JT808UdpSession> SessionIdDict = new ConcurrentDictionary<string, JT808UdpSession>(StringComparer.OrdinalIgnoreCase); | |||
public int SessionCount | |||
{ | |||
get | |||
{ | |||
return SessionIdDict.Count; | |||
} | |||
} | |||
public JT808UdpSession GetSession(string terminalPhoneNo) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) | |||
return default; | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808UdpSession targetSession)) | |||
{ | |||
return targetSession; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
public void TryAdd(IChannel channel,EndPoint sender,string terminalPhoneNo) | |||
{ | |||
//1.先判断是否在缓存里面 | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808UdpSession jT808UdpSession)) | |||
{ | |||
jT808UdpSession.LastActiveTime=DateTime.Now; | |||
jT808UdpSession.Sender = sender; | |||
jT808UdpSession.Channel = channel; | |||
SessionIdDict.TryUpdate(terminalPhoneNo, jT808UdpSession, jT808UdpSession); | |||
} | |||
else | |||
{ | |||
//添加缓存 | |||
//使用场景: | |||
//部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接, | |||
//这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。 | |||
//有设备关联上来可以进行通知 例如:使用Redis发布订阅 | |||
SessionIdDict.TryAdd(terminalPhoneNo, new JT808UdpSession(channel, sender, terminalPhoneNo)); | |||
} | |||
//移动是个大的内网,不跟随下发,根本就发不出来 | |||
//移动很多卡,存储的那个socket地址端口,有效期非常短 | |||
//不速度快点下发,那个socket地址端口就可能映射到别的对应卡去了 | |||
//所以此处采用跟随设备消息下发指令 | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOnline, terminalPhoneNo); | |||
} | |||
public void Heartbeat(string terminalPhoneNo) | |||
{ | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return; | |||
if (SessionIdDict.TryGetValue(terminalPhoneNo, out JT808UdpSession oldjT808Session)) | |||
{ | |||
oldjT808Session.LastActiveTime = DateTime.Now; | |||
SessionIdDict.TryUpdate(terminalPhoneNo, oldjT808Session, oldjT808Session); | |||
} | |||
} | |||
public JT808UdpSession RemoveSession(string terminalPhoneNo) | |||
{ | |||
//设备离线可以进行通知 | |||
//使用Redis 发布订阅 | |||
if (string.IsNullOrEmpty(terminalPhoneNo)) return default; | |||
if (!SessionIdDict.TryGetValue(terminalPhoneNo, out JT808UdpSession jT808Session)) | |||
{ | |||
return default; | |||
} | |||
if (SessionIdDict.TryRemove(terminalPhoneNo, out JT808UdpSession jT808SessionRemove)) | |||
{ | |||
logger.LogInformation($">>>{terminalPhoneNo} Session Remove."); | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline,terminalPhoneNo); | |||
return jT808SessionRemove; | |||
} | |||
else | |||
{ | |||
return default; | |||
} | |||
} | |||
public void RemoveSessionByChannel(IChannel channel) | |||
{ | |||
//设备离线可以进行通知 | |||
//使用Redis 发布订阅 | |||
var terminalPhoneNos = SessionIdDict.Where(w => w.Value.Channel.Id == channel.Id).Select(s => s.Key).ToList(); | |||
if (terminalPhoneNos.Count > 0) | |||
{ | |||
foreach (var key in terminalPhoneNos) | |||
{ | |||
SessionIdDict.TryRemove(key, out JT808UdpSession jT808SessionRemove); | |||
} | |||
string nos = string.Join(",", terminalPhoneNos); | |||
logger.LogInformation($">>>{nos} Channel Remove."); | |||
jT808SessionPublishing.PublishAsync(JT808Constants.SessionOffline, nos); | |||
} | |||
} | |||
public IEnumerable<JT808UdpSession> GetAll() | |||
{ | |||
return SessionIdDict.Select(s => s.Value).ToList(); | |||
} | |||
} | |||
} | |||
@@ -1,6 +1,7 @@ | |||
using DotNetty.Handlers.Timeout; | |||
using DotNetty.Transport.Channels; | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Core.Session; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Threading.Tasks; | |||
@@ -14,10 +15,10 @@ namespace JT808.DotNetty.Tcp.Handlers | |||
{ | |||
private readonly ILogger<JT808TcpConnectionHandler> logger; | |||
private readonly JT808TcpSessionManager jT808SessionManager; | |||
private readonly JT808SessionManager jT808SessionManager; | |||
public JT808TcpConnectionHandler( | |||
JT808TcpSessionManager jT808SessionManager, | |||
JT808SessionManager jT808SessionManager, | |||
ILoggerFactory loggerFactory) | |||
{ | |||
this.jT808SessionManager = jT808SessionManager; | |||
@@ -8,6 +8,7 @@ using JT808.DotNetty.Core.Services; | |||
using JT808.DotNetty.Abstractions.Enums; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.Protocol.Exceptions; | |||
using JT808.DotNetty.Core.Session; | |||
namespace JT808.DotNetty.Tcp.Handlers | |||
{ | |||
@@ -16,7 +17,7 @@ namespace JT808.DotNetty.Tcp.Handlers | |||
/// </summary> | |||
internal class JT808TcpServerHandler : SimpleChannelInboundHandler<byte[]> | |||
{ | |||
private readonly JT808TcpSessionManager jT808SessionManager; | |||
private readonly JT808SessionManager jT808SessionManager; | |||
private readonly JT808AtomicCounterService jT808AtomicCounterService; | |||
@@ -28,7 +29,7 @@ namespace JT808.DotNetty.Tcp.Handlers | |||
IJT808Config jT808Config, | |||
ILoggerFactory loggerFactory, | |||
JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory, | |||
JT808TcpSessionManager jT808SessionManager) | |||
JT808SessionManager jT808SessionManager) | |||
{ | |||
this.jT808SessionManager = jT808SessionManager; | |||
this.jT808AtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.tcp); | |||
@@ -21,18 +21,5 @@ namespace JT808.DotNetty.Tcp | |||
{ | |||
return Instance; | |||
} | |||
public IJT808TcpNettyBuilder ReplaceSessionService<T>() where T : IJT808TcpSessionService | |||
{ | |||
Instance.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808TcpSessionService), typeof(T), ServiceLifetime.Singleton)); | |||
return this; | |||
} | |||
public IJT808TcpNettyBuilder ReplaceUnificationSendService<T>() where T : IJT808UnificationTcpSendService | |||
{ | |||
Instance.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808UnificationTcpSendService), typeof(T), ServiceLifetime.Singleton)); | |||
return this; | |||
} | |||
} | |||
} |
@@ -21,9 +21,6 @@ namespace JT808.DotNetty.Tcp | |||
{ | |||
public static IJT808TcpNettyBuilder AddJT808TcpNettyHost(this IJT808NettyBuilder jT808NettyBuilder) | |||
{ | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808TcpSessionService, JT808TcpSessionService>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808UnificationTcpSendService, JT808UnificationTcpSendService>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<JT808TcpSessionManager>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddScoped<JT808TcpConnectionHandler>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddScoped<JT808TcpEncoder>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddScoped<JT808TcpDecoder>(); | |||
@@ -1,4 +1,5 @@ | |||
using DotNetty.Transport.Channels.Embedded; | |||
using JT808.DotNetty.Core.Session; | |||
using JT808.DotNetty.Internal; | |||
using Microsoft.Extensions.Logging; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
@@ -11,7 +12,7 @@ namespace JT808.DotNetty.Core.Test | |||
[TestClass] | |||
public class SeedTcpSession | |||
{ | |||
public JT808TcpSessionManager jT80TcpSessionManager = new JT808TcpSessionManager( | |||
public JT808SessionManager jT80TcpSessionManager = new JT808SessionManager( | |||
new JT808SessionPublishingEmptyImpl(), | |||
new LoggerFactory()); | |||
@@ -2,6 +2,7 @@ | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Session; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -13,7 +14,7 @@ namespace JT808.DotNetty.Hosting.Handlers | |||
{ | |||
public JT808MsgIdTcpCustomHandler( | |||
ILoggerFactory loggerFactory, | |||
JT808TcpSessionManager sessionManager) : base(sessionManager) | |||
JT808SessionManager sessionManager) : base(sessionManager) | |||
{ | |||
logger = loggerFactory.CreateLogger<JT808MsgIdTcpCustomHandler>(); | |||
} | |||
@@ -2,6 +2,7 @@ | |||
using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Session; | |||
using Microsoft.Extensions.Logging; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -13,7 +14,7 @@ namespace JT808.DotNetty.Hosting.Handlers | |||
{ | |||
public JT808MsgIdUdpCustomHandler( | |||
ILoggerFactory loggerFactory, | |||
JT808UdpSessionManager sessionManager) : base(sessionManager) | |||
JT808SessionManager sessionManager) : base(sessionManager) | |||
{ | |||
logger = loggerFactory.CreateLogger<JT808MsgIdUdpCustomHandler>(); | |||
} | |||
@@ -9,6 +9,7 @@ using System.Threading; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using JT808.Protocol.Extensions; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using JT808.DotNetty.Core.Session; | |||
namespace JT808.DotNetty.Tcp.Test | |||
{ | |||
@@ -64,30 +65,30 @@ namespace JT808.DotNetty.Tcp.Test | |||
[TestMethod] | |||
public void Test1() | |||
{ | |||
IJT808TcpSessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808TcpSessionService>(); | |||
var result = jT808SessionServiceDefaultImpl.GetAll(); | |||
IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
var result = jT808SessionServiceDefaultImpl.GetTcpAll(); | |||
Thread.Sleep(5000); | |||
} | |||
[TestMethod] | |||
public void Test2() | |||
{ | |||
IJT808TcpSessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808TcpSessionService>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetAll(); | |||
IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetTcpAll(); | |||
var result2 = jT808SessionServiceDefaultImpl.RemoveByTerminalPhoneNo("123456789001"); | |||
var result3 = jT808SessionServiceDefaultImpl.GetAll(); | |||
var result3 = jT808SessionServiceDefaultImpl.GetTcpAll(); | |||
} | |||
[TestMethod] | |||
public void Test3() | |||
{ | |||
// 判断通道是否关闭 | |||
IJT808TcpSessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808TcpSessionService>(); | |||
JT808TcpSessionManager jT808TcpSessionManager = ServiceProvider.GetService<JT808TcpSessionManager>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetAll(); | |||
IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
JT808SessionManager jT808TcpSessionManager = ServiceProvider.GetService<JT808SessionManager>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetTcpAll(); | |||
SimpleTcpClient1.Down(); | |||
Thread.Sleep(5000); | |||
var session = jT808TcpSessionManager.GetSession("123456789001"); | |||
var session = jT808TcpSessionManager.GetSessionByTerminalPhoneNo("123456789001"); | |||
Thread.Sleep(100000); | |||
} | |||
} | |||
@@ -19,8 +19,8 @@ namespace JT808.DotNetty.Tcp.Test | |||
{ | |||
static IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6565); | |||
private IJT808UnificationTcpSendService jT808UnificationTcpSendService; | |||
private IJT808TcpSessionService jT808SessionServiceDefaultImpl; | |||
private IJT808UnificationSendService jT808UnificationSendService; | |||
private IJT808SessionService jT808SessionServiceDefaultImpl; | |||
public JT808UnificationTcpSendServiceTest() | |||
{ | |||
@@ -56,9 +56,9 @@ namespace JT808.DotNetty.Tcp.Test | |||
[TestMethod] | |||
public void Test1() | |||
{ | |||
jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808TcpSessionService>(); | |||
jT808UnificationTcpSendService = ServiceProvider.GetService<IJT808UnificationTcpSendService>(); | |||
jT808SessionServiceDefaultImpl.GetAll(); | |||
jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
jT808UnificationSendService = ServiceProvider.GetService<IJT808UnificationSendService>(); | |||
jT808SessionServiceDefaultImpl.GetTcpAll(); | |||
string no = "123456789001"; | |||
// 文本信息包 | |||
JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.文本信息下发.Create(no, new JT808_0x8300 | |||
@@ -67,7 +67,7 @@ namespace JT808.DotNetty.Tcp.Test | |||
TextInfo = "smallchi 518" | |||
}); | |||
var data = JT808Serializer.Serialize(jT808Package2); | |||
JT808ResultDto<bool> jt808Result = jT808UnificationTcpSendService.Send(no, data); | |||
JT808ResultDto<bool> jt808Result = jT808UnificationSendService.Send(no, data); | |||
Thread.Sleep(1000); | |||
Assert.AreEqual(200, jt808Result.Code); | |||
Assert.IsTrue(jt808Result.Data); | |||
@@ -9,6 +9,7 @@ using System.Threading; | |||
using Microsoft.Extensions.DependencyInjection; | |||
using JT808.Protocol.Extensions; | |||
using Microsoft.VisualStudio.TestTools.UnitTesting; | |||
using JT808.DotNetty.Core.Session; | |||
namespace JT808.DotNetty.Udp.Test | |||
{ | |||
@@ -63,29 +64,29 @@ namespace JT808.DotNetty.Udp.Test | |||
[TestMethod] | |||
public void Test1() | |||
{ | |||
IJT808UdpSessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808UdpSessionService>(); | |||
var result = jT808SessionServiceDefaultImpl.GetAll(); | |||
IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
var result = jT808SessionServiceDefaultImpl.GetUdpAll(); | |||
} | |||
[TestMethod] | |||
public void Test2() | |||
{ | |||
IJT808UdpSessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808UdpSessionService>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetAll(); | |||
IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetUdpAll(); | |||
var result2 = jT808SessionServiceDefaultImpl.RemoveByTerminalPhoneNo("123456789001"); | |||
var result3 = jT808SessionServiceDefaultImpl.GetAll(); | |||
var result3 = jT808SessionServiceDefaultImpl.GetUdpAll(); | |||
} | |||
[TestMethod] | |||
public void Test3() | |||
{ | |||
// 判断通道是否关闭 | |||
IJT808UdpSessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808UdpSessionService>(); | |||
JT808UdpSessionManager jT808UdpSessionManager = ServiceProvider.GetService<JT808UdpSessionManager>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetAll(); | |||
IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
JT808SessionManager jT808UdpSessionManager = ServiceProvider.GetService<JT808SessionManager>(); | |||
var result1 = jT808SessionServiceDefaultImpl.GetUdpAll(); | |||
SimpleUdpClient1.Down(); | |||
var session = jT808UdpSessionManager.GetSession("123456789001"); | |||
var result3 = jT808UdpSessionManager.GetAll(); | |||
var session = jT808UdpSessionManager.GetSessionByTerminalPhoneNo("123456789001"); | |||
var result3 = jT808UdpSessionManager.GetUdpAll(); | |||
Thread.Sleep(100000); | |||
} | |||
} | |||
@@ -19,8 +19,8 @@ namespace JT808.DotNetty.Udp.Test | |||
{ | |||
static IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 818); | |||
private IJT808UnificationUdpSendService jT808UnificationUdpSendService; | |||
private IJT808UdpSessionService jT808SessionServiceDefaultImpl; | |||
private IJT808UnificationSendService jT808UnificationSendService; | |||
private IJT808SessionService jT808SessionServiceDefaultImpl; | |||
public JT808UnificationUdpSendServiceTest() | |||
{ | |||
@@ -56,9 +56,9 @@ namespace JT808.DotNetty.Udp.Test | |||
public void Test1() | |||
{ | |||
//"126 131 0 0 13 18 52 86 120 144 1 0 11 5 115 109 97 108 108 99 104 105 32 53 49 56 24 126" | |||
jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808UdpSessionService>(); | |||
jT808UnificationUdpSendService = ServiceProvider.GetService<IJT808UnificationUdpSendService>(); | |||
jT808SessionServiceDefaultImpl.GetAll(); | |||
jT808SessionServiceDefaultImpl = ServiceProvider.GetService<IJT808SessionService>(); | |||
jT808UnificationSendService = ServiceProvider.GetService<IJT808UnificationSendService>(); | |||
jT808SessionServiceDefaultImpl.GetUdpAll(); | |||
string no = "123456789001"; | |||
// 文本信息包 | |||
JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.文本信息下发.Create(no, new JT808_0x8300 | |||
@@ -67,7 +67,7 @@ namespace JT808.DotNetty.Udp.Test | |||
TextInfo = "smallchi 518" | |||
}); | |||
var data = JT808Serializer.Serialize(jT808Package2); | |||
JT808ResultDto<bool> jt808Result = jT808UnificationUdpSendService.Send(no, data); | |||
JT808ResultDto<bool> jt808Result = jT808UnificationSendService.Send(no, data); | |||
Thread.Sleep(1000); | |||
Assert.AreEqual(200, jt808Result.Code); | |||
Assert.IsTrue(jt808Result.Data); | |||
@@ -8,6 +8,7 @@ using JT808.DotNetty.Core.Services; | |||
using JT808.DotNetty.Core; | |||
using JT808.DotNetty.Abstractions.Enums; | |||
using JT808.Protocol.Interfaces; | |||
using JT808.DotNetty.Core.Session; | |||
namespace JT808.DotNetty.Udp.Handlers | |||
{ | |||
@@ -20,7 +21,7 @@ namespace JT808.DotNetty.Udp.Handlers | |||
private readonly ILogger<JT808UdpServerHandler> logger; | |||
private readonly JT808UdpSessionManager jT808UdpSessionManager; | |||
private readonly JT808SessionManager jT808UdpSessionManager; | |||
private readonly JT808Serializer JT808Serializer; | |||
@@ -28,7 +29,7 @@ namespace JT808.DotNetty.Udp.Handlers | |||
IJT808Config jT808Config, | |||
ILoggerFactory loggerFactory, | |||
JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory, | |||
JT808UdpSessionManager jT808UdpSessionManager) | |||
JT808SessionManager jT808UdpSessionManager) | |||
{ | |||
this.jT808AtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.udp); | |||
this.jT808UdpSessionManager = jT808UdpSessionManager; | |||
@@ -17,17 +17,5 @@ namespace JT808.DotNetty.Udp | |||
{ | |||
return Instance; | |||
} | |||
public IJT808UdpNettyBuilder ReplaceSessionService<T>() where T : IJT808UdpSessionService | |||
{ | |||
Instance.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808UdpSessionService), typeof(T), ServiceLifetime.Singleton)); | |||
return this; | |||
} | |||
public IJT808UdpNettyBuilder ReplaceUnificationSendService<T>() where T : IJT808UnificationUdpSendService | |||
{ | |||
Instance.JT808Builder.Services.Replace(new ServiceDescriptor(typeof(IJT808UnificationUdpSendService), typeof(T), ServiceLifetime.Singleton)); | |||
return this; | |||
} | |||
} | |||
} |
@@ -19,10 +19,7 @@ namespace JT808.DotNetty.Udp | |||
{ | |||
public static IJT808UdpNettyBuilder AddJT808UdpNettyHost(this IJT808NettyBuilder jT808NettyBuilder) | |||
{ | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808UdpSessionService, JT808UdpSessionService>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808DatagramPacket, JT808DatagramPacketImpl>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<IJT808UnificationUdpSendService, JT808UnificationUdpSendService>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddSingleton<JT808UdpSessionManager>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddScoped<JT808UdpDecoder>(); | |||
jT808NettyBuilder.JT808Builder.Services.TryAddScoped<JT808UdpServerHandler>(); | |||
jT808NettyBuilder.JT808Builder.Services.AddHostedService<JT808UdpServerHost>(); | |||
@@ -5,6 +5,7 @@ using JT808.DotNetty.Core.Handlers; | |||
using JT808.DotNetty.Core.Interfaces; | |||
using JT808.DotNetty.Core.Metadata; | |||
using JT808.DotNetty.Core.Services; | |||
using JT808.DotNetty.Internal; | |||
using Newtonsoft.Json; | |||
namespace JT808.DotNetty.WebApi.Handlers | |||
@@ -18,67 +19,23 @@ namespace JT808.DotNetty.WebApi.Handlers | |||
private readonly JT808AtomicCounterService jT808UdpAtomicCounterService; | |||
private readonly IJT808TcpSessionService jT808TcpSessionService; | |||
private readonly IJT808SessionService jT808SessionService; | |||
private readonly IJT808UdpSessionService jT808UdpSessionService; | |||
private readonly IJT808UnificationSendService jT808UnificationSendService; | |||
private readonly IJT808UnificationTcpSendService jT808UnificationTcpSendService; | |||
private readonly IJT808UnificationUdpSendService jT808UnificationUdpSendService; | |||
/// <summary> | |||
/// TCP一套注入 | |||
/// </summary> | |||
/// <param name="jT808TcpAtomicCounterService"></param> | |||
public JT808MsgIdDefaultWebApiHandler( | |||
IJT808UnificationTcpSendService jT808UnificationTcpSendService, | |||
IJT808TcpSessionService jT808TcpSessionService, | |||
IJT808UnificationSendService jT808UnificationSendService, | |||
IJT808SessionService jT808SessionService, | |||
JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory | |||
) | |||
{ | |||
this.jT808UnificationTcpSendService = jT808UnificationTcpSendService; | |||
this.jT808TcpSessionService = jT808TcpSessionService; | |||
this.jT808TcpAtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.tcp); | |||
InitTcpRoute(); | |||
} | |||
/// <summary> | |||
/// UDP一套注入 | |||
/// </summary> | |||
/// <param name="jT808UdpAtomicCounterService"></param> | |||
public JT808MsgIdDefaultWebApiHandler( | |||
IJT808UdpSessionService jT808UdpSessionService, | |||
IJT808UnificationUdpSendService jT808UnificationUdpSendService, | |||
JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory | |||
) | |||
{ | |||
this.jT808UdpSessionService = jT808UdpSessionService; | |||
this.jT808UnificationUdpSendService = jT808UnificationUdpSendService; | |||
this.jT808UdpAtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.udp); | |||
InitUdpRoute(); | |||
} | |||
/// <summary> | |||
/// 统一的一套注入 | |||
/// </summary> | |||
/// <param name="jT808TcpAtomicCounterService"></param> | |||
/// <param name="jT808UdpAtomicCounterService"></param> | |||
public JT808MsgIdDefaultWebApiHandler( | |||
IJT808UnificationTcpSendService jT808UnificationTcpSendService, | |||
IJT808UnificationUdpSendService jT808UnificationUdpSendService, | |||
IJT808TcpSessionService jT808TcpSessionService, | |||
IJT808UdpSessionService jT808UdpSessionService, | |||
JT808AtomicCounterServiceFactory jT808AtomicCounterServiceFactory | |||
) | |||
{ | |||
this.jT808UdpSessionService = jT808UdpSessionService; | |||
this.jT808UnificationTcpSendService = jT808UnificationTcpSendService; | |||
this.jT808UnificationUdpSendService = jT808UnificationUdpSendService; | |||
this.jT808TcpSessionService = jT808TcpSessionService; | |||
this.jT808UnificationSendService = jT808UnificationSendService; | |||
this.jT808SessionService = jT808SessionService; | |||
this.jT808TcpAtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.tcp); | |||
this.jT808UdpAtomicCounterService = jT808AtomicCounterServiceFactory.Create(JT808TransportProtocolType.udp); | |||
InitTcpRoute(); | |||
InitUdpRoute(); | |||
InitCommontRoute(); | |||
} | |||
/// <summary> | |||
@@ -88,7 +45,7 @@ namespace JT808.DotNetty.WebApi.Handlers | |||
/// <returns></returns> | |||
public JT808HttpResponse GetTcpSessionAll(JT808HttpRequest request) | |||
{ | |||
var result = jT808TcpSessionService.GetAll(); | |||
var result = jT808SessionService.GetTcpAll(); | |||
return CreateJT808HttpResponse(result); | |||
} | |||
@@ -97,13 +54,13 @@ namespace JT808.DotNetty.WebApi.Handlers | |||
/// </summary> | |||
/// <param name="request"></param> | |||
/// <returns></returns> | |||
public JT808HttpResponse RemoveTcpSessionByTerminalPhoneNo(JT808HttpRequest request) | |||
public JT808HttpResponse RemoveSessionByTerminalPhoneNo(JT808HttpRequest request) | |||
{ | |||
if (string.IsNullOrEmpty(request.Json)) | |||
{ | |||
return EmptyHttpResponse(); | |||
} | |||
var result = jT808TcpSessionService.RemoveByTerminalPhoneNo(request.Json); | |||
var result = jT808SessionService.RemoveByTerminalPhoneNo(request.Json); | |||
return CreateJT808HttpResponse(result); | |||
} | |||
@@ -114,22 +71,7 @@ namespace JT808.DotNetty.WebApi.Handlers | |||
/// <returns></returns> | |||
public JT808HttpResponse GetUdpSessionAll(JT808HttpRequest request) | |||
{ | |||
var result = jT808UdpSessionService.GetAll(); | |||
return CreateJT808HttpResponse(result); | |||
} | |||
/// <summary> | |||
/// 会话服务-通过设备终端号移除对应会话 | |||
/// </summary> | |||
/// <param name="request"></param> | |||
/// <returns></returns> | |||
public JT808HttpResponse RemoveUdpSessionByTerminalPhoneNo(JT808HttpRequest request) | |||
{ | |||
if (string.IsNullOrEmpty(request.Json)) | |||
{ | |||
return EmptyHttpResponse(); | |||
} | |||
var result = jT808UdpSessionService.RemoveByTerminalPhoneNo(request.Json); | |||
var result = jT808SessionService.GetUdpAll(); | |||
return CreateJT808HttpResponse(result); | |||
} | |||
@@ -168,51 +110,39 @@ namespace JT808.DotNetty.WebApi.Handlers | |||
} | |||
/// <summary> | |||
/// 基于Tcp的统一下发信息 | |||
/// 统一下发信息 | |||
/// </summary> | |||
/// <param name="request"></param> | |||
/// <returns></returns> | |||
public JT808HttpResponse UnificationTcpSend(JT808HttpRequest request) | |||
public JT808HttpResponse UnificationSend(JT808HttpRequest request) | |||
{ | |||
if (string.IsNullOrEmpty(request.Json)) | |||
{ | |||
return EmptyHttpResponse(); | |||
} | |||
JT808UnificationSendRequestDto jT808UnificationSendRequestDto = JsonConvert.DeserializeObject<JT808UnificationSendRequestDto>(request.Json); | |||
var result = jT808UnificationTcpSendService.Send(jT808UnificationSendRequestDto.TerminalPhoneNo, jT808UnificationSendRequestDto.Data); | |||
var result = jT808UnificationSendService.Send(jT808UnificationSendRequestDto.TerminalPhoneNo, jT808UnificationSendRequestDto.Data); | |||
return CreateJT808HttpResponse(result); | |||
} | |||
/// <summary> | |||
/// 基于Udp的统一下发信息 | |||
/// </summary> | |||
/// <param name="request"></param> | |||
/// <returns></returns> | |||
public JT808HttpResponse UnificationUdpSend(JT808HttpRequest request) | |||
protected virtual void InitCommontRoute() | |||
{ | |||
if (string.IsNullOrEmpty(request.Json)) | |||
{ | |||
return EmptyHttpResponse(); | |||
} | |||
JT808UnificationSendRequestDto jT808UnificationSendRequestDto = JsonConvert.DeserializeObject<JT808UnificationSendRequestDto>(request.Json); | |||
var result = jT808UnificationUdpSendService.Send(jT808UnificationSendRequestDto.TerminalPhoneNo, jT808UnificationSendRequestDto.Data); | |||
return CreateJT808HttpResponse(result); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.UnificationSend, UnificationSend); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.SessionRemoveByTerminalPhoneNo, RemoveSessionByTerminalPhoneNo); | |||
} | |||
protected virtual void InitTcpRoute() | |||
{ | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.GetTcpAtomicCounter, GetTcpAtomicCounter); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.SessionTcpGetAll, GetTcpSessionAll); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.SessionTcpRemoveByTerminalPhoneNo, RemoveTcpSessionByTerminalPhoneNo); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.UnificationTcpSend, UnificationTcpSend); | |||
} | |||
protected virtual void InitUdpRoute() | |||
{ | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.GetUdpAtomicCounter, GetUdpAtomicCounter); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.UnificationUdpSend, UnificationUdpSend); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.SessionUdpGetAll, GetUdpSessionAll); | |||
CreateRoute(JT808Constants.JT808WebApiRouteTable.SessionUdpRemoveByTerminalPhoneNo, RemoveUdpSessionByTerminalPhoneNo); | |||
} | |||
} | |||
} |