/// <inheritdoc />
        protected override async Task OnMessageReceivedAsync(IWebSocketContext context, byte[] rxBuffer,
                                                             IWebSocketReceiveResult rxResult)
        {
            string  text = Encoding.GetString(rxBuffer);
            JsEvent evt  = JsonUtils.DeserializeFromJson <JsEvent>(text);

            Logger.Info("Got message of type {0}", evt.Type);

            if (evt.Type == "spam")
            {
                // wait some time, simulating actual work being done and then respond with a big chunk of text
                Random rnd = new Random();
                await Task.Delay(rnd.Next(50, 150));

                var responseEvent = new JsEvent("spam-back")
                {
                    Data = JsDataRow.GenerateLargeTable()
                };
                await SendTargetedEvent(context, responseEvent).ConfigureAwait(false);
            }
        }
Пример #2
0
        public static List <JsDataRow> GenerateLargeTable()
        {
            var          random = new Random();
            const string chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
            var          rows   = new List <JsDataRow>();

            for (var i = 0; i < 1000; i++)
            {
                var row  = new JsDataRow();
                var cols = new List <string>();
                for (var j = 0; j < 10; j++)
                {
                    cols.Add(new string(
                                 Enumerable.Repeat(chars, 20)
                                 .Select(s => s[random.Next(s.Length)]).ToArray()));
                }

                row.Columns = cols;
                rows.Add(row);
            }

            return(rows);
        }