2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Windows.Input;
5using System.Windows.Media;
17 private readonly Dictionary<string, Node> nodes =
new Dictionary<string, Node>();
18 private DateTime timer = DateTime.MinValue;
19 private readonly
string key;
20 private readonly
string header;
21 private readonly
bool hasChildSources;
22 private bool unsubscribed =
false;
29 this.hasChildSources = HasChildSources;
31 this.children =
new SortedDictionary<string, TreeNode>()
33 {
string.Empty,
new Loading(
this) }
39 if (this.timer > DateTime.MinValue)
42 this.timer = DateTime.MinValue;
48 public override string Key => this.key;
49 public override string Header => this.header;
50 public override string ToolTip =>
"Data source";
51 public override string TypeName =>
"Data Source";
52 public override bool CanAddChildren =>
false;
53 public override bool CanEdit =>
false;
54 public override bool CanDelete =>
false;
55 public override bool CanRecycle =>
false;
57 public override ImageSource ImageResource
68 public override void Write(XmlWriter Output)
79 while (!(Loop is
null))
91 private bool loadingChildren =
false;
95 if (!this.loadingChildren && !this.IsLoaded)
97 string FullJid = this.Concentrator?.FullJid;
99 if (!
string.IsNullOrEmpty(FullJid))
101 Mouse.OverrideCursor = Cursors.Wait;
103 if (this.hasChildSources)
105 this.loadingChildren =
true;
106 this.Concentrator.XmppAccountNode.ConcentratorClient.
GetChildDataSources(FullJid, this.key, (Sender, e) =>
108 this.loadingChildren =
false;
113 SortedDictionary<string, TreeNode> Children = new SortedDictionary<string, TreeNode>();
115 foreach (DataSourceReference Ref in e.DataSources)
117 DataSource DataSource = new DataSource(this, Ref.SourceID, Ref.SourceID, Ref.HasChildren);
118 Children[Ref.SourceID] = DataSource;
120 DataSource.SubscribeToEvents();
126 this.Concentrator?.NodesAdded(
Children.Values,
this);
129 return Task.CompletedTask;
134 this.loadingChildren =
true;
135 this.Concentrator.XmppAccountNode.ConcentratorClient.
GetRootNodes(FullJid, this.key,
true,
true,
136 "en",
string.Empty,
string.Empty,
string.Empty, (Sender, e) =>
138 this.loadingChildren =
false;
143 SortedDictionary<string, TreeNode> Children = new SortedDictionary<string, TreeNode>();
145 foreach (NodeInformation Ref in e.NodesInformation)
146 Children[Ref.NodeId] = new Node(this, Ref);
148 this.children = Children;
151 this.NodesAdded(Children.Values, this);
154 return Task.CompletedTask;
163 public void NodesAdded(IEnumerable<TreeNode> Nodes,
TreeNode Parent)
169 if (Node is Node Node2)
171 string Key = Node2.Partition +
" " + Node2.NodeId;
172 this.nodes[Key] = Node2;
177 this.Concentrator?.NodesAdded(Nodes, Parent);
180 public void NodesRemoved(IEnumerable<TreeNode> Nodes, TreeNode Parent)
184 foreach (TreeNode Node
in Nodes)
186 if (Node is Node Node2)
188 string Key = Node2.Partition +
" " + Node2.NodeId;
189 this.nodes.Remove(Key);
194 this.Concentrator?.NodesRemoved(Nodes, Parent);
197 public void SubscribeToEvents()
199 this.SubscribeToEvents(
true);
202 private void SubscribeToEvents(
object State)
204 if (this.unsubscribed)
207 if (!(State is
bool))
210 XmppConcentrator Concentrator = this.Concentrator;
211 XmppAccountNode XmppAccountNode = Concentrator?.XmppAccountNode;
217 string FullJid = Concentrator.FullJid;
219 if (this.timer > DateTime.MinValue)
221 MainWindow.Scheduler?.Remove(this.timer);
222 this.timer = DateTime.MinValue;
226 string.Empty,
string.Empty,
string.Empty, (Sender, e) =>
229 this.timer = MainWindow.Scheduler.Add(DateTime.Now.AddMinutes(5), this.SubscribeToEvents, false);
231 this.timer = MainWindow.Scheduler.Add(DateTime.Now.AddMinutes(1), this.SubscribeToEvents, false);
233 return Task.CompletedTask;
237 public void UnsubscribeFromEvents()
239 this.unsubscribed =
true;
241 if (this.timer > DateTime.MinValue)
243 MainWindow.Scheduler?.Remove(this.timer);
244 this.timer = DateTime.MinValue;
247 XmppConcentrator Concentrator = this.Concentrator;
248 if (Concentrator is
null)
251 XmppAccountNode XmppAccountNode = Concentrator.XmppAccountNode;
252 if (XmppAccountNode is
null)
255 string FullJid = Concentrator.FullJid;
260 XmppAccountNode.ConcentratorClient.Unsubscribe(FullJid, this.key,
SourceEventType.All,
"en",
261 string.Empty,
string.Empty,
string.Empty,
null,
null);
266 base.UnloadChildren();
270 if (!(this.children is
null))
271 this.NodesRemoved(this.children.Values,
this);
273 this.children =
new SortedDictionary<string, TreeNode>()
275 {
string.Empty,
new Loading(
this) }
285 string Key, ParentKey;
299 if (this.nodes.ContainsKey(Key))
300 return Task.CompletedTask;
302 if (!this.nodes.TryGetValue(ParentKey, out Parent))
303 return Task.CompletedTask;
311 this.nodes[Key] =
Node;
325 if (!this.nodes.TryGetValue(Key, out Node))
328 return Task.CompletedTask;
331 if (!this.nodes.TryGetValue(OldKey, out Node))
332 return Task.CompletedTask;
334 this.nodes.Remove(OldKey);
335 this.nodes[Key] = Node;
356 if (!this.nodes.TryGetValue(Key, out Node))
357 return Task.CompletedTask;
359 this.nodes.Remove(Key);
362 Node.Parent.RemoveChild(Node);
363 this.NodesRemoved(
new TreeNode[] { Node }, Node.Parent);
374 if (!this.nodes.TryGetValue(Key, out Node))
375 return Task.CompletedTask;
380 Node.NodeInformation.HasChildren, Node.NodeInformation.ChildrenOrdered, Node.NodeInformation.IsReadable, Node.NodeInformation.IsControllable,
381 Node.NodeInformation.HasCommands, Node.NodeInformation.Sniffable, Node.NodeInformation.ParentId, Node.NodeInformation.ParentPartition,
382 Node.NodeInformation.LastChanged, Node.NodeInformation.ParameterList,
null);
395 if (!this.nodes.TryGetValue(Key, out Node))
396 return Task.CompletedTask;
410 if (!this.nodes.TryGetValue(Key, out Node))
411 return Task.CompletedTask;
419 return Task.CompletedTask;
Interaction logic for xaml
Represents a data source in a concentrator.
override void UnloadChildren()
Method is called to notify children can be unloaded.
override void Write(XmlWriter Output)
Saves the object to a file.
override void LoadChildren()
Method is called to make sure children are loaded.
override void Dispose()
Disposes of the node and its resources.
Represents a node in a concentrator.
override void Add()
Is called when the user wants to add a node to the current node.
Represents an XMPP concentrator.
Represents a data source in a concentrator.
Abstract base class for tree nodes in the connection view.
TreeNode[] Children
Children of the node. If null, children are not loaded.
TreeNode Parent
Parent node. May be null if a root node.
virtual void OnUpdated()
Raises the Updated event.
bool IsExpanded
If the node is expanded.
Class representing a normal XMPP account.
Implements an XMPP concentrator client interface.
Task Subscribe(string To, string SourceID, int TimeoutSeconds, SourceEventType EventTypes, bool Parameters, bool Messages, string Language, string ServiceToken, string DeviceToken, string UserToken, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Subscribes to data source events.
ConcentratorClient(XmppClient Client)
Implements an XMPP concentrator client interface.
Task GetChildDataSources(string To, string SourceID, EventHandlerAsync< DataSourcesEventArgs > Callback, object State)
Gets all child data sources for a data source on the server.
Task GetRootNodes(string To, string SourceID, bool Parameters, bool Messages, string Language, string ServiceToken, string DeviceToken, string UserToken, EventHandlerAsync< NodesInformationEventArgs > Callback, object State)
Gets information about all root nodes in a data source.
Event arguments for data source section events.
SourceEvent Event
Source Event
string DisplayName
Display name.
string NodeType
Type of node, at time of event.
bool Sniffable
If node was sniffable, at time of event.
string NodeId
Node identity.
string LogId
Log identity, if different from NodeId.
string Partition
Optional partition.
string LocalId
Local identity, if different from NodeId.
string ParentPartition
Partition of parent of node, at time of event.
string ParentId
Parent identity of node, at time of event.
bool HasChildren
If node had children, at time of event.
bool ChildrenOrdered
If node children was ordered, at time of event.
bool IsControllable
If node was controllable, at time of event.
Parameter[] Parameters
Displayable parameters.
DateTime Updated
When node was last updated, at time of event.
bool HasCommands
If node had commands, at time of event.
bool IsReadable
If node was readable, at time of event.
Node status changed event.
NodeState State
State of node, at time of event.
string OldId
If renamed, this property contains the node identity before the node was renamed.
Abstract base class for all data source events.
abstract SourceEventType EventType
Type of data source event.
string SourceId
Data source identity.
SourceEventType
Data Source event types