Esempio n. 1
0
        public void Write()
        {
            DefaultModel model = new DefaultModel();

            model.Type   = 123;
            model.Number = 500;
            model.Name   = "Default";

            string serialized = _writer.Serialize(model);

            Assert.Equal("123={\"type\":123,\"name\":\"Default\",\"number\":500}", serialized);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates web socket message from model and sends to specified client
        /// </summary>
        public static async Task SendAsync <TModel>(this SocketBase socket, TModel model, IModelWriter writer) where TModel : ISerializableModel
        {
            WebSocketMessage message = new WebSocketMessage
            {
                OpCode  = SocketOpCode.UTF8,
                Content = new MemoryStream(Encoding.UTF8.GetBytes(writer.Serialize(model)))
            };

            await socket.SendAsync(await _writer.Create(message));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates web socket message from model and sends to specified client
        /// </summary>
        public static void Send <TModel>(this SocketBase socket, TModel model, IModelWriter writer) where TModel : ISerializableModel
        {
            WebSocketMessage message = new WebSocketMessage
            {
                OpCode  = SocketOpCode.UTF8,
                Content = new MemoryStream(Encoding.UTF8.GetBytes(writer.Serialize(model)))
            };

            socket.Send(_writer.Create(message).Result);
        }