Example #1
0
        private void ServiceDiscoveryResponse(object Sender, ServiceDiscoveryEventArgs e)
        {
            if (e.Ok)
            {
                XmppContact Node = (XmppContact)e.State;
                object      OldTag;

                if (e.HasFeature(ConcentratorServer.NamespaceConcentrator))
                {
                    bool SupportsEvents = e.HasFeature(SensorClient.NamespaceSensorEvents);

                    OldTag = Node.Tag;
                    Node   = new XmppConcentrator(Node.Parent, this.client, Node.BareJID, SupportsEvents)
                    {
                        Tag = OldTag
                    };

                    this.children[Node.Key] = Node;

                    if (SupportsEvents)
                    {
                        this.AddGroups(Node, ConcentratorGroupName, EventsGroupName);
                    }
                    else
                    {
                        this.AddGroups(Node, ConcentratorGroupName);
                    }
                }
                else if (e.HasFeature(ControlClient.NamespaceControl))
                {
                    bool IsSensor       = e.HasFeature(SensorClient.NamespaceSensorData);
                    bool SupportsEvents = e.HasFeature(SensorClient.NamespaceSensorEvents);

                    OldTag = Node.Tag;
                    Node   = new XmppActuator(Node.Parent, this.client, Node.BareJID, IsSensor, SupportsEvents)
                    {
                        Tag = OldTag
                    };

                    this.children[Node.Key] = Node;

                    List <string> Groups = new List <string>()
                    {
                        ActuatorGroupName
                    };

                    if (IsSensor)
                    {
                        Groups.Add(SensorGroupName);
                    }

                    if (SupportsEvents)
                    {
                        Groups.Add(EventsGroupName);
                    }

                    this.AddGroups(Node, Groups.ToArray());
                }
                else if (e.HasFeature(SensorClient.NamespaceSensorData))
                {
                    bool SupportsEvents = e.HasFeature(SensorClient.NamespaceSensorEvents);

                    OldTag = Node.Tag;
                    Node   = new XmppSensor(Node.Parent, this.client, Node.BareJID, SupportsEvents)
                    {
                        Tag = OldTag
                    };

                    this.children[Node.Key] = Node;

                    List <string> Groups = new List <string>()
                    {
                        SensorGroupName
                    };

                    if (SupportsEvents)
                    {
                        Groups.Add(EventsGroupName);
                    }

                    this.AddGroups(Node, Groups.ToArray());
                }
                else
                {
                    OldTag = Node.Tag;
                    Node   = new XmppOther(Node.Parent, this.client, Node.BareJID)
                    {
                        Tag = OldTag
                    };

                    this.children[Node.Key] = Node;

                    this.AddGroups(Node, OtherGroupName);
                }

                this.OnUpdated();
            }
        }
Example #2
0
        private void CheckRoster()
        {
            SortedDictionary <string, TreeNode> Contacts = this.children;
            Dictionary <string, TreeNode>       Existing = new Dictionary <string, TreeNode>();
            LinkedList <TreeNode> Added = null;
            LinkedList <KeyValuePair <string, TreeNode> > Removed = null;
            LinkedList <RosterItem> Resubscribe   = null;
            LinkedList <RosterItem> Reunsubscribe = null;

            if (Contacts == null)
            {
                Contacts = new SortedDictionary <string, TreeNode>();
            }

            lock (Contacts)
            {
                foreach (RosterItem Item in this.client.Roster)
                {
                    if (Contacts.TryGetValue(Item.BareJid, out TreeNode Contact))
                    {
                        Existing[Item.BareJid] = Contact;
                    }
                    else
                    {
                        if (Item.IsInGroup(ConcentratorGroupName))
                        {
                            Contact = new XmppConcentrator(this, this.client, Item.BareJid, Item.IsInGroup(EventsGroupName));
                        }
                        else if (Item.IsInGroup(ActuatorGroupName))
                        {
                            Contact = new XmppActuator(this, this.client, Item.BareJid, Item.IsInGroup(SensorGroupName), Item.IsInGroup(EventsGroupName));
                        }
                        else if (Item.IsInGroup(SensorGroupName))
                        {
                            Contact = new XmppSensor(this, this.client, Item.BareJid, Item.IsInGroup(EventsGroupName));
                        }
                        else if (Item.IsInGroup(OtherGroupName))
                        {
                            Contact = new XmppOther(this, this.client, Item.BareJid);
                        }
                        else
                        {
                            Contact = new XmppContact(this, this.client, Item.BareJid);
                        }

                        Contacts[Item.BareJid] = Contact;

                        if (Added == null)
                        {
                            Added = new LinkedList <TreeNode>();
                        }

                        Added.AddLast(Contact);
                    }

                    switch (Item.PendingSubscription)
                    {
                    case PendingSubscription.Subscribe:
                        if (Resubscribe == null)
                        {
                            Resubscribe = new LinkedList <RosterItem>();
                        }

                        Resubscribe.AddLast(Item);
                        break;

                    case PendingSubscription.Unsubscribe:
                        if (Reunsubscribe == null)
                        {
                            Reunsubscribe = new LinkedList <RosterItem>();
                        }

                        Reunsubscribe.AddLast(Item);
                        break;
                    }
                }

                if (this.children == null)
                {
                    this.children = Contacts;
                }
                else
                {
                    foreach (KeyValuePair <string, TreeNode> P in this.children)
                    {
                        if (P.Value is XmppContact Contact &&
                            !Existing.ContainsKey(Contact.BareJID))
                        {
                            if (Removed == null)
                            {
                                Removed = new LinkedList <KeyValuePair <string, TreeNode> >();
                            }

                            Removed.AddLast(P);
                        }
                    }

                    if (Removed != null)
                    {
                        foreach (KeyValuePair <string, TreeNode> P in Removed)
                        {
                            this.children.Remove(P.Key);
                        }
                    }
                }
            }

            if (Added != null)
            {
                foreach (TreeNode Node in Added)
                {
                    this.connections.Owner.MainView.NodeAdded(this, Node);
                }
            }

            if (Removed != null)
            {
                foreach (KeyValuePair <string, TreeNode> P in Removed)
                {
                    this.connections.Owner.MainView.NodeRemoved(this, P.Value);
                }
            }

            if (Resubscribe != null)
            {
                foreach (RosterItem Item in Resubscribe)
                {
                    this.client.RequestPresenceSubscription(Item.BareJid);
                }
            }

            if (Reunsubscribe != null)
            {
                foreach (RosterItem Item in Reunsubscribe)
                {
                    this.client.RequestPresenceUnsubscription(Item.BareJid);
                }
            }

            this.OnUpdated();
        }