Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ProvisioningClientExtension.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(ProvisioningClientExtension);
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("SensorServer"))
64 throw new Exception("Define provisioning clients before any sensor server extensions.");
65
66 if (Client.ContainsTag("ControlServer"))
67 throw new Exception("Define provisioning clients before any control server extensions.");
68
69 if (Client.ContainsTag("ConcentratorServer"))
70 throw new Exception("Define provisioning clients before any concentrator server extensions.");
71
72 ProvisioningClient Extension = new ProvisioningClient(Client, this.componentAddress);
73 Client.SetTag("ProvisioningClient", Extension);
74
75 Extension.CanControlQuestion += (Sender, e) =>
76 {
77 this.Model.ExternalEvent(Instance, "OnExecuteReadoutRequest",
78 new KeyValuePair<string, object>("e", e),
79 new KeyValuePair<string, object>("Client", Client));
80
81 return Task.CompletedTask;
82 };
83
84 Extension.CanReadQuestion += (Sender, e) =>
85 {
86 this.Model.ExternalEvent(Instance, "CanReadQuestion",
87 new KeyValuePair<string, object>("e", e),
88 new KeyValuePair<string, object>("Client", Client));
89
90 return Task.CompletedTask;
91 };
92
93 Extension.IsFriendQuestion += (Sender, e) =>
94 {
95 this.Model.ExternalEvent(Instance, "IsFriendQuestion",
96 new KeyValuePair<string, object>("e", e),
97 new KeyValuePair<string, object>("Client", Client));
98
99 return Task.CompletedTask;
100 };
101
102 Extension.CacheCleared += (Sender, e) =>
103 {
104 this.Model.ExternalEvent(Instance, "CacheCleared",
105 new KeyValuePair<string, object>("e", e),
106 new KeyValuePair<string, object>("Client", Client));
107
108 return Task.CompletedTask;
109 };
110
111 return Task.FromResult<object>(Extension);
112 }
113 }
114}
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.
ProvisioningClientExtension(ISimulationNode Parent, Model Model)
Provisioning Client XMPP extension
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
override string LocalName
Local name of XML element defining contents of class.
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 provisioning 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