Ejemplo n.º 1
0
        public void Setup()
        {
            _person = new Person();

            _ageAccessNode     = new PropertyAccessNode(typeof(Person).GetProperty("Age"));
            _brotherAccessNode = new PropertyAccessNode(typeof(Person).GetProperty("Brother"))
            {
                Children = new List <PropertyAccessTreeNode>()
                {
                    _ageAccessNode
                }
            };
            _parameterAccessNode = new ParameterNode(typeof(Person), "person")
            {
                Children = new List <PropertyAccessTreeNode>()
                {
                    _brotherAccessNode
                }
            };

            _brotherNode = new SubscriptionNode()
            {
                AccessNode = _brotherAccessNode
            };
            _target = new SubscriptionNode()
            {
                AccessNode = _parameterAccessNode, Children = new List <SubscriptionNode>()
                {
                    _brotherNode
                }
            };
            _target.Subject = _person;
        }
Ejemplo n.º 2
0
        public static void AddEntry(SubscriptionNode node)
        {
            SubscriptionNode newNode;

            newNode.objectType = node.objectType;
            newNode.eventType  = node.eventType;
            newNode.eventDate  = node.eventDate;
            journal.Add(node);
        }
Ejemplo n.º 3
0
        public void CreateSubscriptionTree_SimplePropertyAccess_TreeHasAllItems()
        {
            InitializeTargetJustAgeAccess();

            SubscriptionTree subscriptionTree = _target.CreateSubscriptionTree(_person);

            Assert.AreEqual(1, subscriptionTree.Children.Count);
            SubscriptionNode root = subscriptionTree.Children[0];

            Assert.AreEqual(_person, root.Subject);
            Assert.IsNull(root.Children);
        }
Ejemplo n.º 4
0
            private int UpdateChildNode(SubscriptionNode childNode, Peer peer, BindingKey subscription, UpdateAction action, string childNodePart, Action <SubscriptionNode, string> remover)
            {
                var update = childNode.Update(peer, subscription, action);

                _peerCountIncludingChildren += update;

                if (childNode.IsEmpty)
                {
                    remover(this, childNodePart);
                }

                return(update);
            }
Ejemplo n.º 5
0
        public void Setup()
        {
            _person = new Person();

            _ageAccessNode = new PropertyAccessNode(typeof(Person).GetProperty("Age"));
            _brotherAccessNode = new PropertyAccessNode(typeof(Person).GetProperty("Brother")) { Children = new List<PropertyAccessTreeNode>() { _ageAccessNode } };
            _parameterAccessNode = new ParameterNode(typeof(Person), "person") { Children = new List<PropertyAccessTreeNode>() { _brotherAccessNode } };

            _brotherNode = new SubscriptionNode() { AccessNode = _brotherAccessNode };
            _parameterNode = new SubscriptionNode() { AccessNode = _parameterAccessNode, Children = new List<SubscriptionNode>() { _brotherNode } };
            _parameterNode.Subject = _person;

            List<SubscriptionNode> nodes = new List<SubscriptionNode>() { _parameterNode };

            _target = new SubscriptionTree(_person, nodes);
        }
Ejemplo n.º 6
0
        public Task <IReadOnlyCollection <MqttQos> > AddSubscriptions(IMqttSession session, IReadOnlyDictionary <string, MqttQos> subscriptions)
        {
            List <MqttQos> result = new List <MqttQos>();

            foreach (KeyValuePair <string, MqttQos> subscription in subscriptions)
            {
                SubscriptionNode node = LookupNode(subscription.Key);
                if (node.subscribers == null)
                {
                    node.subscribers = new Dictionary <IMqttSession, MqttQos>();
                }
                node.subscribers[session] = subscription.Value;
                result.Add(subscription.Value);
            }
            return(Util.RunSynchronously <IReadOnlyCollection <MqttQos> >(() => result));
        }
Ejemplo n.º 7
0
        void AddNextNode(ref int cnt, int parentId, SubscriptionNode r, List <SubscriptionNode2> lst)
        {
            var foo = (new SubscriptionNode2
            {
                Id = cnt++,
                Pid = parentId,
                Name = r.Name,
                Type = r.Type,
            });

            foo.Experts.AddRange(r.Experts);
            lst.Add(foo);
            foreach (var c in r.Children)
            {
                AddNextNode(ref cnt, foo.Id, c, lst);
            }
        }
