public async Task <Response> GetPage(
            ReadAllStreamOptions options,
            CancellationToken cancellationToken)
        {
            var operation = options.GetReadOperation();

            var page = await operation.Invoke(_streamStore, cancellationToken);

            var payloads = await Task.WhenAll(page.Messages
                                              .Select(message => options.EmbedPayload
                    ? message.GetJsonData(cancellationToken)
                    : Task.FromResult <string>(null))
                                              .ToArray());

            return(new Response(
                       new HALResponse(new object())
                       .AddLinks(Links.SelfFeed(options))
                       .AddLinks(Links.Navigation(page, options.Self))
                       .AddLinks(Links.Feed)
                       .AddEmbeddedCollection(
                           Relations.Message,
                           page.Messages.Zip(payloads,
                                             (message, payload) => new HALResponse(new
            {
                message.MessageId,
                message.CreatedUtc,
                message.Position,
                message.StreamId,
                message.StreamVersion,
                message.Type,
                payload
            }).AddLinks(
                                                 Links.Self(message))))));
        }
Beispiel #2
0
        private static MidFunc GetStream(AllStreamResource allStream) => next => async env =>
        {
            var context = new OwinContext(env);

            var options = new ReadAllStreamOptions(context.Request);

            var response = await allStream.GetPage(options, context.Request.CallCancelled);

            await context.WriteHalResponse(response);
        };
 public static Link SelfFeed(ReadAllStreamOptions options)
 => new Link(Relations.Self, options.Self);