Пример #1
0
        private static ArraySegment <byte> AsSignalRMessage(object messageObj)
        {
            var message = JsonConvert.SerializeObject(
                messageObj,
                Formatting.None,
                new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var encoded = Encoding.UTF8.GetBytes(message);
            var bytes   = new ArraySegment <byte>(encoded);

            // Append 0x1e to denote end of message for SignalR server.
            return(bytes.Append((byte)0x1e).ToArray());
        }