Ejemplo n.º 1
0
 public LocalPublicationFilterResult(ILocalPublicationFilterState state, bool cancelPublication)
 {
     state.EnsureNotNull(nameof(state));
     //
     _state             = state;
     _cancelPublication = cancelPublication;
 }
Ejemplo n.º 2
0
        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;
                        }
                    }