private ClientMessage.ReadEventCompleted ReadEvent(ClientMessage.ReadEvent msg) { try { var access = _readIndex.CheckStreamAccess(msg.EventStreamId, StreamAccessType.Read, msg.User); if (!access.Granted) { return(NoData(msg, ReadEventResult.AccessDenied)); } var result = _readIndex.ReadEvent(msg.EventStreamId, msg.EventNumber); var record = result.Result == ReadEventResult.Success && msg.ResolveLinkTos ? ResolveLinkToEvent(result.Record, msg.User) : new ResolvedEvent(result.Record); if (record == null) { return(NoData(msg, ReadEventResult.AccessDenied)); } return(new ClientMessage.ReadEventCompleted(msg.CorrelationId, msg.EventStreamId, result.Result, record.Value, result.Metadata, access.Public, null)); } catch (Exception exc) { Log.ErrorException(exc, "Error during processing ReadEvent request."); return(NoData(msg, ReadEventResult.Error, exc.Message)); } }
private ClientMessage.ReadEventCompleted ReadEvent(ClientMessage.ReadEvent msg) { using (HistogramService.Measure(_readerReadHistogram)) { try { var access = _readIndex.CheckStreamAccess(msg.EventStreamId, StreamAccessType.Read, msg.User); if (!access.Granted) { return(NoData(msg, ReadEventResult.AccessDenied)); } var result = _readIndex.ReadEvent(msg.EventStreamId, msg.EventNumber); var record = result.Result == ReadEventResult.Success && msg.ResolveLinkTos ? ResolveLinkToEvent(result.Record, msg.User, null) : ResolvedEvent.ForUnresolvedEvent(result.Record); if (record == null) { return(NoData(msg, ReadEventResult.AccessDenied)); } if ((result.Result == ReadEventResult.NoStream || result.Result == ReadEventResult.NotFound) && result.OriginalStreamExists && SystemStreams.IsSystemStream(msg.EventStreamId)) { return(NoData(msg, ReadEventResult.Success)); } return(new ClientMessage.ReadEventCompleted(msg.CorrelationId, msg.EventStreamId, result.Result, record.Value, result.Metadata, access.Public, null)); } catch (Exception exc) { Log.ErrorException(exc, "Error during processing ReadEvent request."); return(NoData(msg, ReadEventResult.Error, exc.Message)); } } }
private ResolvedEvent ResolveLinkToEvent(EventRecord eventRecord, long commitPosition) { if (eventRecord.EventType == SystemEventTypes.LinkTo) { try { string[] parts = Helper.UTF8NoBom.GetString(eventRecord.Data).Split('@'); long eventNumber = long.Parse(parts[0]); string streamId = parts[1]; var res = _readIndex.ReadEvent(streamId, eventNumber); if (res.Result == ReadEventResult.Success) { return(ResolvedEvent.ForResolvedLink(res.Record, eventRecord, commitPosition)); } return(ResolvedEvent.ForFailedResolvedLink(eventRecord, res.Result, commitPosition)); } catch (Exception exc) { Log.ErrorException(exc, "Error while resolving link for event record: {0}", eventRecord.ToString()); } return(ResolvedEvent.ForFailedResolvedLink(eventRecord, ReadEventResult.Error, commitPosition)); } return(ResolvedEvent.ForUnresolvedEvent(eventRecord, commitPosition)); }
void IHandle <ClientMessage.ReadEvent> .Handle(ClientMessage.ReadEvent message) { var result = _readIndex.ReadEvent(message.EventStreamId, message.EventNumber); EventRecord record = result.Record; if (result.Result == SingleReadResult.Success && message.ResolveLinkTos) { Debug.Assert(result.Record != null); record = ResolveLinkToEvent(record) ?? record; } //TODO: consider returning redirected stream and ChunkNumber number message.Envelope.ReplyWith(new ClientMessage.ReadEventCompleted(message.CorrelationId, message.EventStreamId, message.EventNumber, result.Result, record)); }
public IndexReadEventResult ReadEvent(string streamName, TStreamId streamId, long eventNumber) => _readIndex.ReadEvent(streamName, streamId, eventNumber);
public static IndexReadEventResult ReadEvent <TStreamId>(this IReadIndex <TStreamId> self, string streamName, long eventNumber) { var streamId = self.GetStreamId(streamName); return(self.ReadEvent(streamName, streamId, eventNumber)); }
public static IndexReadEventResult ReadEvent(this IReadIndex <string> index, string streamName, long eventNumber) => index.ReadEvent(streamName, streamName, eventNumber);