public void TryDeserializeLoadAssemblyCommand() { mocks.ReplayAll(); var objects = new object[] { null, new byte[0] }; string serialized = commandSerializer.Serialize(objects, new List <Type>()); ICommand command; Assert.AreEqual(true, commandSerializer.TryDeserializeCommand(serialized, out command)); Assert.IsInstanceOfType(typeof(LoadAssemblyCommand), command); }
private byte[] Serialize(ITftpCommand command) { using (MemoryStream stream = new MemoryStream()) { CommandSerializer serializer = new CommandSerializer(); serializer.Serialize(command, stream); byte[] commandAsBytes = stream.GetBuffer(); Array.Resize(ref commandAsBytes, (int)stream.Length); return(commandAsBytes); } }
public void Serialize_ClientListCommand() { var commandSerializer = new CommandSerializer(); var clientListCommand = new ClientListCommand { SenderInformation = new ServerInformation(string.Empty,string.Empty,new Version()), AvailableClients =new List<IClientInformation>(), }; commandSerializer.Serialize(clientListCommand); }
public void Send(Commands command) { try { CommandSerializer serializer = new CommandSerializer(); byte[] packet = serializer.Serialize(command); var cmpr = Compression.Compress(packet); var len2 = cmpr.Length; DataSocket.Send(BitConverter.GetBytes(len2)); DataSocket.BeginSend(cmpr, 0, cmpr.Length, SocketFlags.None, SentCallback, null); } catch (Exception ex) { MessageBox.Show(ex.Message, "An error occured", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Send(ITFtpCommand command) { if (m_client == null) { throw new ObjectDisposedException(nameof(UdpChannel)); } if (m_endpoint == null) { throw new InvalidOperationException("RemoteEndpoint needs to be set before you can send TFTP commands."); } using (MemoryStream stream = new MemoryStream()) { m_serializer.Serialize(command, stream); byte[] data = stream.GetBuffer(); m_client.Send(data, (int)stream.Length, m_endpoint); } }
public void UpdatePlayersCommand_SerializationRoundTrip() { var cmd = new UpdatePlayersCommand(); cmd.Players = new[] { "Test1", "Test2" }; string json = Serializer.Serialize(cmd); Assert.IsFalse(string.IsNullOrWhiteSpace(json)); Assert.IsTrue(json.Contains("Test1")); Assert.IsTrue(json.Contains("Test2")); if (Serializer.Deserialize(json) is UpdatePlayersCommand cmd2) { Assert.IsTrue(cmd.Players.Length == 2); Assert.AreEqual("Test1", cmd.Players[0]); Assert.AreEqual("Test2", cmd.Players[1]); } else { Assert.Fail(); } }