2using System.Collections.Generic;
5using System.Threading.Tasks;
69 public override Task
FromXml(XmlElement Definition)
74 this.retain =
XML.
Attribute(Definition,
"retain",
false);
76 return base.FromXml(Definition);
85 if (this.value is
null)
88 throw new Exception(
"Value already registered.");
99 object Content = this.value is
null ? string.Empty : await this.value.
EvaluateAsync(
Variables) ??
string.Empty;
101 if (!(Content is
byte[] Bin))
108 throw new Exception(
"Actor not an MQTT actor.");
110 await MqttActor.Client.PUBLISH(Topic, this.qos, this.retain, Bin);
121 public override void ExportPlantUml(StreamWriter Output,
int Indentation,
char QuoteChar)
123 base.ExportPlantUml(Output, Indentation, QuoteChar);
125 Indent(Output, Indentation);
127 Output.Write(this.actor.
Value);
128 Output.Write(
".Publish");
133 this.AppendArgument(Output, Indentation,
"Topic", this.topic.
Value,
true, QuoteChar);
134 this.AppendArgument(Output, Indentation,
"QoS", this.qos.ToString(),
false, QuoteChar);
137 this.AppendArgument(Output, Indentation,
"Retain",
"true",
false, QuoteChar);
139 if (!(this.value is
null))
142 this.AppendArgument(Output, Indentation,
"Content",
Xml.
RootName,
false, QuoteChar);
144 this.AppendArgument(Output, Indentation,
"Content", this.value, QuoteChar);
147 Output.WriteLine(
");");
150 private void AppendArgument(StreamWriter Output,
int Indentation,
string Name,
string Value,
bool Quotes,
char QuoteChar)
152 this.AppendArgument(Output, Indentation, Name);
160 private void AppendArgument(StreamWriter Output,
int Indentation,
string Name,
IValue Value,
char QuoteChar)
162 this.AppendArgument(Output, Indentation, Name);
166 private void AppendArgument(StreamWriter Output,
int Indentation,
string Name)
169 Indent(Output, Indentation);
Publishes content to a topic.
override async Task< LinkedListNode< IActivityNode > > Execute(Variables Variables)
Executes a node.
void Register(IValue Value)
Registers a value for the argument.
Publish(ISimulationNode Parent, Model Model)
Publishes content to a topic.
override string SchemaResource
Points to the embedded XML Schema resource defining the semantics of the XML namespace.
override ISimulationNode Create(ISimulationNode Parent, Model Model)
Creates a new instance of the node.
override string Namespace
XML Namespace where the element is defined.
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
override string LocalName
Local name of XML element defining contents of class.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
Object used in simulation activities.
MQTT Actor connecting to the MQTT network using traditional TCP.
const string MqttSchema
TAG.Simulator.MQTT.Schema.ComSimMqtt.xsd
const string MqttNamespace
http://lab.tagroot.io/Schema/ComSim/MQTT.xsd
Root node of a simulation model
Abstract base class for activity nodes
Executes script in an activity.
override void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
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
Abstract base class for values
abstract void ExportPlantUml(StreamWriter Output, int Indentation, char QuoteChar)
Exports PlantUML
Static class managing encoding and decoding of internet content.
static Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
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
MqttQualityOfService
MQTT Quality of Service level.