Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ControlServerExtension.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
10
12{
17 {
18 private ControlParameterNode[] parameters;
19
26 : base(Parent, Model)
27 {
28 }
29
33 public override string LocalName => nameof(ControlServerExtension);
34
42 {
44 }
45
50 public override async Task FromXml(XmlElement Definition)
51 {
52 await base.FromXml(Definition);
53
54 List<ControlParameterNode> Parameters = new List<ControlParameterNode>();
55
56 foreach (ISimulationNode Node in this.Children)
57 {
58 if (Node is ControlParameterNode Parameter)
59 Parameters.Add(Parameter);
60 }
61
62 this.parameters = Parameters.ToArray();
63 }
64
71 public override Task<object> Add(IActor Instance, Waher.Networking.XMPP.XmppClient Client)
72 {
73 ControlServer Extension;
74
75 if (Client.TryGetTag("ProvisioningClient", out object Obj) && Obj is ProvisioningClient ProvisioningClient)
76 Extension = new ControlServer(Client, ProvisioningClient);
77 else
78 Extension = new ControlServer(Client);
79
80 Client.SetTag("ControlServer", Extension);
81
82 Extension.OnGetControlParameters += (Node) =>
83 {
84 this.Model.ExternalEvent(Instance, "OnGetControlParameters",
85 new KeyValuePair<string, object>("Node", Node),
86 new KeyValuePair<string, object>("Client", Client));
87
88 List<ControlParameter> Parameters = new List<ControlParameter>();
89
90 foreach (ControlParameterNode Parameter in this.parameters)
91 Parameter.AddParameters(Parameters, Instance);
92
93 return Task.FromResult<ControlParameter[]>(Parameters.ToArray());
94 };
95
96 return Task.FromResult<object>(Extension);
97 }
98
99 }
100}
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 void AddParameters(List< ControlParameter > Parameters, IActor Actor)
Adds control parameters.
override Task< object > Add(IActor Instance, Waher.Networking.XMPP.XmppClient Client)
Adds the extension to the client.
ControlServerExtension(ISimulationNode Parent, Model Model)
Control Server XMPP extension
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.
override async Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Abstract base class for IoT XMPP extensions.
Implements an XMPP control server interface.
Implements an XMPP provisioning client interface.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
Abstract base class for control parameters.
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