async Task <TResult> ReadQueryCheckpoint <TResult>(FlowKey key, Func <TResult> getDefault, Func <ResolvedEvent, TResult> getCheckpoint) { var stream = key.GetCheckpointStream(); EventReadResult result = default(EventReadResult); try { result = await _context.Connection.ReadEventAsync(stream, StreamPosition.End, resolveLinkTos : false); } catch (Exception e) { Console.WriteLine(e.Message); } switch (result.Status) { case EventReadStatus.NoStream: case EventReadStatus.NotFound: return(getDefault()); case EventReadStatus.Success: return(getCheckpoint(result.Event.Value)); default: throw new Exception($"Unexpected result when reading {stream}: {result.Status}"); } }
public async Task <FlowResumeInfo> ReadFlowResumeInfo(FlowKey key) { var stream = key.GetCheckpointStream(); var result = await _context.Connection.ReadEventAsync(stream, StreamPosition.End, resolveLinkTos : false); switch (result.Status) { case EventReadStatus.NoStream: return(await new ReadFlowWithoutCheckpointCommand(_context, key).Execute()); case EventReadStatus.Success: return(await new ReadFlowWithCheckpointCommand(_context, key, result.Event?.Event).Execute()); default: throw new Exception($"Unexpected result when reading {stream} to resume: {result.Status}"); } }
internal async Task <FlowInfo> Execute() { var stream = _key.GetCheckpointStream(); var result = await _context.Connection.ReadEventAsync(stream, StreamPosition.End, resolveLinkTos : false); switch (result.Status) { case EventReadStatus.NoStream: case EventReadStatus.NotFound: return(new FlowInfo.NotFound()); case EventReadStatus.Success: _checkpoint = result.Event.Value; _metadata = _context.ReadCheckpointMetadata(_checkpoint); return(ReadFlow()); default: throw new Exception($"Unexpected result when reading {stream}: {result.Status}"); } }