Example #1
0
            public int Update(Peer peer, BindingKey subscription, UpdateAction action)
            {
                if (IsLeaf(subscription))
                {
                    var update = UpdateList(peer, action);
                    _peerCountIncludingChildren += update;

                    return(update);
                }

                var nextPart = subscription.GetPart(_nextPartIndex);

                if (subscription.IsSharp(_nextPartIndex) || nextPart == null)
                {
                    var sharpNode = GetOrCreateSharpNode();
                    return(UpdateChildNode(sharpNode, peer, subscription, action, null, _removeSharpNode));
                }

                if (subscription.IsStar(_nextPartIndex))
                {
                    var starNode = GetOrCreateStarNode();
                    return(UpdateChildNode(starNode, peer, subscription, action, null, _removeStarNode));
                }

                var childNode = GetOrAddChildNode(nextPart);

                return(UpdateChildNode(childNode, peer, subscription, action, nextPart, _removeNode));
            }
        public static Func <IMessage, bool> GetPredicate(Type messageType, BindingKey bindingKey)
        {
            if (bindingKey.IsEmpty)
            {
                return(_ => true);
            }

            var cacheItem = GetOrCreateCacheItem(messageType);

            var count         = Math.Min(cacheItem.MembersToStringExpressions.Count, bindingKey.PartCount);
            var subPredicates = new List <Expression>();

            for (var index = 0; index < count; index++)
            {
                if (bindingKey.IsSharp(index))
                {
                    break;
                }

                if (bindingKey.IsStar(index))
                {
                    continue;
                }

                var part = bindingKey.GetPart(index);
                var memberToStringExpression = cacheItem.MembersToStringExpressions[index];
                subPredicates.Add(Expression.MakeBinary(ExpressionType.Equal, memberToStringExpression, Expression.Constant(part)));
            }

            if (!subPredicates.Any())
            {
                return(_ => true);
            }

            var finalExpression = subPredicates.Aggregate((Expression)null, (final, exp) => final == null ? exp : Expression.AndAlso(final, exp));

            return((Func <IMessage, bool>)Expression.Lambda(finalExpression, cacheItem.ParameterExpression).Compile());
        }