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; }
public static void AddEntry(SubscriptionNode node) { SubscriptionNode newNode; newNode.objectType = node.objectType; newNode.eventType = node.eventType; newNode.eventDate = node.eventDate; journal.Add(node); }
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); }
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); }
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); }
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)); }
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); } }
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); }
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); }
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); }
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); } }
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; }
private SubscriptionNode GetOrCreateStarNode() { return _starNode ?? (_starNode = new SubscriptionNode(_nextPartIndex + 1, false)); }
private SubscriptionNode GetOrCreateStarNode() => _starNode ?? (_starNode = new SubscriptionNode(_nextPartIndex + 1));
private SubscriptionNode GetOrCreateStarNode() { return(_starNode ?? (_starNode = new SubscriptionNode(_nextPartIndex + 1, false))); }
private SubscriptionNode GetOrCreateSharpNode() { return(_sharpNode ?? (_sharpNode = new SubscriptionNode(_nextPartIndex + 1, true))); }
private SubscriptionNode GetOrCreateSharpNode() { return _sharpNode ?? (_sharpNode = new SubscriptionNode(_nextPartIndex + 1, true)); }