public static void HandleMinerClientMessage(IWsSessionAdapter session, WsMessage message) { if (message == null) { return; } if (!MinerClientSessionSet.TryGetByWsSessionId(session.SessionId, out IMinerClientSession minerSession)) { session.CloseAsync(WsCloseCode.Normal, "意外,会话不存在,请重新连接"); return; } else if (MinerClientWsMessageHandler.TryGetHandler(message.Type, out Action <IMinerClientSession, Guid, WsMessage> handler)) { try { handler.Invoke(minerSession, minerSession.ClientId, message); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } } else { NTMinerConsole.UserWarn($"{nameof(HandleMinerClientMessage)} Received InvalidType {message.Type}"); } }
protected override void OnMessage(MessageEventArgs e) { IMinerClientSession minerSession; if (e.IsPing) { if (WsRoot.MinerClientSessionSet.ActiveByWsSessionId(base.ID, out minerSession)) { WsRoot.MinerClientMqSender.SendMinerClientWsBreathed(minerSession.LoginName, minerSession.ClientId); } return; } WsMessage message = e.ToWsMessage <WsMessage>(); if (message == null) { return; } if (!WsRoot.MinerClientSessionSet.TryGetByWsSessionId(this.ID, out minerSession)) { this.CloseAsync(CloseStatusCode.Normal, "意外,会话不存在,请重新连接"); return; } else if (MinerClientWsMessageHandler.TryGetHandler(message.Type, out Action <MinerClientBehavior, string, Guid, WsMessage> handler)) { try { handler.Invoke(this, minerSession.LoginName, minerSession.ClientId, message); } catch (Exception ex) { Logger.ErrorDebugLine(ex); } } else { Write.UserWarn($"{_behaviorName} {nameof(OnMessage)} Received InvalidType {e.Data}"); } }