瀏覽代碼

整理项目

tags/old
SmallChi 6 年之前
父節點
當前提交
ec702dc40a
共有 41 個檔案被更改,包括 962 行新增367 行删除
  1. +10
    -10
      src/JT809.DotNetty.Core/Clients/JT809MainClient.cs
  2. +20
    -24
      src/JT809.DotNetty.Core/Clients/JT809SubordinateClient.cs
  3. +1
    -1
      src/JT809.DotNetty.Core/Codecs/JT809Decoder.cs
  4. +1
    -1
      src/JT809.DotNetty.Core/Codecs/JT809Encoder.cs
  5. +4
    -17
      src/JT809.DotNetty.Core/Configurations/JT809Configuration.cs
  6. +29
    -0
      src/JT809.DotNetty.Core/Configurations/JT809InferiorPlatformOptions.cs
  7. +29
    -0
      src/JT809.DotNetty.Core/Configurations/JT809SuperiorPlatformOptions.cs
  8. +1
    -1
      src/JT809.DotNetty.Core/Converters/JsonIPAddressConverter.cs
  9. +1
    -1
      src/JT809.DotNetty.Core/Converters/JsonIPEndPointConverter.cs
  10. +15
    -1
      src/JT809.DotNetty.Core/Enums/JT809AtomicCounterType.cs
  11. +118
    -0
      src/JT809.DotNetty.Core/Handlers/JT809InferiorMsgIdReceiveHandlerBase.cs
  12. +95
    -0
      src/JT809.DotNetty.Core/Handlers/JT809MainClientConnectionHandler.cs
  13. +78
    -0
      src/JT809.DotNetty.Core/Handlers/JT809MainClientHandler.cs
  14. +0
    -116
      src/JT809.DotNetty.Core/Handlers/JT809MainMsgIdHandlerBase.cs
  15. +4
    -14
      src/JT809.DotNetty.Core/Handlers/JT809MainServerConnectionHandler.cs
  16. +4
    -8
      src/JT809.DotNetty.Core/Handlers/JT809MainServerHandler.cs
  17. +6
    -8
      src/JT809.DotNetty.Core/Handlers/JT809SubordinateClientConnectionHandler.cs
  18. +79
    -0
      src/JT809.DotNetty.Core/Handlers/JT809SubordinateClientHandler.cs
  19. +0
    -41
      src/JT809.DotNetty.Core/Handlers/JT809SubordinateMsgIdHandlerBase.cs
  20. +90
    -0
      src/JT809.DotNetty.Core/Handlers/JT809SubordinateServerConnectionHandler.cs
  21. +4
    -6
      src/JT809.DotNetty.Core/Handlers/JT809SubordinateServerHandler.cs
  22. +122
    -0
      src/JT809.DotNetty.Core/Handlers/JT809SuperiorMsgIdReceiveHandlerBase.cs
  23. +2
    -1
      src/JT809.DotNetty.Core/Interfaces/IJT809VerifyCodeGenerator.cs
  24. +24
    -0
      src/JT809.DotNetty.Core/Internal/JT809InferiorMsgIdReceiveDefaultHandler.cs
  25. +0
    -22
      src/JT809.DotNetty.Core/Internal/JT809MainMsgIdDefaultHandler.cs
  26. +0
    -18
      src/JT809.DotNetty.Core/Internal/JT809SubordinateMsgIdDefaultHandler.cs
  27. +23
    -0
      src/JT809.DotNetty.Core/Internal/JT809SuperiorMsgIdReceiveDefaultHandler.cs
  28. +9
    -0
      src/JT809.DotNetty.Core/JT809.DotNetty.Core.csproj
  29. +56
    -13
      src/JT809.DotNetty.Core/JT809CoreDotnettyExtensions.cs
  30. +14
    -16
      src/JT809.DotNetty.Core/Servers/JT809MainServerHost.cs
  31. +96
    -0
      src/JT809.DotNetty.Core/Servers/JT809SubordinateServerHost.cs
  32. +2
    -4
      src/JT809.DotNetty.Core/Services/JT809AtomicCounterService.cs
  33. +1
    -3
      src/JT809.DotNetty.Core/Services/JT809AtomicCounterServiceFactory.cs
  34. +1
    -1
      src/JT809.DotNetty.Core/Services/JT809SimpleSystemCollectService.cs
  35. +12
    -12
      src/JT809.DotNetty.Core/Session/JT809MainSessionManager.cs
  36. +2
    -1
      src/JT809.DotNetty.Tcp/Handlers/JT809MsgIdDefaultTcpHandler.cs
  37. +2
    -2
      src/JT809.DotNetty.Tcp/Handlers/JT809TcpConnectionHandler.cs
  38. +2
    -2
      src/JT809.DotNetty.Tcp/Handlers/JT809TcpServerHandler.cs
  39. +1
    -1
      src/JT809.DotNetty.Tcp/JT809TcpDotnettyExtensions.cs
  40. +1
    -1
      src/JT809.DotNetty.Tests/JT809.DotNetty.Tcp.Test/JT809.DotNetty.Tcp.Test.csproj
  41. +3
    -21
      src/JT809.DotNetty.sln

src/JT809.DotNetty.Core/Links/JT809MainClient.cs → src/JT809.DotNetty.Core/Clients/JT809MainClient.cs 查看文件

@@ -15,7 +15,7 @@ using System.Collections.Generic;
using System.Net;
using System.Text;

namespace JT809.DotNetty.Core.Links
namespace JT809.DotNetty.Core.Clients
{
/// <summary>
/// 主链路客户端
@@ -52,18 +52,18 @@ namespace JT809.DotNetty.Core.Links
.Handler(new ActionChannelInitializer<ISocketChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
//下级平台1分钟发送心跳
//上级平台是3分钟没有发送就断开连接
using (var scope = serviceProvider.CreateScope())
//下级平台1分钟发送心跳
//上级平台是3分钟没有发送就断开连接
using (var scope = serviceProvider.CreateScope())
{
pipeline.AddLast("jt809MainLinkTcpBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
pipeline.AddLast("jt809MainClientBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
pipeline.AddLast("jt809MainLinkSystemIdleState", new IdleStateHandler(180, 60, 200));
pipeline.AddLast("jt809MainLinkTcpEncode", scope.ServiceProvider.GetRequiredService<JT809Encoder>());
pipeline.AddLast("jt809MainLinkTcpDecode", scope.ServiceProvider.GetRequiredService<JT809Decoder>());
pipeline.AddLast("jt809MainLinkConnection", scope.ServiceProvider.GetRequiredService<JT809MainServerConnectionHandler>());
pipeline.AddLast("jt809MainClientSystemIdleState", new IdleStateHandler(180, 60, 200));
pipeline.AddLast("jt809MainClientEncode", scope.ServiceProvider.GetRequiredService<JT809Encoder>());
pipeline.AddLast("jt809MainClientDecode", scope.ServiceProvider.GetRequiredService<JT809Decoder>());
pipeline.AddLast("jt809MainClientConnection", scope.ServiceProvider.GetRequiredService<JT809MainClientConnectionHandler>());
pipeline.AddLast("jt809MainClientServer", scope.ServiceProvider.GetRequiredService<JT809MainServerHandler>());
}
}));
}

src/JT809.DotNetty.Core/Links/JT809SubordinateClient.cs → src/JT809.DotNetty.Core/Clients/JT809SubordinateClient.cs 查看文件

@@ -15,13 +15,10 @@ using JT809.Protocol.MessageBody;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace JT809.DotNetty.Core.Links
namespace JT809.DotNetty.Core.Clients
{
/// <summary>
/// 从链路客户端
@@ -57,26 +54,25 @@ namespace JT809.DotNetty.Core.Links
group = new MultithreadEventLoopGroup();
bootstrap = new Bootstrap();
bootstrap.Group(group)
.Channel<TcpSocketChannel>()
.Option(ChannelOption.TcpNodelay, true)
.Handler(new ActionChannelInitializer<ISocketChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
//下级平台1分钟发送心跳
//上级平台是3分钟没有发送就断开连接

using (var scope = serviceProvider.CreateScope())
{
pipeline.AddLast("jt809SubLinkTcpBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
pipeline.AddLast("jt809SubLinkSystemIdleState", new IdleStateHandler(180, 10, 200));
pipeline.AddLast("jt809SubLinkTcpEncode", scope.ServiceProvider.GetRequiredService<JT809Encoder>());
pipeline.AddLast("jt809SubLinkTcpDecode", scope.ServiceProvider.GetRequiredService<JT809Decoder>());
pipeline.AddLast("jt809SubLinkConnection", scope.ServiceProvider.GetRequiredService<JT809SubordinateConnectionHandler>());

}
}));
.Channel<TcpSocketChannel>()
.Option(ChannelOption.TcpNodelay, true)
.Handler(new ActionChannelInitializer<ISocketChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
//下级平台1分钟发送心跳
//上级平台是3分钟没有发送就断开连接
using (var scope = serviceProvider.CreateScope())
{
pipeline.AddLast("jt809SubClientBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
pipeline.AddLast("jt809SubClientSystemIdleState", new IdleStateHandler(180, 60, 200));
pipeline.AddLast("jt809SubClientEncode", scope.ServiceProvider.GetRequiredService<JT809Encoder>());
pipeline.AddLast("jt809SubClientDecode", scope.ServiceProvider.GetRequiredService<JT809Decoder>());
pipeline.AddLast("jt809SubClientConnection", scope.ServiceProvider.GetRequiredService<JT809SubordinateClientConnectionHandler>());
pipeline.AddLast("jt809SubClientServer", scope.ServiceProvider.GetRequiredService<JT809SubordinateClientHandler>());
}
}));
}

