Beispiel #1
0
        /// <summary>
        /// 重写消息处理器
        /// </summary>
        /// <param name="request"></param>
        /// <param name="session"></param>
        public override byte[] Processor(JT808HeaderPackage request, IUnionSession session)
        {
            //AOP 可以自定义添加一些东西:上下行日志、数据转发
            logger.LogDebug("可以自定义添加一些东西:上下行日志、数据转发");
            //流量
            jT808Traffic.Increment(request.Header.TerminalPhoneNo, DateTime.Now.ToString("yyyyMMdd"), request.OriginalData.Length);
            var parameter = (request.Header.TerminalPhoneNo, request.OriginalData.ToArray());

            //转发数据(可同步也可以使用队列进行异步)
            try
            {
                jT808TransmitService.SendAsync(parameter);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "");
            }
            //上行日志(可同步也可以使用队列进行异步)
            jT808MsgLogging.Processor(parameter, UnionMsgLoggingType.up);
            //处理上行消息
            var down = base.Processor(request, session);

            //下行日志(可同步也可以使用队列进行异步)
            jT808MsgLogging.Processor((request.Header.TerminalPhoneNo, down), UnionMsgLoggingType.down);
            return(down);
        }
Beispiel #2
0
        internal void TryLink(string terminalPhoneNo, IUnionSession session)
        {
            DateTime curretDatetime = DateTime.Now;

            if (TerminalPhoneNoSessions.TryGetValue(terminalPhoneNo, out IUnionSession cacheSession))
            {
                if (session.SessionID != cacheSession.SessionID)
                {
                    //从转发到直连的数据需要更新缓存
                    session.ActiveTime = curretDatetime;
                    TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, session, cacheSession);
                    //会话通知
                    JT808SessionProducer?.ProduceAsync(UnionGatewayConstants.SessionOnline, terminalPhoneNo);
                }
                else
                {
                    cacheSession.ActiveTime = curretDatetime;
                    TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, cacheSession, cacheSession);
                }
            }
            else
            {
                session.TerminalPhoneNo = terminalPhoneNo;
                if (TerminalPhoneNoSessions.TryAdd(terminalPhoneNo, session))
                {
                    //会话通知
                    JT808SessionProducer?.ProduceAsync(UnionGatewayConstants.SessionOnline, terminalPhoneNo);
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// 发送字节消息
 /// </summary>
 /// <param name="session"></param>
 /// <param name="data"></param>
 public static async void SendAsync(this IUnionSession session, byte[] data)
 {
     if (session.TransportProtocolType == TransportProtocolType.Tcp)
     {
         await session.Client.SendAsync(data, SocketFlags.None);
     }
     else
     {
         await session.Client.SendToAsync(data, SocketFlags.None, session.RemoteEndPoint);
     }
 }
Beispiel #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request">请求数据</param>
 /// <param name="session">当前会话</param>
 /// <returns>应答消息数据</returns>
 public virtual byte[] Processor(JT808HeaderPackage request, IUnionSession session)
 {
     if (HandlerDict.TryGetValue(request.Header.MsgId, out var func))
     {
         return(func(request, session));
     }
     else
     {
         //处理不了的消息统一回复通用应答
         return(CommonReply(request, session));
     }
 }
Beispiel #5
0
 /// <summary>
 /// 自定义消息
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public byte[] Msg0x9999(JT808HeaderPackage request, IUnionSession session)
 {
     logger.LogDebug("自定义消息");
     return(default);
Beispiel #6
0
 /// <summary>
 /// 重写自带的消息
 /// </summary>
 /// <param name="request"></param>
 /// <param name="session"></param>
 public override byte[] Msg0x0200(JT808HeaderPackage request, IUnionSession session)
 {
     logger.LogDebug("重写自带Msg0x0200的消息");
     return(base.Msg0x0200(request, session));
 }
Beispiel #7
0
 /// <summary>
 /// 终端通用应答
 /// 平台无需回复
 /// 实现自己的业务
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public virtual byte[] Msg0x0001(JT808HeaderPackage request, IUnionSession session)
 {
     return(default);
Beispiel #8
0
 internal bool TryAdd(IUnionSession session)
 {
     return(Sessions.TryAdd(session.SessionID, session));
 }