private async ValueTask WriteCurrentMessageGroupAsync()
        {
            var templateContext = CreateTemplateContext(new Dictionary <string, object>
            {
                ["MessageGroup"] = MessageGroup.Join(_messageGroupBuffer)
            });

            await templateContext.EvaluateAsync(_messageGroupTemplate.Page);
        }
Exemplo n.º 2
0
        public void I_should_be_able_to_join_a_bunch_of_messages_into_a_group()
        {
            object[] items = new object[] { new PingMessage(), new PongMessage() };

            MessageGroup group = MessageGroup.Join(items);

            Assert.That(group.Count, Is.EqualTo(2));

            Assert.That(group[0], Is.TypeOf(typeof(PingMessage)));
            Assert.That(group[1], Is.TypeOf(typeof(PongMessage)));
        }
        public override async ValueTask WritePostambleAsync()
        {
            // Flush current message group
            if (_messageGroupBuffer.Any())
            {
                await WriteMessageGroupAsync(MessageGroup.Join(_messageGroupBuffer));
            }

            var templateContext = new LayoutTemplateContext(Context, _themeName, _messageCount);
            var templateBundle  = await TemplateBundle.ResolveAsync();

            await _writer.WriteLineAsync(
                await templateBundle.PostambleTemplate.RenderAsync(templateContext)
                );
        }
        public override async ValueTask WriteMessageAsync(Message message)
        {
            // If message group is empty or the given message can be grouped, buffer the given message
            if (!_messageGroupBuffer.Any() || MessageGroup.CanJoin(_messageGroupBuffer.Last(), message))
            {
                _messageGroupBuffer.Add(message);
            }
            // Otherwise, flush the group and render messages
            else
            {
                await WriteMessageGroupAsync(MessageGroup.Join(_messageGroupBuffer));

                _messageGroupBuffer.Clear();
                _messageGroupBuffer.Add(message);
            }

            // Increment message count
            _messageCount++;
        }