protected virtual void PublicationFilter(LocalPublicationFilterEventArgs <TPayload> e) { e.EnsureNotNull(nameof(e)); // if (TryReadDA(location: ref _activatedSubscription, considerDisposeRequest: true, result: out var activatedSubscription)) { e.Cancel = !ReferenceEquals(e.Subscription, activatedSubscription); }
protected sealed override void PublicationFilter(LocalPublicationFilterEventArgs <TPayload> e) { base.PublicationFilter(e); // if (!e.OnceCanceled) { TryReadDA(ref _publicationFilter)?.Invoke(e); } }
void ILocalPublicationFilterListener.PublicationFilter(object sender, LocalPublicationFilterEventArgs eventArgs) { eventArgs.EnsureNotNull(nameof(eventArgs)); // var msg = eventArgs.Message as ILocalMessage <TPayload>; if (msg is null) { eventArgs.Cancel = true; } else { var locEventArgs = new LocalPublicationFilterEventArgs <TPayload>(subscription: eventArgs.Subscription, message: msg); PublicationFilter(locEventArgs); eventArgs.Cancel = locEventArgs.OnceCanceled; } }
public async Task <LocalPublicationFilterResult> PublicationFilterAsync(ILocalPublicationFilterState state) { state.EnsureNotNull(nameof(state)); // await Task.CompletedTask; // ILocalMessage msg; if ((msg = state.Message).IsDisposeRequested || !IsActive) { return(new LocalPublicationFilterResult(state: state, cancelPublication: true)); } else { bool eval() { bool locCancelPublication; // if (IsActive) { var locEventArgs = new LocalPublicationFilterEventArgs(subscription: this, message: msg); if (TryReadDA(ref _publisher, considerDisposeRequest: true, out var locIssuer) && TryReadDA(ref _subscriber, considerDisposeRequest: true, out var locSubscriber) && TryReadDA(ref _publisherAsIPublicationFilterListener, considerDisposeRequest: true, out var locFilterListener) && TryReadDA(ref _subscriberAsIPublicationFilterListener, considerDisposeRequest: true, out var locSubscriberListener)) { // try { FirePublicationFilter(locEventArgs); locCancelPublication = locEventArgs.OnceCanceled || !IsActive; } catch (ObjectDisposedException) { if (IsDisposeRequested) { locCancelPublication = true; } else { throw; } } if (!locCancelPublication) { bool locIsCanceledByListener(ILocalPublicationFilterListener locListener) { if (locListener is null) { return(false); } else { try { locListener.PublicationFilter(sender: this, e: locEventArgs); return(locEventArgs.OnceCanceled); } catch (ObjectDisposedException) { var locListenerAsIDisposable = locListener as IEonDisposable; if (locListenerAsIDisposable?.IsDisposeRequested ?? false) { return(true); } else { throw; } } } } locCancelPublication = locIsCanceledByListener(locFilterListener) || locIsCanceledByListener(locSubscriberListener) || !IsActive; } } else { locCancelPublication = true; } }