示例#1
0
            public static IEnumerable <Link> Navigation(
                ReadStreamMessageOptions options,
                StreamMessage message = default(StreamMessage))
            {
                yield return(First());

                if (options.StreamVersion > 0)
                {
                    yield return(Previous(options));
                }

                if (message.MessageId != default(Guid))
                {
                    yield return(Next(options));
                }

                yield return(Last());
            }
        private static MidFunc GetStreamMessage(StreamResource stream) => next => async env =>
        {
            var context = new OwinContext(env);

            var options = new ReadStreamMessageOptions(context.Request);

            var response = await stream.GetMessage(options, context.Request.CallCancelled);

            if (options.StreamVersion == StreamVersion.End)
            {
                context.Response.StatusCode          = 307;
                context.Response.ReasonPhrase        = "Moved Temporarily";
                context.Response.Headers["Location"] = $"{((dynamic) response.Hal.Model).StreamVersion}";

                return;
            }

            await context.WriteHalResponse(response);
        };
示例#3
0
        public async Task <Response> GetMessage(
            ReadStreamMessageOptions options,
            CancellationToken cancellationToken)
        {
            var operation = options.GetReadOperation();

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

            if (message.MessageId == Guid.Empty)
            {
                return(new Response(
                           new HALResponse(new
                {
                    options.StreamId,
                    options.StreamVersion
                })
                           .AddLinks(StreamMessageLinks.Self(options))
                           .AddLinks(StreamMessageLinks.Navigation(options))
                           .AddLinks(StreamLinks.Feed(options)),
                           404));
            }

            var payload = await message.GetJsonData(cancellationToken);

            return(new Response(
                       new HALResponse(new
            {
                message.MessageId,
                message.CreatedUtc,
                message.Position,
                message.StreamId,
                message.StreamVersion,
                message.Type,
                payload
            })
                       .AddLinks(StreamMessageLinks.Self(options))
                       .AddLinks(StreamMessageLinks.Navigation(options, message))
                       .AddLinks(StreamLinks.Feed(options))));
        }
示例#4
0
 public static Link Self(ReadStreamMessageOptions options) => new Link(
     Relations.Self,
     $"{options.StreamVersion}");
示例#5
0
 public static Link Feed(ReadStreamMessageOptions options) => new Link(
     Relations.Feed,
     LinkFormatter.FormatBackwardLink($"../{options.StreamId}", 20, StreamVersion.End));
示例#6
0
 private static Link Next(ReadStreamMessageOptions options) => new Link(
     Relations.Next,
     $"{options.StreamVersion + 1}");
示例#7
0
 private static Link Previous(ReadStreamMessageOptions options) => new Link(
     Relations.Previous,
     $"{options.StreamVersion - 1}");