Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="terminalPhoneNo"></param>
 /// <param name="socket"></param>
 /// <param name="remoteEndPoint"></param>
 /// <returns></returns>
 public IJT808Session TryLink(string terminalPhoneNo, Socket socket, EndPoint remoteEndPoint)
 {
     if (TerminalPhoneNoSessions.TryGetValue(terminalPhoneNo, out IJT808Session currentSession))
     {
         currentSession.ActiveTime      = DateTime.Now;
         currentSession.TerminalPhoneNo = terminalPhoneNo;
         currentSession.RemoteEndPoint  = remoteEndPoint;
         TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, currentSession, currentSession);
     }
     else
     {
         JT808UdpSession session = new JT808UdpSession(socket, remoteEndPoint);
         session.TerminalPhoneNo = terminalPhoneNo;
         Sessions.TryAdd(session.SessionID, session);
         TerminalPhoneNoSessions.TryAdd(terminalPhoneNo, session);
         currentSession = session;
     }
     //会话通知
     //使用场景:
     //部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接,
     //这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。
     //有设备关联上来可以进行通知 例如:使用Redis发布订阅
     if (SessionProducer != null)
     {
         SessionProducer.ProduceAsync(JT808GatewayConstants.SessionOnline, terminalPhoneNo);
     }
     return(currentSession);
 }
Пример #2
0
        internal void TryLink(string terminalPhoneNo, IJT808Session session)
        {
            DateTime curretDatetime = DateTime.Now;

            if (TerminalPhoneNoSessions.TryGetValue(terminalPhoneNo, out IJT808Session cacheSession))
            {
                if (session.SessionID != cacheSession.SessionID)
                {
                    //从转发到直连的数据需要更新缓存
                    session.ActiveTime = curretDatetime;
                    TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, session, cacheSession);
                    //会话通知
                    JT808SessionProducer?.ProduceAsync(JT808GatewayConstants.SessionOnline, terminalPhoneNo);
                }
                else
                {
                    cacheSession.ActiveTime = curretDatetime;
                    TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, cacheSession, cacheSession);
                }
            }
            else
            {
                session.TerminalPhoneNo = terminalPhoneNo;
                if (TerminalPhoneNoSessions.TryAdd(terminalPhoneNo, session))
                {
                    //会话通知
                    JT808SessionProducer?.ProduceAsync(JT808GatewayConstants.SessionOnline, terminalPhoneNo);
                }
            }
        }
        public string TryLink(string terminalPhoneNo, Socket socket, EndPoint remoteEndPoint)
        {
            string sessionId = string.Empty;

            if (TerminalPhoneNoSessions.TryGetValue(terminalPhoneNo, out sessionId))
            {
                if (Sessions.TryGetValue(sessionId, out IJT808Session sessionInfo))
                {
                    sessionInfo.ActiveTime      = DateTime.Now;
                    sessionInfo.TerminalPhoneNo = terminalPhoneNo;
                    sessionInfo.RemoteEndPoint  = remoteEndPoint;
                    Sessions.TryUpdate(sessionId, sessionInfo, sessionInfo);
                }
            }
            else
            {
                JT808UdpSession session = new JT808UdpSession(socket, remoteEndPoint);
                Sessions.TryAdd(session.SessionID, session);
                TerminalPhoneNoSessions.TryAdd(terminalPhoneNo, session.SessionID);
                sessionId = session.SessionID;
            }
            //会话通知
            //使用场景:
            //部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接,
            //这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。
            //有设备关联上来可以进行通知 例如:使用Redis发布订阅
            JT808SessionProducer?.ProduceAsync(JT808GatewayConstants.SessionOnline, terminalPhoneNo);
            return(sessionId);
        }
Пример #4
0
        internal void TryLink(string terminalPhoneNo, IJT1078Session session)
        {
            DateTime curretDatetime = DateTime.Now;

            if (TerminalPhoneNoSessions.TryGetValue(terminalPhoneNo, out IJT1078Session cacheSession))
            {
                if (session.SessionID != cacheSession.SessionID)
                {
                    //从转发到直连的数据需要更新缓存
                    session.ActiveTime = curretDatetime;
                    TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, session, cacheSession);
                    //会话通知
                    SessionNoticeService.SessionNoticeBlockingCollection.Add((JT1078GatewayConstants.SessionOnline, terminalPhoneNo, session.TransportProtocolType.ToString()));
                }
                else
                {
                    cacheSession.ActiveTime = curretDatetime;
                    TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, cacheSession, cacheSession);
                }
            }
            else
            {
                session.TerminalPhoneNo = terminalPhoneNo;
                if (TerminalPhoneNoSessions.TryAdd(terminalPhoneNo, session))
                {
                    //会话通知
                    SessionNoticeService.SessionNoticeBlockingCollection.Add((JT1078GatewayConstants.SessionOnline, terminalPhoneNo, session.TransportProtocolType.ToString()));
                }
            }
        }
Пример #5
0
 public IJT1078Session TryLink(string terminalPhoneNo, Socket socket, EndPoint remoteEndPoint)
 {
     if (TerminalPhoneNoSessions.TryGetValue(terminalPhoneNo, out IJT1078Session currentSession))
     {
         currentSession.ActiveTime      = DateTime.Now;
         currentSession.TerminalPhoneNo = terminalPhoneNo;
         currentSession.RemoteEndPoint  = remoteEndPoint;
         TerminalPhoneNoSessions.TryUpdate(terminalPhoneNo, currentSession, currentSession);
     }
     else
     {
         JT1078UdpSession session = new JT1078UdpSession(socket);
         session.TerminalPhoneNo = terminalPhoneNo;
         session.RemoteEndPoint  = remoteEndPoint;
         Sessions.TryAdd(session.SessionID, session);
         TerminalPhoneNoSessions.TryAdd(terminalPhoneNo, session);
         currentSession = session;
     }
     //会话通知
     SessionNoticeService.SessionNoticeBlockingCollection.Add((JT1078GatewayConstants.SessionOnline, terminalPhoneNo, currentSession.TransportProtocolType.ToString()));
     return(currentSession);
 }