Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppMessage.cs
1using System.Threading.Tasks;
2using System.Xml;
8
10{
15 {
19 public XmppMessage()
20 : base()
21 {
22 }
23
27 public override string LocalName => nameof(XmppMessage);
28
33 public override IStateMachineNode Create()
34 {
35 return new XmppMessage();
36 }
37
42 public override async Task Execute(EvaluationArguments Arguments)
43 {
44 string To = (await this.To.Evaluate(Arguments))?.ToString();
45 object Content = await this.Content.Evaluate(Arguments);
46 string Type = string.Empty;
47 string ContentXml;
48
49 if (Content is XmlNode N)
50 ContentXml = N.OuterXml;
51 else if (Content is string s)
52 {
53 s = s.Trim();
54
55 if (s.StartsWith('<') && s.EndsWith('>') && XML.IsValidXml(s, true, true, true, true, false, false))
56 ContentXml = s;
57 else
58 {
59 int? HeaderEndPos = MarkdownDocument.HeaderEndPosition(s);
60 bool HasHeader = HeaderEndPos.HasValue && HeaderEndPos.Value > 0;
61 MarkdownSettings Settings = new MarkdownSettings(Gateway.Emoji1_24x24, HasHeader, Arguments.Variables);
62 string Markdown = await MarkdownDocument.Preprocess(s, Settings);
63
64 ContentXml = await Gateway.GetMultiFormatChatMessageXml(Markdown, true, true);
65 Type = "chat";
66 }
67 }
69 {
71 bool HasHeader = HeaderEndPos.HasValue && HeaderEndPos.Value > 0;
72 MarkdownSettings Settings = MarkdownContent.Settings ?? new MarkdownSettings(Gateway.Emoji1_24x24, HasHeader, Arguments.Variables);
73 string Markdown = await MarkdownDocument.Preprocess(MarkdownContent.Markdown, Settings);
74
75 ContentXml = await Gateway.GetMultiFormatChatMessageXml(Markdown, true, true);
76 Type = "chat";
77 }
78 else
79 throw new StateMachineException(Arguments.Machine, "Expected XML or Markdown content.");
80
81 await Arguments.Legal.Server.SendMessage(Type, string.Empty,
82 Arguments.EDaler.MainDomain, new XmppAddress(To), string.Empty, ContentXml);
83 }
84 }
85}
Class that can be used to encapsulate Markdown to be returned from a Web Service, bypassing any encod...
Contains a markdown document. This markdown document class supports original markdown,...
static ? int HeaderEndPosition(string Markdown)
Gets the end position of the header, if one is found, null otherwise.
static async Task< string > Preprocess(string Markdown, MarkdownSettings Settings, params Type[] TransparentExceptionTypes)
Preprocesses markdown text.
Contains settings that the Markdown parser uses to customize its behavior.
Helps with common XML-related tasks.
Definition: XML.cs:21
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Definition: XML.cs:1397
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static Task< string > GetMultiFormatChatMessageXml(string Markdown)
Gets XML for a multi-formatted chat message.
Definition: Gateway.cs:4959
static Emoji1LocalFiles Emoji1_24x24
Emojis.
Definition: Gateway.cs:3166
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
override async Task Execute(EvaluationArguments Arguments)
Evaluates the action node
Definition: XmppMessage.cs:42
override IStateMachineNode Create()
Creates a new node of the corresponding type.
Definition: XmppMessage.cs:33
Contains information required for evaluating script in a state-machine.
StateMachine Machine
Reference to state-machine definition.