Exemple #1
0
        /// <summary>
        /// Removes the content handler from the subscription asynchronously.
        /// </summary>
        /// <param name="channel">The channel from which unsubscribe.</param>
        /// <param name="contentHandler">The content handler to be removed from this subscription.</param>
        /// <param name="keepUnderlyingSubscription">Indicates if the node should keep the underlying subscription to the channel in order to improve efficiency in future subscriptions to it.</param>
        /// <returns>A task which value is true if the operation succeeded.</returns>
        public virtual Task <bool> Unsubscribe(string channel, ContentHandler contentHandler, bool keepUnderlyingSubscription = false)
        {
            if (!IsConnected)
            {
                throw new NodeDisconnectedException();
            }

            if (string.IsNullOrWhiteSpace(channel))
            {
                throw new ArgumentNullException(nameof(channel));
            }

            if (contentHandler == null)
            {
                throw new ArgumentNullException(nameof(contentHandler));
            }

            channel = channel.ToLower();

            if (_channelsSubscriptions.Remove(contentHandler, channel))
            {
                contentHandler.BeginInvoke(null, new IrisContextHook {
                    Unsubscribing = true
                }, null, null);

                // If there aren't any subscriptions and there's no request of keeping the underlying subscription
                if (!_channelsSubscriptions.GetSubscriptions(channel, true).Any() && !keepUnderlyingSubscription)
                {
                    return(Publish(new IrisUnsubscribe(Id, channel)));
                }
            }

            return(_completedFailedTask);
        }
Exemple #2
0
        /// <summary>
        /// Removes the content handler from the broadcast communication asynchronously.
        /// </summary>
        /// <param name="contentHandler">The content handler to be removed from the broadcast.</param>
        /// <returns>A task which value is true if the operation succeeded.</returns>
        public Task <bool> UnsubscribeFromBroadcast(ContentHandler contentHandler)
        {
            if (!IsConnected)
            {
                throw new NodeDisconnectedException();
            }

            if (contentHandler == null)
            {
                throw new ArgumentNullException(nameof(contentHandler));
            }

            if (_broadcastHandlers.Remove(contentHandler))
            {
                contentHandler.BeginInvoke(null, new IrisContextHook {
                    Unsubscribing = true
                }, null, null);
                return(_completedSucceededTask);
            }

            return(_completedFailedTask);
        }