Exemplo n.º 1
0
        public static IMessage createMessageFromString(string JsonMessage, Room room, IWebSocketConnection socket)
        {
            IMessage inboundMessage;

            OLDMessage message = JsonSerializer.Deserialize <OLDMessage>(JsonMessage);

            if (message == null)
            {
                throw new Exception("Unable to deserialize incoming message");
            }

            if (string.IsNullOrEmpty(message.type))
            {
                throw new Exception("Empty Message type");
            }

            Console.WriteLine("CREATING MESSAGE");

            switch (message.type)
            {
            case ChatMessage.MessageType:
                inboundMessage = JsonSerializer.Deserialize <ChatMessage>(JsonMessage);
                break;

            case GetHistoryMessage.MessageType:
                inboundMessage = JsonSerializer.Deserialize <GetHistoryMessage>(JsonMessage);
                break;

            case AddStickyNoteMessage.MessageType:
                inboundMessage = JsonSerializer.Deserialize <AddStickyNoteMessage>(JsonMessage);
                break;

            case UserMessage.MessageType:
                inboundMessage = JsonSerializer.Deserialize <UserMessage>(JsonMessage);
                break;

            default:
                throw new Exception("Unknown Message type");
            }

            inboundMessage.setRoom(room);
            inboundMessage.setSourceSocket(socket);

            return(inboundMessage);
        }
Exemplo n.º 2
0
        public void processMessage(string message, IWebSocketConnection socket)
        {
            OLDMessage receivedMessage = JsonSerializer.Deserialize <OLDMessage>(message);

            if (receivedMessage.type == "GetUser")
            {
                socket.Send(getUserMessage());
            }
            else if (receivedMessage.type == "ChatMessage" || receivedMessage.type == "GetHistory" ||
                     receivedMessage.type == "AddStickyNote" || receivedMessage.type == "User")
            {
                IMessage msg = MessageFactory.createMessageFromString(message, this, socket);

                msg.processInbound();
                msg.processOutbound();
            }
            else
            {
                broadCastMessage(message);
            }
        }