/// <summary> /// Sends the given <paramref name="data"/> as a message of the specified <paramref name="type"/> /// </summary> /// /// <param name="type">The type of message being sent</param> /// <param name="data">The data to send within the message</param> private void SendMessage(MessageType type, AcquireNetworkModel data = null) { Utilities.SendMessageToConnection(client, data, type); }
/// <summary> /// Sends a JSON message made from the provided <paramref name="model"/> and <paramref name="type"/> to the given <paramref name="connection"/> /// </summary> /// /// <param name="connection">The connection to send the generated message to</param> /// <param name="model">The data to serialize inside the message</param> /// <param name="type">The type of message to serialize</param> public static void SendMessageToConnection(Connection connection, AcquireNetworkModel model, MessageType type) { SendMessageToConnection(connection, GetNetworkMessageString(model, type)); }
/// <summary> /// Creates a network message with the given parameters /// </summary> /// /// <param name="data">The data to send along with this message</param> /// <param name="type">What type of data this message represents</param> public NetworkMessage(AcquireNetworkModel data, MessageType type) { Data = data; MessageType = type; }
/// <summary> /// Creates a <see cref="NetworkMessage"/> from the given <paramref name="model"/> and <paramref name="type"/> and serializes it to JSON /// </summary> /// /// <param name="model">The data to serialize inside the message</param> /// <param name="type">The type of message to serialize</param> /// /// <returns>A JSON string representing a new <see cref="NetworkMessage"/> containing the given <paramref name="model"/> and <paramref name="type"/></returns> public static string GetNetworkMessageString(AcquireNetworkModel model, MessageType type) => JsonConvert.SerializeObject(new NetworkMessage(model, type), new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto });