示例#1
0
            public ValueTask <bool> Filter(BaseOriginalEvent originalEvent)
            {
                var propValue = _getProp(originalEvent);
                var pass      = _include.IsNullOrMatch(propValue) && _exclude.IsNullOrDoesntMatch(propValue);

                return(new ValueTask <bool>(pass));
            }
示例#2
0
 public PrepareContext(
     BaseOriginalEvent originalEvent, CancellationToken cancellationToken
     )
     : base(cancellationToken)
 {
     OriginalEvent = originalEvent;
 }
示例#3
0
 public void IgnoreEvent()
 {
     OriginalEvent = new IgnoredOriginalEvent(
         OriginalEvent.Created,
         OriginalEvent.EventDetails,
         OriginalEvent.Position,
         OriginalEvent.SequenceNumber,
         OriginalEvent.TracingMetadata
         );
 }
示例#4
0
        public static async ValueTask <bool> CombinedFilter(
            BaseOriginalEvent originalEvent, params FilterEvent[] filters
            )
        {
            foreach (var filter in filters)
            {
                if (!await filter(originalEvent))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#5
0
        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);
            }
        }
示例#6
0
 public ValueTask <bool> Filter(BaseOriginalEvent originalEvent) => _filter.Filter(originalEvent);
示例#7
0
 public static ValueTask <bool> EmptyFilter(BaseOriginalEvent originalEvent) => new(true);