Пример #1
0
        private MessageType GetMessageType(CallObject callMessage)
        {
            if (callMessage.method == null)
            {
                if (callMessage.error != null)
                {
                    return(MessageType.EXCEPTION);
                }
                else
                {
                    return(MessageType.RESPONSE);
                }
            }

            else
            {
                return(MessageType.REQUEST);
            }
        }
Пример #2
0
        public object SerializeMessage(IMessage message)
        {
            string jsonSerializedMessage = "";
            CallObject callMessage = new CallObject();
            callMessage.id = message.ID;

            if (message.Type == MessageType.REQUEST)
            {
                callMessage.parameters = message.Parameters.ToArray();
                callMessage.method = message.MethodName;
            }

            else
            {
                callMessage.result = message.Result;
                callMessage.method = null;
            }

            jsonSerializedMessage = JsonSerializer.Serialize(callMessage);
            return jsonSerializedMessage;
        }
Пример #3
0
        public object SerializeMessage(IMessage message)
        {
            string     jsonSerializedMessage = "";
            CallObject callMessage           = new CallObject();

            callMessage.id = message.ID;

            if (message.Type == MessageType.REQUEST)
            {
                callMessage.parameters = message.Parameters.ToArray();
                callMessage.method     = message.MethodName;
            }

            else
            {
                callMessage.result = message.Result;
                callMessage.method = null;
            }

            jsonSerializedMessage = JsonSerializer.Serialize(callMessage);
            return(jsonSerializedMessage);
        }
Пример #4
0
        public IMessage DeserializeMessage(object message)
        {
            string receivedMessage = message as string;

            // Small hack
            receivedMessage = receivedMessage.Replace("params", "parameters");

            CallObject  receivedCall        = JsonSerializer.Deserialize <CallObject>(receivedMessage);
            MessageBase deserializedMessage = new MessageBase();

            deserializedMessage.ID = receivedCall.id;
            if (receivedCall.parameters != null)
            {
                deserializedMessage.Parameters = new List <object> (receivedCall.parameters);
            }
            if (receivedCall.result != null)
            {
                deserializedMessage.Result = receivedCall.result;
            }
            deserializedMessage.MethodName = receivedCall.method;
            deserializedMessage.Type       = GetMessageType(receivedCall);
            return(deserializedMessage);
        }
Пример #5
0
        private MessageType GetMessageType(CallObject callMessage)
        {
            if (callMessage.method == null)
            {
                if(callMessage.error != null)
                {
                    return MessageType.EXCEPTION;
                }
                else
                {
                    return MessageType.RESPONSE;
                }
            }

            else
            {
                return MessageType.REQUEST;
            }
        }