Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GeoSubscription.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
7
9{
14 {
15 private readonly string boxId = Guid.NewGuid().ToString();
16 private readonly XmppAddress from;
17 private readonly GeoPosition min;
18 private readonly GeoPosition max;
19 private DateTime elapses;
20
29 {
30 this.from = From;
31 this.min = Min;
32 this.max = Max;
33 this.elapses = Elapses;
34 }
35
39 public string BoxId => this.boxId;
40
44 public XmppAddress From => this.from;
45
49 public GeoPosition Min => this.min;
50
54 public GeoPosition Max => this.max;
55
59 public bool IncludeMin => true;
60
64 public bool IncludeMax => true;
65
70 public bool LongitudeWrapped => this.min.Longitude > this.max.Longitude;
71
75 public DateTime Elapses
76 {
77 get => this.elapses;
78 internal set => this.elapses = value;
79 }
80
82 public override bool Equals(object obj)
83 {
84 return
85 obj is GeoSubscription Obj &&
86 (this.min?.Equals(Obj.Min) ?? Obj.Min is null) &&
87 (this.max?.Equals(Obj.Max) ?? Obj.Max is null);
88 }
89
91 public override int GetHashCode()
92 {
93 int Result = this.min?.GetHashCode() ?? 0;
94 Result ^= Result << 5 ^ (this.max?.GetHashCode() ?? 0);
95
96 return Result;
97 }
98
104 public bool Contains(GeoPosition Location)
105 {
106 return !Location.LiesOutside(this.min, this.max, false, false);
107 }
108
115 public bool Contains(GeoPosition Location, bool IgnoreAltitude)
116 {
117 return !Location.LiesOutside(this.min, this.max, false, false, IgnoreAltitude);
118 }
119
126 GeoSpatialComponent Sender)
127 {
128 return this.SendEvent(Reference, Sender, "added");
129 }
130
137 GeoSpatialComponent Sender)
138 {
139 return this.SendEvent(Reference, Sender, "updated");
140 }
141
148 GeoSpatialComponent Sender)
149 {
150 return this.SendEvent(Reference, Sender, "removed");
151 }
152
153 private Task SendEvent(PersistedGeoSpatialObjectReference Reference,
154 GeoSpatialComponent Sender, string EventName)
155 {
156 StringBuilder Xml = new StringBuilder();
157
158 Xml.Append('<');
159 Xml.Append(EventName);
160 Xml.Append(" xmlns='");
162 Xml.Append("' id='");
163 Xml.Append(XML.Encode(this.boxId));
164 Xml.Append("'>");
165
166 Reference.Serialize(Xml);
167
168 Xml.Append("</");
169 Xml.Append(EventName);
170 Xml.Append('>');
171
172 return XmppServerModule.Server.SendMessage(string.Empty, string.Empty, Sender.MainDomain,
173 this.from, string.Empty, Xml.ToString());
174 }
175 }
176}
Helps with common XML-related tasks.
Definition: XML.cs:21
static string Encode(string s)
Encodes a string for use in XML.
Definition: XML.cs:29
XmppAddress MainDomain
Main/principal domain address
Definition: Component.cs:87
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
override string ToString()
object.ToString()
Definition: XmppAddress.cs:190
static readonly XmppAddress Empty
Empty address.
Definition: XmppAddress.cs:31
Task< bool > SendMessage(string Type, string Id, string From, string To, string Language, string ContentXml)
Sends a Message stanza to a recipient.
Definition: XmppServer.cs:3862
Contains information about a position in a geo-spatial coordinate system.
Definition: GeoPosition.cs:17
const string NamespaceGeoSpatialNeuroFoundationV1
urn:nf:iot:geo:1.0
Represents a Geo-spatial subscription.
GeoPosition Min
Lower-left corner of bounding box.
bool LongitudeWrapped
If the bounding box is longitude-wrapped, i.e. if the box passes the +-180 degrees longitude.
DateTime Elapses
When subscription elapses.
Task ObjectUpdated(PersistedGeoSpatialObjectReference Reference, GeoSpatialComponent Sender)
Geo-spatial object has been updated within the area defined by the subscription.
bool Contains(GeoPosition Location)
If the bounding box contains a location.
bool IncludeMin
If the min latitude/longitude/altitude should be considered as included in the boundoing box.
XmppAddress From
Address of owner of subscription.
bool Contains(GeoPosition Location, bool IgnoreAltitude)
If the bounding box contains a location.
Task ObjectAdded(PersistedGeoSpatialObjectReference Reference, GeoSpatialComponent Sender)
Geo-spatial object has been added within the area defined by the subscription.
GeoPosition Max
Upper-right corner of bounding box.
GeoSubscription(XmppAddress From, GeoPosition Min, GeoPosition Max, DateTime Elapses)
Represents a Geo-spatial subscription.
bool IncludeMax
If the max latitude/longitude/altitude should be considered as included in the boundoing box.
string BoxId
The ID of the geo-spatial bounding box.
Task ObjectRemoved(PersistedGeoSpatialObjectReference Reference, GeoSpatialComponent Sender)
Geo-spatial object has been removed within the area defined by the subscription.
void Serialize(StringBuilder Xml)
Serializes a geo-spatial object reference to XML.
Service Module hosting the XMPP broker and its components.
Interface for a geo-spatial bounding box using the Mercator Projection.