public override async Task Read( ReadReq request, IServerStreamWriter <ReadResp> responseStream, ServerCallContext context) { var options = request.Options; var countOptionsCase = options.CountOptionCase; var streamOptionsCase = options.StreamOptionCase; var readDirection = options.ReadDirection; var filterOptionsCase = options.FilterOptionCase; var uuidOptionsCase = options.UuidOption.ContentCase; var user = context.GetHttpContext().User; var requiresLeader = GetRequiresLeader(context.RequestHeaders); var op = streamOptionsCase switch { StreamOptionOneofCase.Stream => ReadOperation.WithParameter( Authorization.Operations.Streams.Parameters.StreamId(request.Options.Stream.StreamName)), StreamOptionOneofCase.All => ReadOperation.WithParameter( Authorization.Operations.Streams.Parameters.StreamId(SystemStreams.AllStream)), _ => throw new InvalidOperationException() }; if (!await _provider.CheckAccessAsync(user, op, context.CancellationToken).ConfigureAwait(false)) { throw AccessDenied(); } await using var enumerator = (streamOptionsCase, countOptionsCase, readDirection, filterOptionsCase) switch { (StreamOptionOneofCase.Stream, CountOptionOneofCase.Count, ReadDirection.Forwards, FilterOptionOneofCase.NoFilter) => (IAsyncEnumerator <ResolvedEvent>) new Enumerators.ReadStreamForwards( _publisher, request.Options.Stream.StreamName, request.Options.Stream.ToStreamRevision(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, context.CancellationToken), (StreamOptionOneofCase.Stream, CountOptionOneofCase.Count, ReadDirection.Backwards, FilterOptionOneofCase.NoFilter) => new Enumerators.ReadStreamBackwards( _publisher, request.Options.Stream.StreamName, request.Options.Stream.ToStreamRevision(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, context.CancellationToken), (StreamOptionOneofCase.All, CountOptionOneofCase.Count, ReadDirection.Forwards, FilterOptionOneofCase.NoFilter) => new Enumerators.ReadAllForwards( _publisher, request.Options.All.ToPosition(), request.Options.Count, request.Options.ResolveLinks, user, requiresLeader, context.Deadline, context.CancellationToken), (StreamOptionOneofCase.All, CountOptionOneofCase.Count, ReadDirection.Forwards, FilterOptionOneofCase.Filter) => new Enumerators.ReadAllForwardsFiltered( _publisher, request.Options.All.ToPosition(), request.Options.Count, request.Options.ResolveLinks, ConvertToEventFilter(request.Options.Filter), request.Options.Filter.WindowCase switch { ReadReq.Types.Options.Types.FilterOptions.WindowOneofCase.Count => null, ReadReq.Types.Options.Types.FilterOptions.WindowOneofCase.Max => request.Options.Filter.Max, _ => throw new InvalidOperationException() },
public override async Task Read( ReadReq request, IServerStreamWriter <ReadResp> responseStream, ServerCallContext context) { var options = request.Options; var countOptionsCase = options.CountOptionsCase; var streamOptionsCase = options.StreamOptionsCase; var readDirection = options.ReadDirection; var filterOptionsCase = options.FilterOptionsCase; var user = await GetUser(_authenticationProvider, context.RequestHeaders); await using var enumerator = (streamOptionsCase, countOptionsCase, readDirection, filterOptionsCase) switch { (StreamOptionsOneofCase.Stream, CountOptionsOneofCase.Count, ReadDirection.Forwards, FilterOptionsOneofCase.NoFilter) => (IAsyncEnumerator <ResolvedEvent>) new Enumerators.ReadStreamForwards( _queue, request.Options.Stream.StreamName, request.Options.Stream.ToStreamRevision(), request.Options.Count, request.Options.ResolveLinks, user, context.CancellationToken), (StreamOptionsOneofCase.Stream, CountOptionsOneofCase.Count, ReadDirection.Backwards, FilterOptionsOneofCase.NoFilter) => new Enumerators.ReadStreamBackwards( _queue, request.Options.Stream.StreamName, request.Options.Stream.ToStreamRevision(), request.Options.Count, request.Options.ResolveLinks, user, context.CancellationToken), (StreamOptionsOneofCase.All, CountOptionsOneofCase.Count, ReadDirection.Forwards, FilterOptionsOneofCase.NoFilter) => new Enumerators.ReadAllForwards( _queue, request.Options.All.ToPosition(), request.Options.Count, request.Options.ResolveLinks, user, context.CancellationToken), (StreamOptionsOneofCase.All, CountOptionsOneofCase.Count, ReadDirection.Forwards, FilterOptionsOneofCase.Filter) => new Enumerators.ReadAllForwardsFiltered( _queue, request.Options.All.ToPosition(), request.Options.Count, request.Options.ResolveLinks, ConvertToEventFilter(request.Options.Filter), request.Options.Filter.WindowCase switch { ReadReq.Types.Options.Types.FilterOptions.WindowOneofCase.Count => default(int?), ReadReq.Types.Options.Types.FilterOptions.WindowOneofCase.Max => request.Options.Filter.Max, _ => throw new InvalidOperationException() },