Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ThingRegistryClientExtension.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
8
10{
15 {
16 private string componentAddress;
17
24 : base(Parent, Model)
25 {
26 }
27
31 public override string LocalName => nameof(ThingRegistryClientExtension);
32
40 {
42 }
43
48 public override Task FromXml(XmlElement Definition)
49 {
50 this.componentAddress = XML.Attribute(Definition, "componentAddress");
51
52 return base.FromXml(Definition);
53 }
54
61 public override Task<object> Add(IActor Instance, Waher.Networking.XMPP.XmppClient Client)
62 {
63 if (Client.ContainsTag("ConcentratorServer"))
64 throw new Exception("Define thing registry clients before any concentrator server extensions.");
65
66 ThingRegistryClient Extension = new ThingRegistryClient(Client, this.componentAddress);
67 Client.SetTag("ThingRegistryClient", Extension);
68
69 Extension.Claimed += (Sender, e) =>
70 {
71 this.Model.ExternalEvent(Instance, "Claimed",
72 new KeyValuePair<string, object>("e", e),
73 new KeyValuePair<string, object>("Client", Client));
74
75 return Task.CompletedTask;
76 };
77
78 Extension.Disowned += (Sender, e) =>
79 {
80 this.Model.ExternalEvent(Instance, "Disowned",
81 new KeyValuePair<string, object>("e", e),
82 new KeyValuePair<string, object>("Client", Client));
83
84 return Task.CompletedTask;
85 };
86
87 Extension.Removed += (Sender, e) =>
88 {
89 this.Model.ExternalEvent(Instance, "Removed",
90 new KeyValuePair<string, object>("e", e),
91 new KeyValuePair<string, object>("Client", Client));
92
93 return Task.CompletedTask;
94 };
95
96 return Task.FromResult<object>(Extension);
97 }
98 }
99}
Root node of a simulation model
Definition: Model.cs:49
bool ExternalEvent(IExternalEventsNode Source, string Name, params KeyValuePair< string, object >[] Arguments)
Method called when an external event has been received.
Definition: Model.cs:889
Abstract base class for IoT XMPP extensions.
override Task< object > Add(IActor Instance, Waher.Networking.XMPP.XmppClient Client)
Adds the extension to the client.
override string LocalName
Local name of XML element defining contents of class.
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
ThingRegistryClientExtension(ISimulationNode Parent, Model Model)
ThingRegistry Client XMPP extension
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Helps with common XML-related tasks.
Definition: XML.cs:19
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Definition: XML.cs:914
Implements an XMPP thing registry client interface.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
Definition: IActor.cs:11
Definition: App.xaml.cs:4