Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UnsubscribeFrom.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(UnsubscribeFrom);
36
40 public override string SchemaResource => XmppActor.XmppSchema;
41
45 public override string Namespace => XmppActor.XmppNamespace;
46
54 {
55 return new UnsubscribeFrom(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 if (!(await this.GetActorObjectAsync(this.actor, Variables) is XmppActivityObject XmppActor))
80 throw new Exception("Actor not an XMPP client.");
81
82 await XmppActor.Client.RequestPresenceUnsubscription(To);
83
84 return null;
85 }
86
93 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
94 {
95 base.ExportPlantUml(Output, Indentation, QuoteChar);
96
97 Indent(Output, Indentation);
98 Output.Write(':');
99 Output.Write(this.actor.Value);
100 Output.Write(".UnsubscribeFrom");
101 Output.Write("(");
102
103 Indentation++;
104
105 SendMessage.AppendArgument(Output, Indentation, "To", this.to.Value, true, QuoteChar);
106
107 Output.WriteLine(");");
108 }
109
110 }
111}
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
Unsubscribes from the presence of another entity.
override string Namespace
XML Namespace where the element is defined.
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.
override string SchemaResource
Points to the embedded XML Schema resource defining the semantics of the XML namespace.
override string LocalName
Local name of XML element defining contents of class.
UnsubscribeFrom(ISimulationNode Parent, Model Model)
Unsubscribes from the presence of another entity.
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
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.