Example #1
0
        public ReadAllStreamOperation(HttpRequest request)
        {
            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
                ? LinkFormatter.FormatForwardLink(
                Constants.Streams.All,
                MaxCount,
                FromPositionInclusive,
                EmbedPayload)
                : LinkFormatter.FormatBackwardLink(
                Constants.Streams.All,
                MaxCount,
                FromPositionInclusive,
                EmbedPayload);

            IsUriCanonical = Self.Remove(0, Constants.Streams.All.Length)
                             == request.QueryString.ToUriComponent();
        }
Example #2
0
        public ReadStreamOperation(HttpRequest request)
        {
            StreamId = request.Path.Value.Remove(0, 1);

            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;

            Self = ReadDirection == Constants.ReadDirection.Forwards
                ? LinkFormatter.FormatForwardLink(StreamId, MaxCount, FromVersionInclusive, EmbedPayload)
                : LinkFormatter.FormatBackwardLink(StreamId, MaxCount, FromVersionInclusive, EmbedPayload);

            IsUriCanonical = Self.Remove(0, StreamId.Length)
                             == request.QueryString.ToUriComponent();
        }