public void Handle(ClientMessage.ReadEventsBackwards message) { _externalRequestQueue.Publish( new ClientMessage.ReadEventsBackwards( message.CorrelationId, new PublishToWrapEnvelop(_inputQueue, message.Envelope), message.EventStreamId, message.FromEventNumber, message.MaxCount, message.ResolveLinks)); }
void IHandle <ClientMessage.ReadEventsBackwards> .Handle(ClientMessage.ReadEventsBackwards message) { EventRecord[] records; EventRecord[] links = null; var lastCommitPosition = _readIndex.LastCommitPosition; var result = _readIndex.TryReadRecordsBackwards(message.EventStreamId, message.FromEventNumber, message.MaxCount, out records); var nextEventNumber = result == RangeReadResult.Success & records.Length > 0 ? records[records.Length - 1].EventNumber - 1 : -1; if (result == RangeReadResult.Success && records.Length > 1) { for (var index = 1; index < records.Length; index++) { if (records[index].EventNumber != records[index - 1].EventNumber - 1) { throw new Exception(string.Format( "Invalid order of events has been detected in read index for the event stream '{0}'. " + "The event {1} at position {2} goes after the event {3} at position {4}", message.EventStreamId, records[index].EventNumber, records[index].LogPosition, records[index - 1].EventNumber, records[index - 1].LogPosition)); } } } if (result == RangeReadResult.Success && message.ResolveLinks) { links = ResolveLinkToEvents(records); } message.Envelope.ReplyWith( new ClientMessage.ReadEventsBackwardsCompleted(message.CorrelationId, message.EventStreamId, records, links, result, nextEventNumber, records.Length == 0 ? lastCommitPosition : (long?)null)); }