3using System.Threading.Tasks;
21 private readonly
string componentAddress;
61 #region NeuroFoundation V1
75 #region NeuroFoundation V1
116 EventHandlerAsync<SubscribedEventArgs> Callback,
object State)
118 return this.
Subscribe(
string.Empty, Min, Max,
null, Callback, State);
139 EventHandlerAsync<SubscribedEventArgs> Callback,
object State)
141 return this.
Subscribe(
string.Empty, Min, Max, Ttl, Callback, State);
163 EventHandlerAsync<SubscribedEventArgs> Callback,
object State)
165 return this.
Subscribe(this.componentAddress, SubscriptionId, Min, Max, Ttl, Callback, State);
189 EventHandlerAsync<SubscribedEventArgs> Callback,
object State)
192 throw new ArgumentNullException(nameof(Min));
195 throw new ArgumentNullException(nameof(Max));
197 StringBuilder Xml =
new StringBuilder();
199 Xml.Append(
"<subscribe xmlns='");
202 if (!
string.IsNullOrEmpty(SubscriptionId))
204 Xml.Append(
"' id='");
208 Xml.Append(
"' minLat='");
211 Xml.Append(
"' minLon='");
216 Xml.Append(
"' minAlt='");
220 Xml.Append(
"' maxLat='");
223 Xml.Append(
"' maxLon='");
228 Xml.Append(
"' maxAlt='");
234 Xml.Append(
"' ttl='");
235 Xml.Append(Ttl.Value);
240 await this.
client.
SendIqSet(ComponentAddress, Xml.ToString(), async (sender, e) =>
308 return this.
SubscribeAsync(this.componentAddress, SubscriptionId, Min, Max, Ttl);
333 TaskCompletionSource<SubscribedEventArgs> Result =
new TaskCompletionSource<SubscribedEventArgs>();
335 await this.
Subscribe(ComponentAddress, SubscriptionId, Min, Max, Ttl, (sender, e) =>
338 Result.TrySetResult(e);
340 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to perform subscription."));
342 return Task.CompletedTask;
345 return await Result.Task;
359 EventHandlerAsync<UnsubscribedEventArgs> Callback,
object State)
361 return this.
Unsubscribe(this.componentAddress, SubscriptionId, Callback, State);
372 EventHandlerAsync<UnsubscribedEventArgs> Callback,
object State)
374 StringBuilder Xml =
new StringBuilder();
376 Xml.Append(
"<unsubscribe xmlns='");
378 Xml.Append(
"' id='");
382 await this.
client.
SendIqSet(ComponentAddress, Xml.ToString(), async (sender, e) =>
408 TaskCompletionSource<UnsubscribedEventArgs> Result =
new TaskCompletionSource<UnsubscribedEventArgs>();
410 await this.
Unsubscribe(ComponentAddress, SubscriptionId, (sender, e) =>
413 Result.TrySetResult(e);
415 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to perform unsubscription."));
417 return Task.CompletedTask;
420 return await Result.Task;
425 #region Event Notifications
439 public event EventHandlerAsync<GeoObjectSubscriptionEventArgs>
ObjectAdded;
453 public event EventHandlerAsync<GeoObjectSubscriptionEventArgs>
ObjectUpdated;
467 public event EventHandlerAsync<GeoObjectSubscriptionEventArgs>
ObjectRemoved;
469 private static GeoObjectReference ParseObjectReferenceFirstChild(XmlElement ParentXml)
471 if (ParentXml is
null)
474 foreach (XmlNode Node
in ParentXml.ChildNodes)
476 if (Node is XmlElement E &&
477 E.LocalName ==
"ref" &&
480 return ParseObjectReference(E);
492 Creator = Xml.HasAttribute(
"creator") ?
XML.
Attribute(Xml,
"creator") :
null,
496 Xml.HasAttribute(
"alt") ?
XML.
Attribute(Xml,
"alt", 0.0) : (
double?)
null),
497 TimeToLive = Xml.HasAttribute(
"ttl") ?
XML.
Attribute(Xml,
"ttl", 0) : (
int?)
null,
498 Created =
XML.
Attribute(Xml,
"created", DateTime.MinValue),
499 Updated = Xml.HasAttribute(
"updated") ?
XML.
Attribute(Xml,
"updated", DateTime.MinValue) : (DateTime?)
null,
500 From = Xml.HasAttribute(
"from") ?
XML.
Attribute(Xml,
"from", DateTime.MinValue) : (DateTime?)
null,
501 To = Xml.HasAttribute(
"to") ?
XML.
Attribute(Xml,
"to", DateTime.MinValue) : (DateTime?)
null
504 foreach (XmlNode N
in Xml.ChildNodes)
506 if (N is XmlElement E)
508 Result.Definition = E;
520 public Task Publish(
string GeoId,
GeoPosition Location,
int? Ttl,
521 DateTime? From, DateTime? To,
string CustomXml)
523 return Task.CompletedTask;
526 public Task PublishAsync()
528 return Task.CompletedTask;
537 return Task.CompletedTask;
540 public Task DeleteAsync()
542 return Task.CompletedTask;
551 return Task.CompletedTask;
554 public Task SearchAsync()
556 return Task.CompletedTask;
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
static string Encode(string s)
Encodes a string for use in XML.
Event arguments for message events.
XmlElement Content
Content of the message. For messages that are processed by registered message handlers,...
Adds support for geo-spatial publish/subscribe communication pattern to an XMPP client.
Task Unsubscribe(string SubscriptionId, EventHandlerAsync< UnsubscribedEventArgs > Callback, object State)
Unsubscribes an existing subscription.
Task Subscribe(string SubscriptionId, GeoPosition Min, GeoPosition Max, int? Ttl, EventHandlerAsync< SubscribedEventArgs > Callback, object State)
Subscribes to geo-spatial information, or updates an existing subscription.
static bool IsNamespaceGeoSpatial(string Namespace)
If a namespace corresponds to a geo-spatial namespace.
Task< SubscribedEventArgs > SubscribeAsync(GeoPosition Min, GeoPosition Max)
Subscribes to geo-spatial information, or updates an existing subscription.
Task Subscribe(GeoPosition Min, GeoPosition Max, EventHandlerAsync< SubscribedEventArgs > Callback, object State)
Subscribes to geo-spatial information, or updates an existing subscription.
override string[] Extensions
Implemented extensions.
string ComponentAddress
Component address.
async Task< SubscribedEventArgs > SubscribeAsync(string ComponentAddress, string SubscriptionId, GeoPosition Min, GeoPosition Max, int? Ttl)
Subscribes to geo-spatial information, or updates an existing subscription.
EventHandlerAsync< GeoObjectSubscriptionEventArgs > ObjectAdded
Event raised when object hass been added.
override void Dispose()
Disposes of the extension.
async Task Unsubscribe(string ComponentAddress, string SubscriptionId, EventHandlerAsync< UnsubscribedEventArgs > Callback, object State)
Unsubscribes an existing subscription.
Task< SubscribedEventArgs > SubscribeAsync(string SubscriptionId, GeoPosition Min, GeoPosition Max, int? Ttl)
Subscribes to geo-spatial information, or updates an existing subscription.
EventHandlerAsync< GeoObjectSubscriptionEventArgs > ObjectUpdated
Event raised when object hass been updated.
EventHandlerAsync< GeoObjectSubscriptionEventArgs > ObjectRemoved
Event raised when object hass been updated.
const string NamespaceGeoSpatialNeuroFoundationV1
urn:nf:iot:geo:1.0
GeoClient(XmppClient Client, string ComponentAddress)
Adds support for geo-spatial publish/subscribe communication pattern to an XMPP client.
Task< UnsubscribedEventArgs > UnsubscribeAsync(string SubscriptionId)
Unsubscribes an existing subscription.
async Task Subscribe(string ComponentAddress, string SubscriptionId, GeoPosition Min, GeoPosition Max, int? Ttl, EventHandlerAsync< SubscribedEventArgs > Callback, object State)
Subscribes to geo-spatial information, or updates an existing subscription.
Task< SubscribedEventArgs > SubscribeAsync(GeoPosition Min, GeoPosition Max, int Ttl)
Subscribes to geo-spatial information, or updates an existing subscription.
async Task< UnsubscribedEventArgs > UnsubscribeAsync(string ComponentAddress, string SubscriptionId)
Unsubscribes an existing subscription.
Task Subscribe(GeoPosition Min, GeoPosition Max, int Ttl, EventHandlerAsync< SubscribedEventArgs > Callback, object State)
Subscribes to geo-spatial information, or updates an existing subscription.
static readonly string[] NamespacesGeoSpatial
Namespaces supported for legal identities.
Represents a reference to a geo-spatial object.
Event arguments for events related to Geo-spatial objects.
Event arguments for the result of a subscription request.
Event arguments for the result of an unsubscription request.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
bool UnregisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool RemoveNamespaceAsClientFeature)
Unregisters a Message handler.
void RegisterMessageHandler(string LocalName, string Namespace, EventHandlerAsync< MessageEventArgs > Handler, bool PublishNamespaceAsClientFeature)
Registers a Message handler.
Task< uint > SendIqSet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Set request.
Base class for XMPP Extensions.
XmppClient client
XMPP Client used by the extension.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
XmppClient Client
XMPP Client.
Contains information about a position in a geo-spatial coordinate system.
double Longitude
Longitude in degrees.
double? Altitude
Altitude in meters. Can be null.
double Latitude
Latitude in degrees.