public static Links StreamMessageNavigation( this Links links, StreamMessage message, ReadStreamMessageByStreamVersionOperation operation) { links.Add(Constants.Relations.First, $"{StreamId(operation)}/0"); if (operation.StreamVersion > 0) { links.Add(Constants.Relations.Previous, $"{StreamId(operation)}/{operation.StreamVersion - 1}"); } if (message.StreamId != default) { links.Add(Constants.Relations.Next, $"{StreamId(operation)}/{operation.StreamVersion + 1}"); } return(links.Add(Constants.Relations.Last, $"{StreamId(operation)}/-1") .Add( Constants.Relations.Feed, Links.FormatBackwardLink( StreamId(operation), Constants.MaxCount, StreamVersion.End, false), operation.StreamId) .Add( Constants.Relations.Message, $"{StreamId(operation)}/{operation.StreamVersion}", $"{operation.StreamId}@{operation.StreamVersion}").Self()); }
public async Task <Response> Get( ReadAllStreamMessageOperation operation, CancellationToken cancellationToken) { var message = await operation.Invoke(_streamStore, cancellationToken); var links = Links .FromOperation(operation) .Index() .Find() .Browse() .Add( Constants.Relations.Message, $"stream/{message.Position}", $"{message.StreamId}@{message.StreamVersion}").Self() .Add( Constants.Relations.Feed, Links.FormatBackwardLink( Constants.Streams.All, Constants.MaxCount, Position.End, false)); if (message.MessageId == Guid.Empty) { return(new HalJsonResponse( new HALResponse(null) .AddLinks(links), 404)); } var payload = await message.GetJsonData(cancellationToken); return(new HalJsonResponse(new StreamMessageHALResponse(message, payload).AddLinks(links))); }
public static Links StreamsNavigation(this Links links, ReadStreamPage page, ReadStreamOperation operation) { var baseAddress = $"streams/{operation.StreamId}"; var first = Links.FormatForwardLink( baseAddress, operation.MaxCount, StreamVersion.Start, operation.EmbedPayload); var last = Links.FormatBackwardLink( baseAddress, operation.MaxCount, StreamVersion.End, operation.EmbedPayload); links.Add(Constants.Relations.First, first); if (operation.Self != first && !page.IsEnd) { links.Add( Constants.Relations.Previous, Links.FormatBackwardLink( baseAddress, operation.MaxCount, page.Messages.Min(m => m.StreamVersion) - 1, operation.EmbedPayload)); } links.Add(Constants.Relations.Feed, operation.Self, operation.StreamId).Self(); if (operation.Self != last && !page.IsEnd) { links.Add( Constants.Relations.Next, Links.FormatForwardLink( baseAddress, operation.MaxCount, page.Messages.Max(m => m.StreamVersion) + 1, operation.EmbedPayload)); } links.Add(Constants.Relations.Last, last) .Add(Constants.Relations.Metadata, $"{baseAddress}/metadata"); return(links); }
public static Links AllStreamNavigation( this Links links, ReadAllPage page, ReadAllStreamOperation operation) { var first = Links.FormatForwardLink( Constants.Streams.All, operation.MaxCount, Position.Start, operation.EmbedPayload); var last = Links.FormatBackwardLink( Constants.Streams.All, operation.MaxCount, Position.End, operation.EmbedPayload); links.Add(Constants.Relations.First, first); if (operation.Self != first && !page.IsEnd) { links.Add( Constants.Relations.Previous, Links.FormatBackwardLink( Constants.Streams.All, operation.MaxCount, page.Messages.Min(m => m.Position) - 1, operation.EmbedPayload)); } links.Add(Constants.Relations.Feed, operation.Self).Self(); if (operation.Self != last && !page.IsEnd) { links.Add( Constants.Relations.Next, Links.FormatForwardLink( Constants.Streams.All, operation.MaxCount, page.Messages.Max(m => m.Position) + 1, operation.EmbedPayload)); } links.Add(Constants.Relations.Last, last); return(links); }
public ReadAllStreamOperation(HttpRequest request) { Path = request.Path; EmbedPayload = request.Query.TryGetValueCaseInsensitive('e', out var embedPayload) && embedPayload == "1"; ReadDirection = request.Query.TryGetValueCaseInsensitive('d', out var readDirection) && readDirection == "f" || readDirection == "F" ? Constants.ReadDirection.Forwards : Constants.ReadDirection.Backwards; _fromPositionInclusive = request.Query.TryGetValueCaseInsensitive('p', out var position) ? (long.TryParse(position, out _fromPositionInclusive) ? (_fromPositionInclusive < Position.End ? Position.End : _fromPositionInclusive) : (ReadDirection == Constants.ReadDirection.Forwards ? Position.Start : Position.End)) : (ReadDirection == Constants.ReadDirection.Forwards ? Position.Start : Position.End); _maxCount = request.Query.TryGetValueCaseInsensitive('m', out var maxCount) ? (int.TryParse(maxCount, out _maxCount) ? (_maxCount <= 0 ? Constants.MaxCount : _maxCount) : Constants.MaxCount) : Constants.MaxCount; Self = ReadDirection == Constants.ReadDirection.Forwards ? Links.FormatForwardLink( Constants.Streams.All, MaxCount, FromPositionInclusive, EmbedPayload) : Links.FormatBackwardLink( Constants.Streams.All, MaxCount, FromPositionInclusive, EmbedPayload); IsUriCanonical = Self.Remove(0, Constants.Streams.All.Length) == request.QueryString.ToUriComponent(); }
public ReadStreamOperation(HttpRequest request) { Path = request.Path; StreamId = request.Path.Value.Remove(0, 2 + Constants.Streams.Stream.Length); EmbedPayload = request.Query.TryGetValueCaseInsensitive('e', out var embedPayload) && embedPayload == "1"; ReadDirection = request.Query.TryGetValueCaseInsensitive('d', out var readDirection) && readDirection == "f" || readDirection == "F" ? Constants.ReadDirection.Forwards : Constants.ReadDirection.Backwards; _fromVersionInclusive = request.Query.TryGetValueCaseInsensitive('p', out var position) ? int.TryParse(position, out _fromVersionInclusive) ? ReadDirection == Constants.ReadDirection.Forwards ? _fromVersionInclusive < StreamVersion.Start ? StreamVersion.Start : _fromVersionInclusive : _fromVersionInclusive < StreamVersion.End ? StreamVersion.End : _fromVersionInclusive : ReadDirection == Constants.ReadDirection.Forwards ? StreamVersion.Start : StreamVersion.End : ReadDirection == Constants.ReadDirection.Forwards ? StreamVersion.Start : StreamVersion.End; _maxCount = request.Query.TryGetValueCaseInsensitive('m', out var maxCount) ? int.TryParse(maxCount, out _maxCount) ? _maxCount <= 0 ? Constants.MaxCount : _maxCount : Constants.MaxCount : Constants.MaxCount; var baseAddress = $"streams/{StreamId}"; Self = ReadDirection == Constants.ReadDirection.Forwards ? Links.FormatForwardLink(baseAddress, MaxCount, FromVersionInclusive, EmbedPayload) : Links.FormatBackwardLink(baseAddress, MaxCount, FromVersionInclusive, EmbedPayload); IsUriCanonical = Self.Remove(0, baseAddress.Length) == request.QueryString.ToUriComponent(); }
public async Task all_stream_head_link(HttpMethod method) { await _fixture.WriteNMessages(StreamId, 10); var position = await _fixture.StreamStore.ReadHeadPosition(); using (var response = await _fixture.HttpClient.SendAsync( new HttpRequestMessage( method, Links.FormatBackwardLink("/stream", 20, Position.End, true)))) { response.IsSuccessStatusCode.ShouldBeTrue(); response.Headers.GetValues(Constants.Headers.HeadPosition) .ShouldBe(new[] { $"{position}" }); } }