public void Fire(BaseRtmResponse response) { AllMessages?.Invoke(this, new RtmMessageEventArgs <BaseRtmResponse>(response)); switch (response) { case HelloResponse helloResponse: HelloMessage?.Invoke(this, new RtmMessageEventArgs <HelloResponse>(helloResponse)); break; case PongResponse pongResponse: PongMessage?.Invoke(this, new RtmMessageEventArgs <PongResponse>(pongResponse)); break; case UserTypingResponse userTypingResponse: UserTypingMessage?.Invoke(this, new RtmMessageEventArgs <UserTypingResponse>(userTypingResponse)); break; case BaseMessageResponse messageResponse: switch (messageResponse) { case BotMessageResponse botMessageResponse: BotMessage?.Invoke(this, new RtmMessageEventArgs <BotMessageResponse>(botMessageResponse)); break; default: UserMessage?.Invoke(this, new RtmMessageEventArgs <UserMessageResponse>(messageResponse)); break; } break; default: throw new NotImplementedException(); } }
public async Task <IMessage> ReadAndDecodeMessage(Header header, NetworkStream networkStream) { byte[] dataBuffer = new byte[header.MessageSize]; await networkStream.ReadAsync(dataBuffer, 0, dataBuffer.Length); Console.WriteLine("message type being read in network service: " + header.MessageType); var dataBufferList = dataBuffer.ToList(); switch (header.MessageType) { case MessageType.NotSet: return(null); case MessageType.Connect: return(ConnectRequestMessage.Decode(dataBufferList)); case MessageType.Chat: return(ChatMessage.Decode(dataBufferList)); case MessageType.Image: return(ImageMessage.Decode(dataBufferList)); case MessageType.NewUserOnline: return(NewUserOnlineMessage.Decode(dataBufferList)); case MessageType.UserLogoff: return(UserLogoffMessage.Decode(dataBufferList)); case MessageType.UserOffline: return(UserOfflineMessage.Decode(dataBufferList)); case MessageType.Typing: return(UserTypingMessage.Decode(dataBufferList)); default: throw new ArgumentOutOfRangeException(); } }
void OnUserTyping(UserTypingMessage msg) { UserTyping(this, new SessionEventArgs(msg.SessionId, msg.Sender)); Trace.WriteLine(msg.Sender + " is typing."); }