Example #1
0
 protected override async 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());
         }
         SuperiorMainSessionManager.TryAdd(ctx.Channel, jT809Package.Header.MsgGNSSCENTERID);
         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);
                 await 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));
         }
     }
 }
Example #2
0
 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));
         }
     }
 }