Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PubSubExtension.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(PubSubExtension);
32
40 {
41 return new PubSubExtension(Parent, Model);
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 PubSubClient Extension = new PubSubClient(Client, this.componentAddress);
64 Client.SetTag("PubSub", Extension);
65
66 Extension.AffiliationNotification += (Sender, e) =>
67 {
68 this.Model.ExternalEvent(Instance, "AffiliationNotification",
69 new KeyValuePair<string, object>("e", e),
70 new KeyValuePair<string, object>("Client", Client));
71
72 return Task.CompletedTask;
73 };
74
75 Extension.ItemNotification += (Sender, e) =>
76 {
77 this.Model.ExternalEvent(Instance, "ItemNotification",
78 new KeyValuePair<string, object>("e", e),
79 new KeyValuePair<string, object>("Client", Client));
80
81 return Task.CompletedTask;
82 };
83
84 Extension.ItemRetracted += (Sender, e) =>
85 {
86 this.Model.ExternalEvent(Instance, "ItemRetracted",
87 new KeyValuePair<string, object>("e", e),
88 new KeyValuePair<string, object>("Client", Client));
89
90 return Task.CompletedTask;
91 };
92
93 Extension.NodePurged += (Sender, e) =>
94 {
95 this.Model.ExternalEvent(Instance, "NodePurged",
96 new KeyValuePair<string, object>("e", e),
97 new KeyValuePair<string, object>("Client", Client));
98
99 return Task.CompletedTask;
100 };
101
102 Extension.SubscriptionRequest += (Sender, e) =>
103 {
104 this.Model.ExternalEvent(Instance, "SubscriptionRequest",
105 new KeyValuePair<string, object>("e", e),
106 new KeyValuePair<string, object>("Client", Client));
107
108 return Task.CompletedTask;
109 };
110
111 Extension.SubscriptionStatusChanged += (Sender, e) =>
112 {
113 this.Model.ExternalEvent(Instance, "SubscriptionStatusChanged",
114 new KeyValuePair<string, object>("e", e),
115 new KeyValuePair<string, object>("Client", Client));
116
117 return Task.CompletedTask;
118 };
119
120 return Task.FromResult<object>(Extension);
121 }
122
123 }
124}
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
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.
PubSubExtension(ISimulationNode Parent, Model Model)
PubSub XMPP extension
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Abstract base class for XMPP extensions.
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
Client managing communication with a Publish/Subscribe component. https://xmpp.org/extensions/xep-006...
Definition: PubSubClient.cs:20
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