public void BroadcastResponse(ServerResponseDTO serverResponse) { string responseSerialization = JsonConvert.SerializeObject(serverResponse); byte[] responseBytesArray = Encoding.ASCII.GetBytes(responseSerialization); _tcpServer.BroadCastData(responseBytesArray); }
private void RecieveResponse(byte[] data, IPEndPoint sender) { string responseSerialization = Encoding.ASCII.GetString(data); ServerResponseDTO serverResponse = JsonConvert .DeserializeObject <ServerResponseDTO>(responseSerialization); RemoveSendCommandByResponse(serverResponse); _clientMediator.HandleResponse(serverResponse); }
public void HandleResponse(ServerResponseDTO serverResponse) { try { _clientResponseHandler.HandleServerResponse(serverResponse); } catch (Exception exception) { throw new SystemDiagnosticClientException(exception, "Error with handle response."); } }
public void HandleServerResponse(ServerResponseDTO serverResponse) { MethodInfo handleMethod = SearchHandlerMethod(_classHandlers, serverResponse.Information.Status); if (handleMethod == null) { throw new ClientResponseHandlerException("Undefined status code of response."); } object[] methodArguments = new object[] { serverResponse.Information, serverResponse.Command }; handleMethod.Invoke(this, methodArguments); }
private void RecieveClientCommand(byte[] message, IPEndPoint sender) { string clientCommandSerialization = Encoding.ASCII.GetString(message); ClientCommandDTO clientCommand = JsonConvert.DeserializeObject <ClientCommandDTO>(clientCommandSerialization); ServerResponseDTO serverResponse = _serverCommandHandler.HandleCommand(clientCommand); string serverResponseSerialization = JsonConvert.SerializeObject(serverResponse); byte[] serverResponseBytesArray = Encoding.ASCII.GetBytes(serverResponseSerialization); _tcpServer.SendDataAsync(serverResponseBytesArray, sender); }
private void RemoveSendCommandByResponse(ServerResponseDTO serverResponse) { lock (commandQueueLocker) { SendCommandInformation sendCommand = _sendCommands .Where(c => c.Command.IdCommand.Equals(serverResponse.IdCommand)).FirstOrDefault(); if (sendCommand != null) { _sendCommands.Remove(sendCommand); } } }
public void Ctor_Assigns_NullError_IfNotPassed() { //arrange. var serverResponseDTO = new ServerResponseDTO { OK = true, Error = null, Reason = "some reason here" }; //act. var sut = new ServerResponse(serverResponseDTO); //assert. Assert.Null(sut.Error); }
public void Ctor_Initializes_PropertiesAsPassed() { //arrange. var serverResponseDTO = new ServerResponseDTO { OK = true, Error = CommonError.File_Exists.ToErrorString(), Reason = "some reason here" }; //act. var sut = new ServerResponse(serverResponseDTO); //assert. Assert.Equal(serverResponseDTO.OK, sut.OK); Assert.NotNull(sut.Error); Assert.True(sut.Error.CommonError.HasValue); Assert.True(sut.Error.CommonError.GetValueOrDefault().EqualsErrorString(serverResponseDTO.Error)); Assert.Equal(serverResponseDTO.Reason, sut.Error.Reason); Assert.Equal(serverResponseDTO.Reason, sut.Reason); }