/// <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); }
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); } } }
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())); } } }
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); }