4using System.Net.Security;
5using System.Security.Cryptography.X509Certificates;
7using System.Threading.Tasks;
21 private string endpoint;
49 public override Task
FromXml(XmlElement Definition)
51 if (Definition.HasAttribute(
"endpoint"))
56 return base.FromXml(Definition);
64 await base.Initialize();
66 if (
string.IsNullOrEmpty(this.endpoint))
68 using (HttpClient HttpClient =
new HttpClient(
new HttpClientHandler()
70 ServerCertificateCustomValidationCallback = this.RemoteCertificateValidationCallback,
74 Timeout = TimeSpan.FromMilliseconds(60000)
79 HttpResponseMessage Response = await HttpClient.GetAsync(
"http://" + this.
Host +
"/.well-known/host-meta");
80 Response.EnsureSuccessStatusCode();
82 Stream Stream = await Response.Content.ReadAsStreamAsync();
83 byte[] Bin = await Response.Content.ReadAsByteArrayAsync();
84 string CharSet = Response.Content.Headers.ContentType.CharSet;
87 if (
string.IsNullOrEmpty(CharSet))
88 Encoding = Encoding.UTF8;
92 string XmlResponse = Encoding.GetString(Bin);
93 XmlDocument Doc =
new XmlDocument()
95 PreserveWhitespace =
true
97 Doc.LoadXml(XmlResponse);
99 if (Doc.DocumentElement !=
null && Doc.DocumentElement.LocalName ==
"XRD")
104 this.endpoint =
null;
108 if (
string.IsNullOrEmpty(this.endpoint))
109 throw new Exception(
"Unable to find endpoint of " + this.
Host);
129 foreach (XmlNode
N in Xrd.DocumentElement.ChildNodes)
131 if (
N is XmlElement E && E.LocalName ==
"Link" &&
XML.
Attribute(E,
"rel") == Rel)
138 private bool RemoteCertificateValidationCallback(
object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
142 if (sslPolicyErrors == SslPolicyErrors.None)
161 Result.endpoint = this.endpoint;
172 Result.UriEndpoint = this.endpoint;
Root node of a simulation model
string InstanceId
ID of actor instance.
int InstanceIndex
Actor instance index.
int N
Number of actors of this type specified.
Abstract base class for XMPP actors with custom endpoint.
XmppActorEndpoint(ISimulationNode Parent, Model Model)
Abstract base class for XMPP actors with custom endpoint.
override async Task Initialize()
Initialized the node before simulation.
async override Task< XmppCredentials > GetInstanceCredentials()
Gets XMPP credentials for the instance.
abstract string EndpointType
Type of XRD link representing endpoint.
override Task FromXml(XmlElement Definition)
Sets properties and attributes of class in accordance with XML definition.
override async Task< Actor > CreateInstanceAsync(int InstanceIndex, string InstanceId)
Creates an instance of the actor.
string FindEndpoint(XmlDocument Xrd)
Finds the endpoint from the XRD XML definition.
XmppActorEndpoint(ISimulationNode Parent, Model Model, int InstanceIndex, string InstanceId)
Abstract base class for XMPP actors with custom endpoint.
Abstract base class for XMPP actors.
bool TrustServer
If server is to be trusted, regardless of state of certificate.
Static class managing encoding and decoding of internet content.
static Encoding GetEncoding(string CharacterSet)
Gets a character encoding from its name.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Class containing credentials for an XMPP client connection.
Basic interface for simulator nodes. Implementing this interface allows classes with default contruct...
ISimulationNode Parent
Parent node in the simulation model.