public ValueTask <bool> Filter(BaseOriginalEvent originalEvent) { var propValue = _getProp(originalEvent); var pass = _include.IsNullOrMatch(propValue) && _exclude.IsNullOrDoesntMatch(propValue); return(new ValueTask <bool>(pass)); }
public PrepareContext( BaseOriginalEvent originalEvent, CancellationToken cancellationToken ) : base(cancellationToken) { OriginalEvent = originalEvent; }
public void IgnoreEvent() { OriginalEvent = new IgnoredOriginalEvent( OriginalEvent.Created, OriginalEvent.EventDetails, OriginalEvent.Position, OriginalEvent.SequenceNumber, OriginalEvent.TracingMetadata ); }
public static async ValueTask <bool> CombinedFilter( BaseOriginalEvent originalEvent, params FilterEvent[] filters ) { foreach (var filter in filters) { if (!await filter(originalEvent)) { return(false); } } return(true); }
public async ValueTask <bool> Filter( BaseOriginalEvent originalEvent ) { if (originalEvent is not OriginalEvent) { return(true); } var meta = await _cache.GetOrAddStreamMeta( originalEvent.EventDetails.Stream, _connection.GetStreamMeta ).ConfigureAwait(false); var isDeleted = meta.IsDeleted && meta.DeletedAt > originalEvent.Created; return(!isDeleted && !Truncated() && !TtlExpired() && !await OverMaxCount().ConfigureAwait(false)); bool TtlExpired() => meta.MaxAge.HasValue && originalEvent.Created < DateTime.Now - meta.MaxAge; bool Truncated() => meta.TruncateBefore.HasValue && originalEvent.Position.EventNumber < meta.TruncateBefore; // add the check timestamp, so we can check again if we get newer events (edge case) async Task <bool> OverMaxCount() { if (!meta.MaxCount.HasValue) { return(false); } var streamSize = await _cache.GetOrAddStreamSize( originalEvent.EventDetails.Stream, _connection.GetStreamSize ).ConfigureAwait(false); return(originalEvent.Position.EventNumber < streamSize.LastEventNumber - meta.MaxCount); } }
public ValueTask <bool> Filter(BaseOriginalEvent originalEvent) => _filter.Filter(originalEvent);
public static ValueTask <bool> EmptyFilter(BaseOriginalEvent originalEvent) => new(true);