Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SetPresence.cs
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using System.Threading.Tasks;
10using Waher.Script;
12using System.IO;
13
15{
20 {
21 private IValue value;
22 private StringAttribute actor;
23 private Availability availability;
24
31 : base(Parent, Model)
32 {
33 }
34
38 public override string LocalName => nameof(SetPresence);
39
43 public override string SchemaResource => XmppActor.XmppSchema;
44
48 public override string Namespace => XmppActor.XmppNamespace;
49
57 {
58 return new SetPresence(Parent, Model);
59 }
60
65 public override Task FromXml(XmlElement Definition)
66 {
67 this.actor = new StringAttribute(XML.Attribute(Definition, "actor"));
68 this.availability = (Availability)XML.Attribute(Definition, "availability", Availability.Online);
69
70 return base.FromXml(Definition);
71 }
72
77 public void Register(IValue Value)
78 {
79 if (this.value is null)
80 this.value = Value;
81 else
82 throw new Exception("Value already registered.");
83 }
84
90 public override async Task<LinkedListNode<IActivityNode>> Execute(Variables Variables)
91 {
92 object Content = this.value is null ? string.Empty : await this.value.EvaluateAsync(Variables) ?? string.Empty;
93 string Xml;
94
95 if (!(await this.GetActorObjectAsync(this.actor, Variables) is XmppActivityObject XmppActor))
96 throw new Exception("Actor not an XMPP client.");
97
98 if (Content is XmlDocument Doc)
99 Xml = Doc.OuterXml;
100 else if (Content is XmlElement E)
101 Xml = E.OuterXml;
102 else
103 throw new Exception("Custom content in presence must be XML.");
104
105 XmppActor.Client.SetTag("CutomPresenceXML", Xml);
106 await XmppActor.Client.SetPresence(this.availability);
107
108 return null;
109 }
110
117 public override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
118 {
119 base.ExportPlantUml(Output, Indentation, QuoteChar);
120
121 Indent(Output, Indentation);
122 Output.Write(':');
123 Output.Write(this.actor.Value);
124 Output.Write(".SetPresence");
125 Output.Write("(");
126
127 Indentation++;
128
129 SendMessage.AppendArgument(Output, Indentation, "Availability", this.availability.ToString(), true, QuoteChar);
130
131 if (!(this.value is null))
132 {
133 if (this.value is Xml Xml && !string.IsNullOrEmpty(Xml.RootName))
134 SendMessage.AppendArgument(Output, Indentation, "Content", Xml.RootName, false, QuoteChar);
135 else
136 SendMessage.AppendArgument(Output, Indentation, "Content", this.value, QuoteChar);
137 }
138
139 Output.WriteLine(");");
140 }
141
142 }
143}
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.
string Value
String value, from definition
Abstract base class for values
Definition: Value.cs:11
string RootName
Root name
Definition: Xml.cs:34
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
Sets the presence of the current actor.
Definition: SetPresence.cs:20
override string LocalName
Local name of XML element defining contents of class.
Definition: SetPresence.cs:38
void Register(IValue Value)
Registers a value for the argument.
Definition: SetPresence.cs:77
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
Definition: SetPresence.cs:56
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
Definition: SetPresence.cs:90
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Definition: SetPresence.cs:117
SetPresence(ISimulationNode Parent, Model Model)
Sets the presence of the current actor.
Definition: SetPresence.cs:30
override string Namespace
XML Namespace where the element is defined.
Definition: SetPresence.cs:48
override string SchemaResource
Points to the embedded XML Schema resource defining the semantics of the XML namespace.
Definition: SetPresence.cs:43
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Definition: SetPresence.cs:65
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
void SetTag(string TagName, object Tag)
Sets a tag value.
Definition: XmppClient.cs:7249
Task SetPresence()
Sets the presence of the connection. Add a CustomPresenceXml event handler to add custom presence XML...
Definition: XmppClient.cs:4776
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.
Task< object > EvaluateAsync(Variables Variables)
Evaluates the value.
Interface for nodes holding a value node
Availability
Resource availability.
Definition: Availability.cs:7