Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SubscribeTo.cs
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using System.Threading.Tasks;
9using Waher.Script;
10using System.IO;
11
13{
18 {
19 private StringAttribute actor;
20 private StringAttribute to;
21
28 : base(Parent, Model)
29 {
30 }
31
35 public override string LocalName => nameof(SubscribeTo);
36
40 public override string SchemaResource => XmppActor.XmppSchema;
41
45 public override string Namespace => XmppActor.XmppNamespace;
46
54 {
55 return new SubscribeTo(Parent, Model);
56 }
57
62 public override Task FromXml(XmlElement Definition)
63 {
64 this.actor = new StringAttribute(XML.Attribute(Definition, "actor"));
65 this.to = new StringAttribute(XML.Attribute(Definition, "to"));
66
67 return base.FromXml(Definition);
68 }
69
75 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
76 {
77 string To = await this.to.GetValueAsync(Variables);
78
79 object Obj = await this.GetActorObjectAsync(this.actor, Variables);
80 if (!(Obj is XmppActivityObject XmppActor))
81 throw new Exception("Actor not an XMPP client.");
82
83 await XmppActor.Client.RequestPresenceSubscription(To);
84
85 return null;
86 }
87
94 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
95 {
96 base.ExportPlantUml(Output, Indentation, QuoteChar);
97
98 Indent(Output, Indentation);
99 Output.Write(':');
100 Output.Write(this.actor.Value);
101 Output.Write(".SubscribeTo");
102 Output.Write("(");
103
104 Indentation++;
105
106 SendMessage.AppendArgument(Output, Indentation, "To", this.to.Value, true, QuoteChar);
107
108 Output.WriteLine(");");
109 }
110
111 }
112}
Root node of a simulation model
Definition: Model.cs:49
Abstract base class for activity nodes
Definition: ActivityNode.cs:15
async Task< object > GetActorObjectAsync(StringAttribute Actor, Variables Variables)
Gets an actor object, given a string representation, possibly containing script, of the actor.
static void Indent(StreamWriter Output, int Indentation)
Adds indentation to the current row.
Contains the value of a string attribute, possibly with embedded script.
async Task< string > GetValueAsync(Variables Variables)
Gets the value of the attribute.
string Value
String value, from definition
Sends a custom message to a recipient
Definition: SendMessage.cs:20
static void AppendArgument(StreamWriter Output, int Indentation, string Name, string Value, bool Quotes, char QuoteChar)
Appends an argument
Definition: SendMessage.cs:188
Subscribes to the presence of another entity.
Definition: SubscribeTo.cs:18
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: SubscribeTo.cs:62
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Definition: SubscribeTo.cs:94
override string LocalName
Local name of XML element defining contents of class.
Definition: SubscribeTo.cs:35
SubscribeTo(ISimulationNode Parent, Model Model)
Subscribes to the presence of another entity.
Definition: SubscribeTo.cs:27
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: SubscribeTo.cs:75
override string Namespace
XML Namespace where the element is defined.
Definition: SubscribeTo.cs:45
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: SubscribeTo.cs:53
override string SchemaResource
Points to the embedded XML Schema resource defining the semantics of the XML namespace.
Definition: SubscribeTo.cs:40
Object used in simulation activities.
Abstract base class for XMPP actors.
Definition: XmppActor.cs:23
XmppClient Client
XMPP Client
Definition: XmppActor.cs:110
const string XmppSchema
TAG.Simulator.XMPP.Schema.ComSimXmpp.xsd
Definition: XmppActor.cs:32
const string XmppNamespace
http://lab.tagroot.io/Schema/ComSim/XMPP.xsd
Definition: XmppActor.cs:27
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
Collection of variables.
Definition: Variables.cs:25
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.