Exemplo n.º 1
0
        public void ReadCallback(IAsyncResult ar)
        {
            StateObject state = (StateObject)ar.AsyncState;

            Socket = state.WorkSocket;
            ISocketMessage message = new JsonSocketMessage();

            try
            {
                int bytesRead = Socket.EndReceive(ar);

                if (bytesRead > 0)
                {
                    foreach (var msg in message.Deserialize(state.Buffer))
                    {
                        switch (msg.MessageType)
                        {
                        case SocketMessageType.Method:
                            MethodRecievedEvent?.Invoke(this,
                                                        MethodSignatureDto.DeserializeMethodObject(msg.Message));
                            break;

                        case SocketMessageType.Methods:
                            break;

                        case SocketMessageType.MethodExecution:
                            break;

                        case SocketMessageType.Identity:
                            ClientIdentificationEvent?.Invoke(this, Guid.Parse(msg.Message));
                            break;

                        case SocketMessageType.Normal:
                            MessageRecievedEvent?.Invoke(this, msg);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }

                    Socket.BeginReceive(state.Buffer, 0, state.BufferSize, 0, ReadCallback, state);
                }

                else
                {
                }
            }
            catch (SocketException e)
            {
                _logger.Warn(e.Message);
            }
        }
Exemplo n.º 2
0
 public void Is_argument_exception_thrown_when_MethodDeserialization_string_is_null()
 {
     MethodSignatureDto.DeserializeMethodObject(null);
 }
Exemplo n.º 3
0
        public void Is_jsonserialization_exception_thrown_when_json_array_is_parsed_to_MethodDeserialization()
        {
            string invalidJson = "[{\"IsMember\" : true, \"Name\" : \"John\", \"Age\" : 24}]";

            MethodSignatureDto.DeserializeMethodObject(invalidJson);
        }
Exemplo n.º 4
0
        public void Is_argument_exception_thrown_when_MethodDeserialization_string_is_empty()
        {
            string json = "";

            MethodSignatureDto.DeserializeMethodObject(json);
        }
Exemplo n.º 5
0
        public void Is_jsonreader_exception_thrown_when_MethodDeserialization_string_is_invalid()
        {
            string invalidJson = "this is not valid json";

            MethodSignatureDto.DeserializeMethodObject(invalidJson);
        }