コード例 #1
0
        /// <summary>
        /// Returns a cloned instance with the same subscribers as the original, minus the new <paramref name="subscriber"/>
        /// </summary>
        /// <param name="current"></param>
        /// <param name="subscriber"></param>
        /// <returns></returns>
        public static BrokerServiceState RemoveSubscriber(BrokerServiceState current, Reference subscriber)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            return(RemoveSubscriber(current, subscriber.ServiceOrActorReference));
        }
コード例 #2
0
        /// <summary>
        /// Returns a cloned instance with the same subscribers as the original, plus the new <paramref name="subscriber"/>
        /// </summary>
        /// <param name="current"></param>
        /// <param name="subscriber"></param>
        /// <returns></returns>
        public static BrokerServiceState AddSubscriber(BrokerServiceState current, Reference subscriber)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }
            if (current.Subscribers.Any(s => s.ServiceOrActorReference.Equals(subscriber.ServiceOrActorReference)))
            {
                return(current);
            }

            var clone = new BrokerServiceState(current.MessageTypeName, ((ImmutableList <Reference>)current.Subscribers).Add(subscriber));

            return(clone);
        }
コード例 #3
0
        /// <summary>
        /// Returns a cloned instance with the same subscribers as the original, minus the new <paramref name="subscriber"/>
        /// </summary>
        /// <param name="current"></param>
        /// <param name="subscriber"></param>
        /// <returns></returns>
        public static BrokerServiceState RemoveSubscriber(BrokerServiceState current, ReferenceWrapper subscriber)
        {
            if (current == null)
            {
                throw new ArgumentNullException(nameof(current));
            }
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            if (current.Subscribers.All(s => s.ServiceOrActorReference != subscriber))
            {
                return(current);
            }

            var clone = new BrokerServiceState(current.MessageTypeName, ((ImmutableList <Reference>)current.Subscribers).RemoveAll(s => s.ServiceOrActorReference == subscriber));

            return(clone);
        }