private void DisownDevice_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; XmppContact Contact = (XmppContact)Item.Tag; this.registryClient.Disown(Contact.BareJID, (sender2, e2) => { if (e2.Ok) { MainWindow.SuccessBox(Contact.BareJID + " has been disowned."); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to disown " + Contact.BareJID + "." : e2.ErrorText); } }, null); }
private void ReconfigureDevice_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; XmppContact Contact = (XmppContact)Item.Tag; this.provisioningClient.DeleteDeviceRules(Contact.BareJID, (sender2, e2) => { if (e2.Ok) { MainWindow.SuccessBox("The rules in " + Contact.BareJID + " have been deleted."); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to delete the rules in " + Contact.BareJID + "." : e2.ErrorText); } }, null); }
private void ClearRuleCache_Click(object sender, RoutedEventArgs e) { MenuItem Item = (MenuItem)sender; XmppContact Contact = (XmppContact)Item.Tag; this.provisioningClient.ClearDeviceCache(Contact.BareJID, (sender2, e2) => { if (e2.Ok) { MainWindow.SuccessBox("The rule cache in " + Contact.BareJID + " has been cleared."); } else { MainWindow.ErrorBox(string.IsNullOrEmpty(e2.ErrorText) ? "Unable to clear the rule cache in " + Contact.BareJID + "." : e2.ErrorText); } }, null); }
private void Client_OnRosterItemUpdated(object Sender, RosterItem Item) { if (this.children == null) { this.CheckRoster(); } else { XmppContact Contact; bool Added = false; lock (this.children) { if (this.children.TryGetValue(Item.BareJid, out TreeNode Node)) { if ((Contact = Node as XmppContact) != null) { Contact.RosterItem = Item; } } else { Contact = new XmppContact(this, this.client, Item.BareJid); this.children[Item.BareJid] = Contact; Added = true; } } if (Added) { this.connections.Owner.MainView.NodeAdded(this, Contact); this.OnUpdated(); } else { Contact.OnUpdated(); } } }
private void AddGroups(XmppContact Contact, params string[] GroupNames) { string[] Groups = Contact.RosterItem.Groups; bool Updated = false; int c; foreach (string GroupName in GroupNames) { if (Array.IndexOf <string>(Groups, GroupName) < 0) { c = Groups.Length; Array.Resize <string>(ref Groups, c + 1); Groups[c] = GroupName; Updated = true; } } if (Updated) { Array.Sort <string>(Groups); this.client.UpdateRosterItem(Contact.BareJID, Contact.RosterItem.Name, Groups); } }
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(); } }
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(); }