Ejemplo n.º 8
0
        public void CreateSubscriptionTree_TwoLevelPropertyAccess_TreeHasAllItems()
        {
            InitializeTargetBrothersAgeAccess();

            SubscriptionTree subscriptionTree = _target.CreateSubscriptionTree(_person);

            Assert.AreEqual(1, subscriptionTree.Children.Count);

            SubscriptionNode root = subscriptionTree.Children[0];

            Assert.AreEqual(_person, root.Subject);
            Assert.AreEqual(1, root.Children.Count);

            SubscriptionNode brotherSubscriptionNode = root.Children[0];

            Assert.AreEqual(_brotherPropertyAccessNode, brotherSubscriptionNode.AccessNode);
            Assert.IsNull(brotherSubscriptionNode.Children);
        }
Ejemplo n.º 9
0
 public Task RemoveSubscriptions(IMqttSession session, IEnumerable <string> topicFilters)
 {
     foreach (string topicFilter in topicFilters)
     {
         SubscriptionNode node = LookupNode(topicFilter);
         if (node.subscribers != null && node.subscribers.Remove(session))
         {
             //TODO: clean up dead branches, recursively.
             //    if (node.subscribers.Count == 0 && node.children.Count == 0)
             //    {
             //        int lastSlash = topicFilter.LastIndexOf('/')
             //        string parentTopic = topicFilter.Substring(0, topicFilter.LastIndexOf('/'));
             //        SubscriptionNode parentNode = LookupNode(parentTopic);
             //        parentNode.children.Remove()
             //    }
         }
     }
     return(Util.CompletedTask);
 }
Ejemplo n.º 10
0
        private SubscriptionNode LookupNode(string topicFilter)
        {
            SubscriptionNode node = subscriptionRoot;

            foreach (string segment in topicFilter.Split('/'))
            {
                if (node.children == null)
                {
                    node.children = new Dictionary <string, SubscriptionNode>();
                }
                SubscriptionNode next;
                if (!node.children.TryGetValue(segment, out next))
                {
                    next = new SubscriptionNode();
                    node.children.Add(segment, next);
                }
                node = next;
            }
            return(node);
        }
Ejemplo n.º 11
0
        void AddNextNode(ref int cnt, int parentId, SubscriptionNode r, List <LoadData> lst)
        {
            var foo = (new LoadData
            {
                Id = cnt++,
                Parent = parentId,
                Text = r.Name,
            });

            lst.Add(foo);
            if (r.Children.Count == 0)
            {
                foo.HasChild = false;
            }
            else
            {
                foo.HasChild = true;
            }
            foreach (var c in r.Children)
            {
                AddNextNode(ref cnt, foo.Id, c, lst);
            }
        }
Ejemplo n.º 12
0
            private int UpdateChildNode(SubscriptionNode childNode, Peer peer, BindingKey subscription, UpdateAction action, string childNodePart, Action<SubscriptionNode, string> remover)
            {
                var update = childNode.Update(peer, subscription, action);
                _peerCountIncludingChildren += update;
                
                if (childNode.IsEmpty)
                    remover(this, childNodePart);

                return update;
            }
Ejemplo n.º 13
0
 private SubscriptionNode GetOrCreateStarNode()
 {
     return _starNode ?? (_starNode = new SubscriptionNode(_nextPartIndex + 1, false));
 }
Ejemplo n.º 14
0
 private SubscriptionNode GetOrCreateStarNode()
 => _starNode ?? (_starNode = new SubscriptionNode(_nextPartIndex + 1));
Ejemplo n.º 15
0
 private SubscriptionNode GetOrCreateStarNode()
 {
     return(_starNode ?? (_starNode = new SubscriptionNode(_nextPartIndex + 1, false)));
 }
Ejemplo n.º 16
0
 private SubscriptionNode GetOrCreateSharpNode()
 {
     return(_sharpNode ?? (_sharpNode = new SubscriptionNode(_nextPartIndex + 1, true)));
 }
Ejemplo n.º 17
0
 private SubscriptionNode GetOrCreateSharpNode()
 {
     return _sharpNode ?? (_sharpNode = new SubscriptionNode(_nextPartIndex + 1, true));
 }