public async void ConnectAsync(string ip,int port,uint verifyCode,int delay=3000)

+ 1
- 1
src/JT809.DotNetty.Core/Codecs/JT809Decoder.cs 查看文件

@@ -9,7 +9,7 @@ namespace JT809.DotNetty.Core.Codecs
/// <summary>
/// JT809解码
/// </summary>
public class JT809Decoder : ByteToMessageDecoder
internal class JT809Decoder : ByteToMessageDecoder
{
protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
{


+ 1
- 1
src/JT809.DotNetty.Core/Codecs/JT809Encoder.cs 查看文件

@@ -10,7 +10,7 @@ namespace JT809.DotNetty.Core.Codecs
/// <summary>
/// JT809编码
/// </summary>
public class JT809Encoder : MessageToByteEncoder<JT809Response>
internal class JT809Encoder : MessageToByteEncoder<JT809Response>
{
protected override void Encode(IChannelHandlerContext context, JT809Response message, IByteBuffer output)
{


+ 4
- 17
src/JT809.DotNetty.Core/Configurations/JT809Configuration.cs 查看文件

@@ -6,24 +6,11 @@ namespace JT809.DotNetty.Core.Configurations
{
public class JT809Configuration
{
public int TcpPort { get; set; } = 809;
/// <summary>
/// 默认开启从链路连接客户端
/// </summary>
public bool SubordinateClientEnable { get; set; } = true;

public int QuietPeriodSeconds { get; set; } = 1;

public TimeSpan QuietPeriodTimeSpan => TimeSpan.FromSeconds(QuietPeriodSeconds);

public int ShutdownTimeoutSeconds { get; set; } = 3;

public TimeSpan ShutdownTimeoutTimeSpan => TimeSpan.FromSeconds(ShutdownTimeoutSeconds);

public int SoBacklog { get; set; } = 8192;

public int EventLoopCount { get; set; } = Environment.ProcessorCount;

public int ReaderIdleTimeSeconds { get; set; } = 180;

public int WriterIdleTimeSeconds { get; set; } = 60;

public int AllIdleTimeSeconds { get; set; } = 180;
}
}

+ 29
- 0
src/JT809.DotNetty.Core/Configurations/JT809InferiorPlatformOptions.cs 查看文件

@@ -0,0 +1,29 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.DotNetty.Core.Configurations
{
/// <summary>
/// 下级平台配置项
/// </summary>
public class JT809InferiorPlatformOptions : IOptions<JT809InferiorPlatformOptions>
{
public JT809InferiorPlatformOptions Value => this;

public int TcpPort { get; set; } = 809;

public int QuietPeriodSeconds { get; set; } = 1;

public TimeSpan QuietPeriodTimeSpan => TimeSpan.FromSeconds(QuietPeriodSeconds);

public int ShutdownTimeoutSeconds { get; set; } = 3;

public TimeSpan ShutdownTimeoutTimeSpan => TimeSpan.FromSeconds(ShutdownTimeoutSeconds);

public int SoBacklog { get; set; } = 8192;

public int EventLoopCount { get; set; } = Environment.ProcessorCount;
}
}

+ 29
- 0
src/JT809.DotNetty.Core/Configurations/JT809SuperiorPlatformOptions.cs 查看文件

@@ -0,0 +1,29 @@
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.DotNetty.Core.Configurations
{
/// <summary>
/// 上级平台配置项
/// </summary>
public class JT809SuperiorPlatformOptions : IOptions<JT809SuperiorPlatformOptions>
{
public JT809SuperiorPlatformOptions Value => this;

public int TcpPort { get; set; } = 819;

public int QuietPeriodSeconds { get; set; } = 1;

public TimeSpan QuietPeriodTimeSpan => TimeSpan.FromSeconds(QuietPeriodSeconds);

public int ShutdownTimeoutSeconds { get; set; } = 3;

public TimeSpan ShutdownTimeoutTimeSpan => TimeSpan.FromSeconds(ShutdownTimeoutSeconds);

public int SoBacklog { get; set; } = 8192;

public int EventLoopCount { get; set; } = Environment.ProcessorCount;
}
}

+ 1
- 1
src/JT809.DotNetty.Core/Converters/JsonIPAddressConverter.cs 查看文件

@@ -6,7 +6,7 @@ using System.Text;

namespace JT809.DotNetty.Core.Converters
{
public class JsonIPAddressConverter : JsonConverter
internal class JsonIPAddressConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{


+ 1
- 1
src/JT809.DotNetty.Core/Converters/JsonIPEndPointConverter.cs 查看文件

@@ -5,7 +5,7 @@ using System.Net;

namespace JT809.DotNetty.Core.Converters
{
public class JsonIPEndPointConverter: JsonConverter
internal class JsonIPEndPointConverter: JsonConverter
{
public override bool CanConvert(Type objectType)
{


+ 15
- 1
src/JT809.DotNetty.Core/Enums/JT809AtomicCounterType.cs 查看文件

@@ -6,7 +6,21 @@ namespace JT809.DotNetty.Core.Enums
{
public enum JT809AtomicCounterType
{
/// <summary>
/// 上级平台连接下级平台从链路(企业-企业)
/// </summary>
ClientSubordinate=1,
ServerMain=2
/// <summary>
/// 上级平台连接下级平台从链路(监管平台-企业)
/// </summary>
ServerSubordinate=2,
/// <summary>
/// 上级平台接收下级平台主链路(企业-企业)
/// </summary>
ServerMain =3,
/// <summary>
/// 下级平台连接上级平台主链路(企业-监管平台)
/// </summary>
ClientMain=4
}
}

+ 118
- 0
src/JT809.DotNetty.Core/Handlers/JT809InferiorMsgIdReceiveHandlerBase.cs 查看文件

@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using JT809.DotNetty.Core.Configurations;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Clients;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol.Enums;
using JT809.Protocol.Extensions;
using JT809.Protocol.MessageBody;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 下级平台
/// 主从链路接收消息处理程序
/// </summary>
public abstract class JT809InferiorMsgIdReceiveHandlerBase
{
protected JT809Configuration Configuration { get; }
protected ILogger Logger { get; }
/// <summary>
/// 初始化消息处理业务
/// </summary>
protected JT809InferiorMsgIdReceiveHandlerBase(
ILoggerFactory loggerFactory,
IOptions<JT809Configuration> jT809ConfigurationAccessor,
IJT809VerifyCodeGenerator verifyCodeGenerator,
JT809SubordinateClient subordinateLinkClient)
{
this.Logger = loggerFactory.CreateLogger<JT809SuperiorMsgIdReceiveHandlerBase>();
HandlerDict = new Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>>
{
//{JT809BusinessType.主链路登录请求消息, Msg0x1001},
{JT809BusinessType.主链路注销请求消息, Msg0x1003},
{JT809BusinessType.主链路连接保持请求消息, Msg0x1005},
{JT809BusinessType.主链路动态信息交换消息, Msg0x1200},

{JT809BusinessType.从链路注销应答消息, Msg0x9004},
};

SubHandlerDict = new Dictionary<JT809SubBusinessType, Func<JT809Request, JT809Response>>
{
//{JT809SubBusinessType.实时上传车辆定位信息, Msg0x1200_0x1202},
};
}

public Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>> HandlerDict { get; protected set; }

public Dictionary<JT809SubBusinessType, Func<JT809Request, JT809Response>> SubHandlerDict { get; protected set; }

/// <summary>
/// 主链路登录请求消息
/// </summary>
/// <param name="request"></param>
/// <returns>主链路登录应答消息</returns>
//public virtual JT809Response Msg0x1001(JT809Request request)
//{
// var verifyCode = VerifyCodeGenerator.Create();
// Logger.LogInformation($"VerifyCode-{verifyCode}");
// var package = JT809BusinessType.主链路登录应答消息.Create(new JT809_0x1002()
// {
// Result = JT809_0x1002_Result.成功,
// VerifyCode = verifyCode
// });
// if (Configuration.SubordinateClientEnable)
// {
// var jT809_0x1001 = request.Package.Bodies as JT809_0x1001;
// SubordinateLinkClient.ConnectAsync(jT809_0x1001.DownLinkIP, jT809_0x1001.DownLinkPort, verifyCode);
// }
// return new JT809Response(package, 100);
//}

/// <summary>
/// 主链路注销请求消息
/// </summary>
/// <param name="request"></param>
/// <returns>主链路注销应答消息</returns>
public virtual JT809Response Msg0x1003(JT809Request request)
{
var package = JT809BusinessType.主链路注销应答消息.Create();
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路连接保持请求消息
/// </summary>
/// <param name="request"></param>
/// <returns>主链路连接保持应答消息</returns>
public virtual JT809Response Msg0x1005(JT809Request request)
{
var package = JT809BusinessType.主链路连接保持应答消息.Create();
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路动态信息交换消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x1200(JT809Request request)
{

return null;
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns>从链路注销应答消息</returns>
public virtual JT809Response Msg0x9004(JT809Request request)
{
return null;
}
}
}

+ 95
- 0
src/JT809.DotNetty.Core/Handlers/JT809MainClientConnectionHandler.cs 查看文件

@@ -0,0 +1,95 @@
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Channels;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol.Enums;
using JT809.Protocol.Extensions;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// JT809主链路客户端连接处理器
/// </summary>
internal class JT809MainClientConnectionHandler : ChannelHandlerAdapter
{

private readonly ILogger<JT809MainClientConnectionHandler> logger;

public JT809MainClientConnectionHandler(
ILoggerFactory loggerFactory)
{
logger = loggerFactory.CreateLogger<JT809MainClientConnectionHandler>();
}

/// <summary>
/// 通道激活
/// </summary>
/// <param name="context"></param>
public override void ChannelActive(IChannelHandlerContext context)
{
string channelId = context.Channel.Id.AsShortText();
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug($"<<<{ channelId } Successful client connection to server.");
base.ChannelActive(context);
}

/// <summary>
/// 客户端主动断开
/// </summary>
/// <param name="context"></param>
public override void ChannelInactive(IChannelHandlerContext context)
{
string channelId = context.Channel.Id.AsShortText();
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug($">>>{ channelId } The client disconnects from the server.");
base.ChannelInactive(context);
}

/// <summary>
/// 服务器主动断开
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task CloseAsync(IChannelHandlerContext context)
{
string channelId = context.Channel.Id.AsShortText();
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug($"<<<{ channelId } The server disconnects from the client.");
return base.CloseAsync(context);
}

public override void ChannelReadComplete(IChannelHandlerContext context) => context.Flush();

/// <summary>
/// 超时策略
/// </summary>
/// <param name="context"></param>
/// <param name="evt"></param>
public override void UserEventTriggered(IChannelHandlerContext context, object evt)
{
IdleStateEvent idleStateEvent = evt as IdleStateEvent;
if (idleStateEvent != null)
{
if (idleStateEvent.State == IdleState.WriterIdle)
{
string channelId = context.Channel.Id.AsShortText();
logger.LogInformation($"{idleStateEvent.State.ToString()}>>>Heartbeat-{channelId}");
//发送主链路保持请求数据包
var package = JT809BusinessType.主链路连接保持请求消息.Create();
JT809Response jT809Response = new JT809Response(package, 100);
context.WriteAndFlushAsync(jT809Response);
}
}
base.UserEventTriggered(context, evt);
}

public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
string channelId = context.Channel.Id.AsShortText();
logger.LogError(exception, $"{channelId} {exception.Message}");
context.CloseAsync();
}
}
}

+ 78
- 0
src/JT809.DotNetty.Core/Handlers/JT809MainClientHandler.cs 查看文件

@@ -0,0 +1,78 @@
using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using JT809.Protocol;
using System;
using Microsoft.Extensions.Logging;
using JT809.Protocol.Exceptions;
using JT809.DotNetty.Core.Services;
using JT809.DotNetty.Core.Metadata;
using JT809.DotNetty.Core.Enums;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 下级平台
/// JT809主链路客户端处理程序
/// </summary>
internal class JT809MainClientHandler : SimpleChannelInboundHandler<byte[]>
{
private readonly JT809InferiorMsgIdReceiveHandlerBase handler;
private readonly JT809AtomicCounterService jT809AtomicCounterService;

private readonly ILogger<JT809MainServerHandler> logger;

public JT809MainClientHandler(
ILoggerFactory loggerFactory,
JT809InferiorMsgIdReceiveHandlerBase handler,
JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty
)
{
this.handler = handler;
this.jT809AtomicCounterService = jT809AtomicCounterServiceFactorty.Create(JT809AtomicCounterType.ClientMain.ToString());
logger = loggerFactory.CreateLogger<JT809MainServerHandler>();
}


protected override void ChannelRead0(IChannelHandlerContext ctx, byte[] msg)
{
try
{
JT809Package jT809Package = JT809Serializer.Deserialize(msg);
jT809AtomicCounterService.MsgSuccessIncrement();
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("accept package success count<<<" + jT809AtomicCounterService.MsgSuccessCount.ToString());
}
Func<JT809Request, JT809Response> handlerFunc;
if (handler.HandlerDict.TryGetValue(jT809Package.Header.BusinessType, out handlerFunc))
{
JT809Response jT808Response = handlerFunc(new JT809Request(jT809Package, msg));
if (jT808Response != null)
{
var sendData = JT809Serializer.Serialize(jT808Response.Package, jT808Response.MinBufferSize);
ctx.WriteAndFlushAsync(Unpooled.WrappedBuffer(sendData));
}
}
}
catch (JT809Exception ex)
{
jT809AtomicCounterService.MsgFailIncrement();
if (logger.IsEnabled(LogLevel.Error))
{
logger.LogError("accept package fail count<<<" + jT809AtomicCounterService.MsgFailCount.ToString());
logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg));
}
}
catch (Exception ex)
{
jT809AtomicCounterService.MsgFailIncrement();
if (logger.IsEnabled(LogLevel.Error))
{
logger.LogError("accept package fail count<<<" + jT809AtomicCounterService.MsgFailCount.ToString());
logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg));
}
}
}
}
}

+ 0
- 116
src/JT809.DotNetty.Core/Handlers/JT809MainMsgIdHandlerBase.cs 查看文件

@@ -1,116 +0,0 @@
using System;
using System.Collections.Generic;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Links;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol.Enums;
using JT809.Protocol.Extensions;
using JT809.Protocol.MessageBody;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 抽象消息处理业务
/// 自定义消息处理业务
/// 注意:
/// 1.ConfigureServices:
/// services.Replace(new ServiceDescriptor(typeof(JT809MsgIdTcpHandlerBase),typeof(JT809MsgIdCustomTcpHandlerImpl),ServiceLifetime.Singleton));
/// 2.解析具体的消息体,具体消息调用具体的JT809Serializer.Deserialize<T>
/// </summary>
public abstract class JT809MainMsgIdHandlerBase
{
protected JT809SessionManager sessionManager { get; }
protected IJT809VerifyCodeGenerator verifyCodeGenerator { get; }
protected JT809SubordinateClient subordinateLinkClient { get; }
/// <summary>
/// 初始化消息处理业务
/// </summary>
protected JT809MainMsgIdHandlerBase(
IJT809VerifyCodeGenerator verifyCodeGenerator,
JT809SubordinateClient subordinateLinkClient,
JT809SessionManager sessionManager)
{
this.sessionManager = sessionManager;
this.verifyCodeGenerator = verifyCodeGenerator;
this.subordinateLinkClient = subordinateLinkClient;
HandlerDict = new Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>>
{
{JT809BusinessType.主链路登录请求消息, Msg0x1001},
{JT809BusinessType.主链路注销请求消息, Msg0x1003},
{JT809BusinessType.主链路连接保持请求消息, Msg0x1005},
{JT809BusinessType.主链路动态信息交换消息, Msg0x1200}
};
//SubHandlerDict = new Dictionary<JT809SubBusinessType, Func<JT809Request, JT809Response>>
//{
// {JT809SubBusinessType.实时上传车辆定位信息, Msg0x1200_0x1202},
//};
}

public Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>> HandlerDict { get; protected set; }

//public Dictionary<JT809SubBusinessType, Func<JT809Request, JT809Response>> SubHandlerDict { get; protected set; }

/// <summary>
/// 主链路登录应答消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x1001(JT809Request request)
{
var verifyCode = verifyCodeGenerator.Create();
var package= JT809BusinessType.主链路登录应答消息.Create(new JT809_0x1002()
{
Result= JT809_0x1002_Result.成功,
VerifyCode= verifyCode
});
var jT809_0x1001 = request.Package.Bodies as JT809_0x1001;
subordinateLinkClient.ConnectAsync(jT809_0x1001.DownLinkIP, jT809_0x1001.DownLinkPort, verifyCode);
return new JT809Response(package,100);
}

/// <summary>
/// 主链路注销应答消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x1003(JT809Request request)
{
var package = JT809BusinessType.主链路注销应答消息.Create();
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路连接保持应答消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x1005(JT809Request request)
{
var package = JT809BusinessType.主链路连接保持应答消息.Create();
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路动态信息交换消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x1200(JT809Request request)
{
return null;
}

///// <summary>
///// 主链路动态信息交换消息
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//public virtual JT809Response Msg0x1200_0x1202(JT809Request request)
//{

// return null;
//}
}
}

+ 4
- 14
src/JT809.DotNetty.Core/Handlers/JT809MainServerConnectionHandler.cs 查看文件

@@ -1,10 +1,5 @@
using DotNetty.Buffers;
using DotNetty.Handlers.Timeout;
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Channels;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol;
using JT809.Protocol.Enums;
using JT809.Protocol.Extensions;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
@@ -14,7 +9,7 @@ namespace JT809.DotNetty.Core.Handlers
/// <summary>
/// JT809主链路服务端连接处理器
/// </summary>
public class JT809MainServerConnectionHandler : ChannelHandlerAdapter
internal class JT809MainServerConnectionHandler : ChannelHandlerAdapter
{

private readonly ILogger<JT809MainServerConnectionHandler> logger;
@@ -74,14 +69,9 @@ namespace JT809.DotNetty.Core.Handlers
IdleStateEvent idleStateEvent = evt as IdleStateEvent;
if (idleStateEvent != null)
{
if (idleStateEvent.State == IdleState.WriterIdle)
if (idleStateEvent.State == IdleState.ReaderIdle)
{
string channelId = context.Channel.Id.AsShortText();
logger.LogInformation($"{idleStateEvent.State.ToString()}>>>Heartbeat-{channelId}");
//发送主链路保持请求数据包
var package = JT809BusinessType.主链路连接保持请求消息.Create();
JT809Response jT809Response = new JT809Response(package, 100);
context.WriteAndFlushAsync(jT809Response);
context.CloseAsync();
}
}
base.UserEventTriggered(context, evt);


+ 4
- 8
src/JT809.DotNetty.Core/Handlers/JT809MainServerHandler.cs 查看文件

@@ -11,27 +11,24 @@ using JT809.DotNetty.Core.Enums;
namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 上级平台
/// JT809主链路服务端处理程序
/// </summary>
internal class JT809MainServerHandler : SimpleChannelInboundHandler<byte[]>
{
private readonly JT809MainMsgIdHandlerBase handler;
private readonly JT809SuperiorMsgIdReceiveHandlerBase handler;
private readonly JT809SessionManager jT809SessionManager;

private readonly JT809AtomicCounterService jT809AtomicCounterService;

private readonly ILogger<JT809MainServerHandler> logger;

public JT809MainServerHandler(
ILoggerFactory loggerFactory,
JT809MainMsgIdHandlerBase handler,
JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty,
JT809SessionManager jT809SessionManager
JT809SuperiorMsgIdReceiveHandlerBase handler,
JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty
)
{
this.handler = handler;
this.jT809SessionManager = jT809SessionManager;
this.jT809AtomicCounterService = jT809AtomicCounterServiceFactorty.Create(JT809AtomicCounterType.ServerMain.ToString()); ;
logger = loggerFactory.CreateLogger<JT809MainServerHandler>();
}
@@ -47,7 +44,6 @@ namespace JT809.DotNetty.Core.Handlers
{
logger.LogDebug("accept package success count<<<" + jT809AtomicCounterService.MsgSuccessCount.ToString());
}
jT809SessionManager.TryAdd(ctx.Channel, jT809Package.Header.MsgGNSSCENTERID);
Func<JT809Request, JT809Response> handlerFunc;
if (handler.HandlerDict.TryGetValue(jT809Package.Header.BusinessType, out handlerFunc))
{


src/JT809.DotNetty.Core/Handlers/JT809SubordinateConnectionHandler.cs → src/JT809.DotNetty.Core/Handlers/JT809SubordinateClientConnectionHandler.cs 查看文件

@@ -1,8 +1,6 @@
using DotNetty.Buffers;
using DotNetty.Handlers.Timeout;
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Channels;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol;
using JT809.Protocol.Enums;
using JT809.Protocol.Extensions;
using Microsoft.Extensions.Logging;
@@ -12,17 +10,17 @@ using System.Threading.Tasks;
namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// JT809从链路连接处理器
/// JT809 从链路客户端连接处理器
/// </summary>
public class JT809SubordinateConnectionHandler: ChannelHandlerAdapter
internal class JT809SubordinateClientConnectionHandler : ChannelHandlerAdapter
{

private readonly ILogger<JT809SubordinateConnectionHandler> logger;
private readonly ILogger<JT809SubordinateClientConnectionHandler> logger;

public JT809SubordinateConnectionHandler(
public JT809SubordinateClientConnectionHandler(
ILoggerFactory loggerFactory)
{
logger = loggerFactory.CreateLogger<JT809SubordinateConnectionHandler>();
logger = loggerFactory.CreateLogger<JT809SubordinateClientConnectionHandler>();
}

/// <summary>

+ 79
- 0
src/JT809.DotNetty.Core/Handlers/JT809SubordinateClientHandler.cs 查看文件

@@ -0,0 +1,79 @@
using DotNetty.Buffers;
using DotNetty.Transport.Channels;
using JT809.Protocol;
using System;
using Microsoft.Extensions.Logging;
using JT809.Protocol.Exceptions;
using JT809.DotNetty.Core.Services;
using JT809.DotNetty.Core;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Metadata;
using JT809.DotNetty.Core.Internal;
using JT809.DotNetty.Core.Enums;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// JT809从链路客户端业务处理程序
/// </summary>
internal class JT809SubordinateClientHandler : SimpleChannelInboundHandler<byte[]>
{
private readonly JT809SuperiorMsgIdReceiveHandlerBase handler;
private readonly JT809AtomicCounterService jT809AtomicCounterService;

private readonly ILogger<JT809SubordinateServerHandler> logger;

public JT809SubordinateClientHandler(
ILoggerFactory loggerFactory,
JT809SuperiorMsgIdReceiveHandlerBase handler,
JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty
)
{
this.handler = handler;
this.jT809AtomicCounterService = jT809AtomicCounterServiceFactorty.Create(JT809AtomicCounterType.ClientSubordinate.ToString());
logger = loggerFactory.CreateLogger<JT809SubordinateServerHandler>();
}


protected override void ChannelRead0(IChannelHandlerContext ctx, byte[] msg)
{
try
{
JT809Package jT809Package = JT809Serializer.Deserialize(msg);
jT809AtomicCounterService.MsgSuccessIncrement();
if (logger.IsEnabled(LogLevel.Debug))
{
logger.LogDebug("accept package success count<<<" + jT809AtomicCounterService.MsgSuccessCount.ToString());
}
Func<JT809Request, JT809Response> handlerFunc;
if (handler.HandlerDict.TryGetValue(jT809Package.Header.BusinessType, out handlerFunc))
{
JT809Response jT808Response = handlerFunc(new JT809Request(jT809Package, msg));
if (jT808Response != null)
{
ctx.WriteAndFlushAsync(jT808Response);
}
}
}
catch (JT809Exception ex)
{
jT809AtomicCounterService.MsgFailIncrement();
if (logger.IsEnabled(LogLevel.Error))
{
logger.LogError("accept package fail count<<<" + jT809AtomicCounterService.MsgFailCount.ToString());
logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg));
}
}
catch (Exception ex)
{
jT809AtomicCounterService.MsgFailIncrement();
if (logger.IsEnabled(LogLevel.Error))
{
logger.LogError("accept package fail count<<<" + jT809AtomicCounterService.MsgFailCount.ToString());
logger.LogError(ex, "accept msg<<<" + ByteBufferUtil.HexDump(msg));
}
}
}
}
}

+ 0
- 41
src/JT809.DotNetty.Core/Handlers/JT809SubordinateMsgIdHandlerBase.cs 查看文件

@@ -1,41 +0,0 @@
using System;
using System.Collections.Generic;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol.Enums;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 抽象从链路消息处理业务
/// 自定义消息处理业务
/// 注意:
/// 1.ConfigureServices:
/// services.Replace(new ServiceDescriptor(typeof(JT809SubordinateMsgIdTcpHandlerBase),typeof(JT809SubordinateMsgIdCustomTcpHandlerImpl),ServiceLifetime.Singleton));
/// 2.解析具体的消息体,具体消息调用具体的JT809Serializer.Deserialize<T>
/// </summary>
public abstract class JT809SubordinateMsgIdHandlerBase
{
/// <summary>
/// 初始化消息处理业务
/// </summary>
protected JT809SubordinateMsgIdHandlerBase()
{
HandlerDict = new Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>>
{
{JT809BusinessType.从链路注销应答消息, Msg0x9004},
};
}

public Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>> HandlerDict { get; protected set; }

/// <summary>
/// 从链路注销应答消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x9004(JT809Request request)
{
return null;
}
}
}

+ 90
- 0
src/JT809.DotNetty.Core/Handlers/JT809SubordinateServerConnectionHandler.cs 查看文件

@@ -0,0 +1,90 @@
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Channels;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// JT809 从链路服务端连接处理器
/// </summary>
internal class JT809SubordinateServerConnectionHandler: ChannelHandlerAdapter
{

private readonly ILogger<JT809SubordinateServerConnectionHandler> logger;

public JT809SubordinateServerConnectionHandler(
ILoggerFactory loggerFactory)
{
logger = loggerFactory.CreateLogger<JT809SubordinateServerConnectionHandler>();
}

/// <summary>
/// 通道激活
/// </summary>
/// <param name="context"></param>
public override void ChannelActive(IChannelHandlerContext context)
{
string channelId = context.Channel.Id.AsShortText();
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug($"<<<{ channelId } Successful client connection to server.");
base.ChannelActive(context);
}

/// <summary>
/// 客户端主动断开
/// </summary>
/// <param name="context"></param>
public override void ChannelInactive(IChannelHandlerContext context)
{
string channelId = context.Channel.Id.AsShortText();
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug($">>>{ channelId } The client disconnects from the server.");
base.ChannelInactive(context);
}

/// <summary>
/// 服务器主动断开
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override Task CloseAsync(IChannelHandlerContext context)
{
string channelId = context.Channel.Id.AsShortText();
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug($"<<<{ channelId } The server disconnects from the client.");
return base.CloseAsync(context);
}

public override void ChannelReadComplete(IChannelHandlerContext context) => context.Flush();

/// <summary>
/// 超时策略
/// </summary>
/// <param name="context"></param>
/// <param name="evt"></param>
public override void UserEventTriggered(IChannelHandlerContext context, object evt)
{
IdleStateEvent idleStateEvent = evt as IdleStateEvent;
if (idleStateEvent != null)
{
if (idleStateEvent.State == IdleState.ReaderIdle)
{
if (idleStateEvent.State == IdleState.ReaderIdle)
{
context.CloseAsync();
}
}
}
base.UserEventTriggered(context, evt);
}

public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
{
string channelId = context.Channel.Id.AsShortText();
logger.LogError(exception, $"{channelId} {exception.Message}");
context.CloseAsync();
}
}
}

+ 4
- 6
src/JT809.DotNetty.Core/Handlers/JT809SubordinateServerHandler.cs 查看文件

@@ -5,20 +5,18 @@ using System;
using Microsoft.Extensions.Logging;
using JT809.Protocol.Exceptions;
using JT809.DotNetty.Core.Services;
using JT809.DotNetty.Core;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Metadata;
using JT809.DotNetty.Core.Internal;
using JT809.DotNetty.Core.Enums;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 下级平台
/// JT809从链路业务处理程序
/// </summary>
internal class JT809SubordinateServerHandler : SimpleChannelInboundHandler<byte[]>
{
private readonly JT809SubordinateMsgIdHandlerBase handler;
private readonly JT809InferiorMsgIdReceiveHandlerBase handler;
private readonly JT809AtomicCounterService jT809AtomicCounterService;

@@ -26,12 +24,12 @@ namespace JT809.DotNetty.Core.Handlers

public JT809SubordinateServerHandler(
ILoggerFactory loggerFactory,
JT809SubordinateMsgIdHandlerBase handler,
JT809InferiorMsgIdReceiveHandlerBase handler,
JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty
)
{
this.handler = handler;
this.jT809AtomicCounterService = jT809AtomicCounterServiceFactorty.Create(JT809AtomicCounterType.ClientSubordinate.ToString());
this.jT809AtomicCounterService = jT809AtomicCounterServiceFactorty.Create(JT809AtomicCounterType.ServerSubordinate.ToString());
logger = loggerFactory.CreateLogger<JT809SubordinateServerHandler>();
}



+ 122
- 0
src/JT809.DotNetty.Core/Handlers/JT809SuperiorMsgIdReceiveHandlerBase.cs 查看文件

@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using JT809.DotNetty.Core.Configurations;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Clients;
using JT809.DotNetty.Core.Metadata;
using JT809.Protocol.Enums;
using JT809.Protocol.Extensions;
using JT809.Protocol.MessageBody;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace JT809.DotNetty.Core.Handlers
{
/// <summary>
/// 上级平台
/// 主从链路接收消息处理程序
/// </summary>
public abstract class JT809SuperiorMsgIdReceiveHandlerBase
{
protected IJT809VerifyCodeGenerator VerifyCodeGenerator { get; }
protected JT809SubordinateClient SubordinateLinkClient { get; }
protected JT809Configuration Configuration { get; }
protected ILogger Logger { get; }
/// <summary>
/// 初始化消息处理业务
/// </summary>
protected JT809SuperiorMsgIdReceiveHandlerBase(
ILoggerFactory loggerFactory,
IOptions<JT809Configuration> jT809ConfigurationAccessor,
IJT809VerifyCodeGenerator verifyCodeGenerator,
JT809SubordinateClient subordinateLinkClient)
{
this.Logger = loggerFactory.CreateLogger<JT809SuperiorMsgIdReceiveHandlerBase>();
this.VerifyCodeGenerator = verifyCodeGenerator;
this.SubordinateLinkClient = subordinateLinkClient;
HandlerDict = new Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>>
{
{JT809BusinessType.主链路登录请求消息, Msg0x1001},
{JT809BusinessType.主链路注销请求消息, Msg0x1003},
{JT809BusinessType.主链路连接保持请求消息, Msg0x1005},
{JT809BusinessType.主链路动态信息交换消息, Msg0x1200},

{JT809BusinessType.从链路注销应答消息, Msg0x9004},
};

SubHandlerDict = new Dictionary<JT809SubBusinessType, Func<JT809Request, JT809Response>>
{
//{JT809SubBusinessType.实时上传车辆定位信息, Msg0x1200_0x1202},
};
}

public Dictionary<JT809BusinessType, Func<JT809Request, JT809Response>> HandlerDict { get; protected set; }

public Dictionary<JT809SubBusinessType, Func<JT809Request, JT809Response>> SubHandlerDict { get; protected set; }

/// <summary>
/// 主链路登录请求消息
/// </summary>
/// <param name="request"></param>
/// <returns>主链路登录应答消息</returns>
public virtual JT809Response Msg0x1001(JT809Request request)
{
var verifyCode = VerifyCodeGenerator.Create();
Logger.LogInformation($"VerifyCode-{verifyCode}");
var package = JT809BusinessType.主链路登录应答消息.Create(new JT809_0x1002()
{
Result = JT809_0x1002_Result.成功,
VerifyCode = verifyCode
});
if (Configuration.SubordinateClientEnable)
{
var jT809_0x1001 = request.Package.Bodies as JT809_0x1001;
SubordinateLinkClient.ConnectAsync(jT809_0x1001.DownLinkIP, jT809_0x1001.DownLinkPort, verifyCode);
}
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路注销请求消息
/// </summary>
/// <param name="request"></param>
/// <returns>主链路注销应答消息</returns>
public virtual JT809Response Msg0x1003(JT809Request request)
{
var package = JT809BusinessType.主链路注销应答消息.Create();
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路连接保持请求消息
/// </summary>
/// <param name="request"></param>
/// <returns>主链路连接保持应答消息</returns>
public virtual JT809Response Msg0x1005(JT809Request request)
{
var package = JT809BusinessType.主链路连接保持应答消息.Create();
return new JT809Response(package, 100);
}

/// <summary>
/// 主链路动态信息交换消息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public virtual JT809Response Msg0x1200(JT809Request request)
{

return null;
}

/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns>从链路注销应答消息</returns>
public virtual JT809Response Msg0x9004(JT809Request request)
{
return null;
}
}
}

+ 2
- 1
src/JT809.DotNetty.Core/Interfaces/IJT809VerifyCodeGenerator.cs 查看文件

@@ -6,8 +6,9 @@ namespace JT809.DotNetty.Core.Interfaces
{
/// <summary>
/// 校验码生成器
/// 注:上级平台使用
/// </summary>
public interface IJT809VerifyCodeGenerator
public interface IJT809VerifyCodeGenerator
{
uint Create();
uint Get();


+ 24
- 0
src/JT809.DotNetty.Core/Internal/JT809InferiorMsgIdReceiveDefaultHandler.cs 查看文件

@@ -0,0 +1,24 @@
using JT809.DotNetty.Core;
using JT809.DotNetty.Core.Configurations;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Clients;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.DotNetty.Core.Internal
{
/// <summary>
/// 下级平台
/// 默认消息处理业务实现
/// </summary>
internal class JT809InferiorMsgIdReceiveDefaultHandler : JT809InferiorMsgIdReceiveHandlerBase
{
public JT809InferiorMsgIdReceiveDefaultHandler(ILoggerFactory loggerFactory, IOptions<JT809Configuration> jT809ConfigurationAccessor, IJT809VerifyCodeGenerator verifyCodeGenerator, JT809SubordinateClient subordinateLinkClient) : base(loggerFactory, jT809ConfigurationAccessor, verifyCodeGenerator, subordinateLinkClient)
{
}
}
}

+ 0
- 22
src/JT809.DotNetty.Core/Internal/JT809MainMsgIdDefaultHandler.cs 查看文件

@@ -1,22 +0,0 @@
using JT809.DotNetty.Core;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Links;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.DotNetty.Core.Internal
{
/// <summary>
/// 默认主链路服务端消息处理业务实现
/// </summary>
internal class JT809MainMsgIdDefaultHandler : JT809MainMsgIdHandlerBase
{
public JT809MainMsgIdDefaultHandler(IJT809VerifyCodeGenerator verifyCodeGenerator,
JT809SubordinateClient subordinateLinkClient, JT809SessionManager sessionManager)
: base(verifyCodeGenerator, subordinateLinkClient, sessionManager)
{
}
}
}

+ 0
- 18
src/JT809.DotNetty.Core/Internal/JT809SubordinateMsgIdDefaultHandler.cs 查看文件

@@ -1,18 +0,0 @@
using JT809.DotNetty.Core;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Links;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.DotNetty.Core.Internal
{
/// <summary>
/// 默认从链路客户端消息处理业务实现
/// </summary>
internal class JT809SubordinateMsgIdDefaultHandler : JT809SubordinateMsgIdHandlerBase
{
}
}

+ 23
- 0
src/JT809.DotNetty.Core/Internal/JT809SuperiorMsgIdReceiveDefaultHandler.cs 查看文件

@@ -0,0 +1,23 @@
using JT809.DotNetty.Core;
using JT809.DotNetty.Core.Configurations;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Clients;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
using System.Text;

namespace JT809.DotNetty.Core.Internal
{
/// <summary>
/// 默认消息处理业务实现
/// </summary>
internal class JT809SuperiorMsgIdReceiveDefaultHandler : JT809SuperiorMsgIdReceiveHandlerBase
{
public JT809SuperiorMsgIdReceiveDefaultHandler(ILoggerFactory loggerFactory, IOptions<JT809Configuration> jT809ConfigurationAccessor, IJT809VerifyCodeGenerator verifyCodeGenerator, JT809SubordinateClient subordinateLinkClient) : base(loggerFactory, jT809ConfigurationAccessor, verifyCodeGenerator, subordinateLinkClient)
{
}
}
}

+ 9
- 0
src/JT809.DotNetty.Core/JT809.DotNetty.Core.csproj 查看文件

@@ -4,6 +4,11 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Internal\JT809SessionPublishingEmptyImpl.cs" />
<Compile Remove="Session\JT809MainSessionManager.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetty.Handlers" Version="0.6.0" />
@@ -19,5 +24,9 @@
<ProjectReference Include="..\JT809.DotNetty.Abstractions\JT809.DotNetty.Abstractions.csproj" />
<ProjectReference Include="..\JT809.Protocol\src\JT809.Protocol\JT809.Protocol.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Session\" />
</ItemGroup>

</Project>

+ 56
- 13
src/JT809.DotNetty.Core/JT809CoreDotnettyExtensions.cs 查看文件

@@ -6,19 +6,20 @@ using JT809.DotNetty.Core.Enums;
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Internal;
using JT809.DotNetty.Core.Links;
using JT809.DotNetty.Core.Clients;
using JT809.DotNetty.Core.Metadata;
using JT809.DotNetty.Core.Services;
using JT809.DotNetty.Core.Servers;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Newtonsoft.Json;
using System;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Options;


[assembly: InternalsVisibleTo("JT809.DotNetty.Core.Test")]
[assembly: InternalsVisibleTo("JT809.DotNetty.Tcp.Test")]
[assembly: InternalsVisibleTo("JT809.DotNetty.Udp.Test")]
[assembly: InternalsVisibleTo("JT809.DotNetty.WebApi.Test")]

namespace JT809.DotNetty.Core
@@ -42,7 +43,7 @@ namespace JT809.DotNetty.Core
});
}

public static IServiceCollection AddJT809Core(this IServiceCollection serviceDescriptors, IConfiguration configuration, Newtonsoft.Json.JsonSerializerSettings settings=null)
public static IServiceCollection AddJT809Core(this IServiceCollection serviceDescriptors,IConfiguration configuration, Newtonsoft.Json.JsonSerializerSettings settings = null)
{
if (settings != null)
{
@@ -56,22 +57,64 @@ namespace JT809.DotNetty.Core
}
serviceDescriptors.Configure<JT809Configuration>(configuration.GetSection("JT809Configuration"));
serviceDescriptors.TryAddSingleton<JT809SimpleSystemCollectService>();
serviceDescriptors.TryAddSingleton<IJT809VerifyCodeGenerator, JT809VerifyCodeGeneratorDefaultImpl>();
//JT809计数器服务工厂
serviceDescriptors.TryAddSingleton<JT809AtomicCounterServiceFactory>();
//JT809编解码器
serviceDescriptors.TryAddScoped<JT809Decoder>();
serviceDescriptors.TryAddScoped<JT809Encoder>();
//主从链路连接处理器
serviceDescriptors.TryAddScoped<JT809SubordinateConnectionHandler>();
serviceDescriptors.TryAddScoped<JT809MainServerConnectionHandler>();
//从链路客户端
serviceDescriptors.TryAddSingleton<JT809SubordinateClient>();
//主从链路消息默认业务处理器实现
serviceDescriptors.TryAddSingleton<JT809MainMsgIdHandlerBase, JT809MainMsgIdDefaultHandler>();
serviceDescriptors.TryAddSingleton<JT809SubordinateMsgIdHandlerBase, JT809SubordinateMsgIdDefaultHandler>();
return serviceDescriptors;
}

/// <summary>
/// 下级平台
/// 主链路为客户端
/// 从链路为服务端
/// </summary>
/// <param name="serviceDescriptors"></param>
/// <returns></returns>
public static IServiceCollection AddJT809InferiorPlatform(this IServiceCollection serviceDescriptors, Action<IOptions<JT809InferiorPlatformOptions>> options)
{
serviceDescriptors.Configure<JT809InferiorPlatformOptions>(options);
//主从链路客户端和服务端连接处理器
serviceDescriptors.TryAddScoped<JT809MainClientConnectionHandler>();
serviceDescriptors.TryAddScoped<JT809SubordinateServerConnectionHandler>();
//主链路服务端会话管理
//serviceDescriptors.TryAddSingleton<JT809MainSessionManager>();
//主从链路接收消息默认业务处理器
serviceDescriptors.TryAddSingleton<JT809InferiorMsgIdReceiveHandlerBase, JT809InferiorMsgIdReceiveDefaultHandler>();
//主从链路消息接收处理器
serviceDescriptors.TryAddScoped<JT809MainServerHandler>();
serviceDescriptors.TryAddScoped<JT809SubordinateServerHandler>();
//主链路客户端
serviceDescriptors.TryAddSingleton<JT809MainClient>();
//从链路服务端
serviceDescriptors.AddHostedService<JT809SubordinateServerHost>();
return serviceDescriptors;
}

/// <summary>
/// 上级平台
/// 主链路为服务端
/// 从链路为客户端
/// </summary>
/// <param name="serviceDescriptors"></param>
/// <returns></returns>
public static IServiceCollection AddJT809SuperiorPlatform(this IServiceCollection serviceDescriptors,Action<IOptions<JT809SuperiorPlatformOptions>> options)
{
serviceDescriptors.Configure<JT809SuperiorPlatformOptions>(options);
serviceDescriptors.TryAddSingleton<IJT809VerifyCodeGenerator, JT809VerifyCodeGeneratorDefaultImpl>();
//主从链路客户端和服务端连接处理器
serviceDescriptors.TryAddScoped<JT809MainServerConnectionHandler>();
serviceDescriptors.TryAddScoped<JT809SubordinateClientConnectionHandler>();
//主链路服务端会话管理
//serviceDescriptors.TryAddSingleton<JT809MainSessionManager>();
//主从链路接收消息默认业务处理器
serviceDescriptors.TryAddSingleton<JT809SuperiorMsgIdReceiveHandlerBase, JT809SuperiorMsgIdReceiveDefaultHandler>();
//主从链路消息接收处理器
serviceDescriptors.TryAddScoped<JT809MainServerHandler>();
serviceDescriptors.TryAddScoped<JT809SubordinateClientHandler>();
//从链路客户端
serviceDescriptors.TryAddSingleton<JT809SubordinateClient>();
//主链路服务端
serviceDescriptors.AddHostedService<JT809MainServerHost>();
return serviceDescriptors;


src/JT809.DotNetty.Core/Services/JT809MainServerHost.cs → src/JT809.DotNetty.Core/Servers/JT809MainServerHost.cs 查看文件

@@ -18,15 +18,16 @@ using JT809.Protocol;
using JT809.DotNetty.Core.Codecs;
using JT809.DotNetty.Core.Handlers;

namespace JT809.DotNetty.Core.Services

namespace JT809.DotNetty.Core.Servers
{
/// <summary>
/// JT809 Tcp网关服务
/// JT809 主链路服务器
/// </summary>
internal class JT809MainServerHost : IHostedService
{
private readonly IServiceProvider serviceProvider;
private readonly JT809Configuration configuration;
private readonly JT809SuperiorPlatformOptions configuration;
private readonly ILogger<JT809MainServerHost> logger;
private DispatcherEventLoopGroup bossGroup;
private WorkerEventLoopGroup workerGroup;
@@ -37,7 +38,7 @@ namespace JT809.DotNetty.Core.Services
public JT809MainServerHost(
IServiceProvider provider,
ILoggerFactory loggerFactory,
IOptions<JT809Configuration> jT809ConfigurationAccessor)
IOptions<JT809SuperiorPlatformOptions> jT809ConfigurationAccessor)
{
serviceProvider = provider;
configuration = jT809ConfigurationAccessor.Value;
@@ -66,22 +67,19 @@ namespace JT809.DotNetty.Core.Services
.ChildHandler(new ActionChannelInitializer<IChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
channel.Pipeline.AddLast("jt809MainBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
channel.Pipeline.AddLast("jt809MainSystemIdleState", new IdleStateHandler(
configuration.ReaderIdleTimeSeconds,
configuration.WriterIdleTimeSeconds,
configuration.AllIdleTimeSeconds));
pipeline.AddLast("jt809MainEncode", new JT809Encoder());
pipeline.AddLast("jt809MainDecode", new JT809Decoder());
channel.Pipeline.AddLast("jt809MainConnection", new JT809MainServerConnectionHandler(loggerFactory));
using (var scope = serviceProvider.CreateScope())
{
channel.Pipeline.AddLast("jt809MainService", scope.ServiceProvider.GetRequiredService<JT809MainServerHandler>());
channel.Pipeline.AddLast("jt809MainServerBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
channel.Pipeline.AddLast("jt809MainServerSystemIdleState", new IdleStateHandler(180, 200, 200));
pipeline.AddLast("jt809MainServerEncode", scope.ServiceProvider.GetRequiredService<JT809Encoder>());
pipeline.AddLast("jt809MainServerDecode", scope.ServiceProvider.GetRequiredService<JT809Decoder>());
channel.Pipeline.AddLast("jt809MainServerConnection", scope.ServiceProvider.GetRequiredService<JT809MainServerConnectionHandler>());
channel.Pipeline.AddLast("jt809MainServerService", scope.ServiceProvider.GetRequiredService<JT809MainServerHandler>());
}
}));
logger.LogInformation($"JT809 TCP Server start at {IPAddress.Any}:{configuration.TcpPort}.");
logger.LogInformation($"JT809 Main Link Server start at {IPAddress.Any}:{configuration.TcpPort}.");
return bootstrap.BindAsync(configuration.TcpPort)
.ContinueWith(i => bootstrapChannel = i.Result);
}

+ 96
- 0
src/JT809.DotNetty.Core/Servers/JT809SubordinateServerHost.cs 查看文件

@@ -0,0 +1,96 @@
using DotNetty.Buffers;
using DotNetty.Codecs;
using DotNetty.Handlers.Timeout;
using DotNetty.Transport.Bootstrapping;
using DotNetty.Transport.Channels;
using DotNetty.Transport.Libuv;
using JT809.DotNetty.Core.Configurations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using JT809.Protocol;
using JT809.DotNetty.Core.Codecs;
using JT809.DotNetty.Core.Handlers;


namespace JT809.DotNetty.Core.Servers
{
/// <summary>
/// JT809 从链路服务器
/// </summary>
internal class JT809SubordinateServerHost : IHostedService
{
private readonly IServiceProvider serviceProvider;
private readonly JT809InferiorPlatformOptions configuration;
private readonly ILogger<JT809SubordinateServerHost> logger;
private DispatcherEventLoopGroup bossGroup;
private WorkerEventLoopGroup workerGroup;
private IChannel bootstrapChannel;
private IByteBufferAllocator serverBufferAllocator;
private ILoggerFactory loggerFactory;

public JT809SubordinateServerHost(
IServiceProvider provider,
ILoggerFactory loggerFactory,
IOptions<JT809InferiorPlatformOptions> jT809ConfigurationAccessor)
{
serviceProvider = provider;
configuration = jT809ConfigurationAccessor.Value;
logger = loggerFactory.CreateLogger<JT809SubordinateServerHost>();
this.loggerFactory = loggerFactory;
}

public Task StartAsync(CancellationToken cancellationToken)
{
bossGroup = new DispatcherEventLoopGroup();
workerGroup = new WorkerEventLoopGroup(bossGroup, configuration.EventLoopCount);
serverBufferAllocator = new PooledByteBufferAllocator();
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.Group(bossGroup, workerGroup);
bootstrap.Channel<TcpServerChannel>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|| RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
bootstrap
.Option(ChannelOption.SoReuseport, true)
.ChildOption(ChannelOption.SoReuseaddr, true);
}
bootstrap
.Option(ChannelOption.SoBacklog, configuration.SoBacklog)
.ChildOption(ChannelOption.Allocator, serverBufferAllocator)
.ChildHandler(new ActionChannelInitializer<IChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
using (var scope = serviceProvider.CreateScope())
{
channel.Pipeline.AddLast("jt809SubServerBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
channel.Pipeline.AddLast("jt809SubServerSystemIdleState", new IdleStateHandler(180, 200, 200));
pipeline.AddLast("jt809SubServerEncode", scope.ServiceProvider.GetRequiredService<JT809Encoder>());
pipeline.AddLast("jt809SubServerDecode", scope.ServiceProvider.GetRequiredService<JT809Decoder>());
channel.Pipeline.AddLast("jt809SubServerConnection", scope.ServiceProvider.GetRequiredService<JT809SubordinateServerConnectionHandler>());
channel.Pipeline.AddLast("jt809SubServerService", scope.ServiceProvider.GetRequiredService<JT809SubordinateServerHandler>());
}
}));
logger.LogInformation($"JT809 Subordinate Link Server start at {IPAddress.Any}:{configuration.TcpPort}.");
return bootstrap.BindAsync(configuration.TcpPort)
.ContinueWith(i => bootstrapChannel = i.Result);
}

public async Task StopAsync(CancellationToken cancellationToken)
{
await bootstrapChannel.CloseAsync();
var quietPeriod = configuration.QuietPeriodTimeSpan;
var shutdownTimeout = configuration.ShutdownTimeoutTimeSpan;
await workerGroup.ShutdownGracefullyAsync(quietPeriod, shutdownTimeout);
await bossGroup.ShutdownGracefullyAsync(quietPeriod, shutdownTimeout);
}
}
}

+ 2
- 4
src/JT809.DotNetty.Core/Services/JT809AtomicCounterService.cs 查看文件

@@ -1,13 +1,11 @@
using JT809.DotNetty.Core.Enums;
using JT809.DotNetty.Core.Internal;
using JT809.DotNetty.Core.Metadata;
using JT809.DotNetty.Core.Metadata;

namespace JT809.DotNetty.Core.Services
{
/// <summary>
/// Tcp计数包服务
/// </summary>
public class JT809AtomicCounterService
internal class JT809AtomicCounterService
{
private readonly JT809AtomicCounter MsgSuccessCounter;



+ 1
- 3
src/JT809.DotNetty.Core/Services/JT809AtomicCounterServiceFactory.cs 查看文件

@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Concurrent;

namespace JT809.DotNetty.Core.Services
{
public class JT809AtomicCounterServiceFactory
internal class JT809AtomicCounterServiceFactory
{
private static readonly ConcurrentDictionary<string, JT809AtomicCounterService> cache;



+ 1
- 1
src/JT809.DotNetty.Core/Services/JT809SimpleSystemCollectService.cs 查看文件

@@ -9,7 +9,7 @@ namespace JT809.DotNetty.Core.Services
/// <summary>
/// 简单系统收集服务
/// </summary>
public class JT809SimpleSystemCollectService
internal class JT809SimpleSystemCollectService
{
/// <summary>
/// 获取系统当前进程使用情况


src/JT809.DotNetty.Core/Session/JT809SessionManager.cs → src/JT809.DotNetty.Core/Session/JT809MainSessionManager.cs 查看文件

@@ -7,23 +7,23 @@ using DotNetty.Transport.Channels;
using JT809.DotNetty.Abstractions;
using JT809.DotNetty.Core.Metadata;

namespace JT809.DotNetty.Core
namespace JT809.DotNetty.Core.Session
{
/// <summary>
/// JT809 Tcp会话管理
/// JT809 主链路会话管理
/// </summary>
public class JT809SessionManager
public class JT809MainSessionManager
{
private readonly ILogger<JT809SessionManager> logger;
private readonly ILogger<JT809MainSessionManager> logger;

private readonly IJT809SessionPublishing jT809SessionPublishing;
//private readonly IJT809SessionPublishing jT809SessionPublishing;

public JT809SessionManager(
IJT809SessionPublishing jT809SessionPublishing,
public JT809MainSessionManager(
//IJT809SessionPublishing jT809SessionPublishing,
ILoggerFactory loggerFactory)
{
this.jT809SessionPublishing = jT809SessionPublishing;
logger = loggerFactory.CreateLogger<JT809SessionManager>();
//this.jT809SessionPublishing = jT809SessionPublishing;
logger = loggerFactory.CreateLogger<JT809MainSessionManager>();
}

private ConcurrentDictionary<uint, JT809Session> SessionIdDict = new ConcurrentDictionary<uint, JT809Session>();
@@ -62,7 +62,7 @@ namespace JT809.DotNetty.Core
if (SessionIdDict.ContainsKey(msgGNSSCENTERID)) return;
if (SessionIdDict.TryAdd(msgGNSSCENTERID, new JT809Session(channel, msgGNSSCENTERID)))
{
jT809SessionPublishing.PublishAsync(JT809Constants.SessionOnline, msgGNSSCENTERID.ToString());
//jT809SessionPublishing.PublishAsync(JT809Constants.SessionOnline, msgGNSSCENTERID.ToString());
}
}

@@ -76,7 +76,7 @@ namespace JT809.DotNetty.Core
if (SessionIdDict.TryRemove(msgGNSSCENTERID, out JT809Session jT808SessionRemove))
{
logger.LogInformation($">>>{msgGNSSCENTERID} Session Remove.");
jT809SessionPublishing.PublishAsync(JT809Constants.SessionOffline, msgGNSSCENTERID.ToString());
//jT809SessionPublishing.PublishAsync(JT809Constants.SessionOffline, msgGNSSCENTERID.ToString());
return jT808SessionRemove;
}
else
@@ -96,7 +96,7 @@ namespace JT809.DotNetty.Core
}
string nos = string.Join(",", keys);
logger.LogInformation($">>>{nos} Channel Remove.");
jT809SessionPublishing.PublishAsync(JT809Constants.SessionOffline, nos);
//jT809SessionPublishing.PublishAsync(JT809Constants.SessionOffline, nos);
}
}


+ 2
- 1
src/JT809.DotNetty.Tcp/Handlers/JT809MsgIdDefaultTcpHandler.cs 查看文件

@@ -2,6 +2,7 @@
using JT809.DotNetty.Core.Handlers;
using JT809.DotNetty.Core.Interfaces;
using JT809.DotNetty.Core.Links;
using JT809.DotNetty.Core.Session;
using System;
using System.Collections.Generic;
using System.Text;
@@ -14,7 +15,7 @@ namespace JT809.DotNetty.Tcp.Handlers
internal class JT809MsgIdDefaultTcpHandler : JT809MainMsgIdHandlerBase
{
public JT809MsgIdDefaultTcpHandler(IJT809VerifyCodeGenerator verifyCodeGenerator,
JT809SubordinateClient subordinateLinkClient, JT809SessionManager sessionManager)
JT809SubordinateClient subordinateLinkClient, JT809MainSessionManager sessionManager)
: base(verifyCodeGenerator, subordinateLinkClient, sessionManager)
{
}


+ 2
- 2
src/JT809.DotNetty.Tcp/Handlers/JT809TcpConnectionHandler.cs 查看文件

@@ -14,10 +14,10 @@ namespace JT809.DotNetty.Tcp.Handlers
{
private readonly ILogger<JT809TcpConnectionHandler> logger;

private readonly JT809SessionManager jT809SessionManager;
private readonly JT809MainSessionManager jT809SessionManager;

public JT809TcpConnectionHandler(
JT809SessionManager jT809SessionManager,
JT809MainSessionManager jT809SessionManager,
ILoggerFactory loggerFactory)
{
this.jT809SessionManager = jT809SessionManager;


+ 2
- 2
src/JT809.DotNetty.Tcp/Handlers/JT809TcpServerHandler.cs 查看文件

@@ -19,7 +19,7 @@ namespace JT809.DotNetty.Tcp.Handlers
{
private readonly JT809MainMsgIdHandlerBase handler;
private readonly JT809SessionManager jT809SessionManager;
private readonly JT809MainSessionManager jT809SessionManager;

private readonly JT809AtomicCounterService jT809AtomicCounterService;

@@ -29,7 +29,7 @@ namespace JT809.DotNetty.Tcp.Handlers
ILoggerFactory loggerFactory,
JT809MainMsgIdHandlerBase handler,
JT809AtomicCounterServiceFactory jT809AtomicCounterServiceFactorty,
JT809SessionManager jT809SessionManager
JT809MainSessionManager jT809SessionManager
)
{
this.handler = handler;


+ 1
- 1
src/JT809.DotNetty.Tcp/JT809TcpDotnettyExtensions.cs 查看文件

@@ -19,7 +19,7 @@ namespace JT809.DotNetty.Tcp
{
public static IServiceCollection AddJT809TcpHost(this IServiceCollection serviceDescriptors)
{
serviceDescriptors.TryAddSingleton<JT809SessionManager>();
serviceDescriptors.TryAddSingleton<JT809MainSessionManager>();
serviceDescriptors.TryAddSingleton<JT809MainMsgIdHandlerBase, JT809MsgIdDefaultTcpHandler>();
serviceDescriptors.TryAddScoped<JT809TcpConnectionHandler>();
serviceDescriptors.TryAddScoped<JT809Decoder>();


+ 1
- 1
src/JT809.DotNetty.Tests/JT809.DotNetty.Tcp.Test/JT809.DotNetty.Tcp.Test.csproj 查看文件

@@ -25,7 +25,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\JT809.DotNetty.Tcp\JT809.DotNetty.Tcp.csproj" />
<ProjectReference Include="..\..\JT809.DotNetty.Core\JT809.DotNetty.Core.csproj" />
</ItemGroup>

</Project>

+ 3
- 21
src/JT809.DotNetty.sln 查看文件

@@ -3,25 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2016
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809Netty.Core", "JT809Netty.Core\JT809Netty.Core.csproj", "{2054D7E6-53B6-412F-BE9D-C6DABD80A111}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809Netty.DownMasterLink", "JT809Netty.DownMasterLink\JT809Netty.DownMasterLink.csproj", "{3BF1D40D-A17D-4FBC-B3FF-B6DF8B3F13ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.DotNetty.Core", "JT809.DotNetty.Core\JT809.DotNetty.Core.csproj", "{0291C1D6-B4C6-4E7E-984B-0BAFB238727D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C712B2DE-34FE-4D9C-B574-A08B019246E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol", "JT809.Protocol\src\JT809.Protocol\JT809.Protocol.csproj", "{321EE8EE-10D7-4233-8B8A-279BE68FB18A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.DotNetty.Tcp", "JT809.DotNetty.Tcp\JT809.DotNetty.Tcp.csproj", "{9BE94CDE-E813-403A-A68B-45C78BCAAF74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.DotNetty.Abstractions", "JT809.DotNetty.Abstractions\JT809.DotNetty.Abstractions.csproj", "{EB8276CC-1848-4E7D-B77E-29B22AF767F0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.DotNetty.Abstractions", "JT809.DotNetty.Abstractions\JT809.DotNetty.Abstractions.csproj", "{EB8276CC-1848-4E7D-B77E-29B22AF767F0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{DD4611CF-79A9-45C7-91EB-1E84D22B7D07}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.DotNetty.Tcp.Test", "JT809.DotNetty.Tests\JT809.DotNetty.Tcp.Test\JT809.DotNetty.Tcp.Test.csproj", "{560913C8-B618-46AD-B974-9D324F1ABBAC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.DotNetty.Tcp.Test", "JT809.DotNetty.Tests\JT809.DotNetty.Tcp.Test\JT809.DotNetty.Tcp.Test.csproj", "{560913C8-B618-46AD-B974-9D324F1ABBAC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JT809.DotNetty.Host.Test", "JT809.DotNetty.Tests\JT809.DotNetty.Host.Test\JT809.DotNetty.Host.Test.csproj", "{D4E18559-C429-416F-9399-42C0E604D27B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.DotNetty.Host.Test", "JT809.DotNetty.Tests\JT809.DotNetty.Host.Test\JT809.DotNetty.Host.Test.csproj", "{D4E18559-C429-416F-9399-42C0E604D27B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JT809.Protocol.Extensions.DependencyInjection", "JT809.Protocol\src\JT809.Protocol.Extensions.DependencyInjection\JT809.Protocol.Extensions.DependencyInjection.csproj", "{975D959C-7C0B-418E-838E-EB383E912F8C}"
EndProject
@@ -31,14 +25,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2054D7E6-53B6-412F-BE9D-C6DABD80A111}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2054D7E6-53B6-412F-BE9D-C6DABD80A111}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2054D7E6-53B6-412F-BE9D-C6DABD80A111}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2054D7E6-53B6-412F-BE9D-C6DABD80A111}.Release|Any CPU.Build.0 = Release|Any CPU
{3BF1D40D-A17D-4FBC-B3FF-B6DF8B3F13ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3BF1D40D-A17D-4FBC-B3FF-B6DF8B3F13ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3BF1D40D-A17D-4FBC-B3FF-B6DF8B3F13ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3BF1D40D-A17D-4FBC-B3FF-B6DF8B3F13ED}.Release|Any CPU.Build.0 = Release|Any CPU
{0291C1D6-B4C6-4E7E-984B-0BAFB238727D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0291C1D6-B4C6-4E7E-984B-0BAFB238727D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0291C1D6-B4C6-4E7E-984B-0BAFB238727D}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -47,10 +33,6 @@ Global
{321EE8EE-10D7-4233-8B8A-279BE68FB18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{321EE8EE-10D7-4233-8B8A-279BE68FB18A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{321EE8EE-10D7-4233-8B8A-279BE68FB18A}.Release|Any CPU.Build.0 = Release|Any CPU
{9BE94CDE-E813-403A-A68B-45C78BCAAF74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9BE94CDE-E813-403A-A68B-45C78BCAAF74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9BE94CDE-E813-403A-A68B-45C78BCAAF74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9BE94CDE-E813-403A-A68B-45C78BCAAF74}.Release|Any CPU.Build.0 = Release|Any CPU
{EB8276CC-1848-4E7D-B77E-29B22AF767F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EB8276CC-1848-4E7D-B77E-29B22AF767F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EB8276CC-1848-4E7D-B77E-29B22AF767F0}.Release|Any CPU.ActiveCfg = Release|Any CPU


||||||
x
 
000:0
Loading…
取消
儲存