Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
PersistedGeoSpatialObjectReference.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
4using Waher.Content;
9
11{
15 [CollectionName("GeoObjects")]
16 [TypeName(TypeNameSerialization.None)]
17 [Index("GeoId")]
19 {
24 : base()
25 {
26 }
27
33 : base(Object)
34 {
35 }
36
42 public new static async Task<PersistedGeoSpatialObjectReference> Create(IGeoSpatialObject Object)
43 {
45 {
46 GeoId = Object.GeoId,
48 Location = await Object.GetLocation(),
49 Created = DateTime.UtcNow
50 };
51 }
52
56 [ObjectId]
57 public string ObjectId { get; set; }
58
62 [DefaultValueStringEmpty]
63 public string ContentXml { get; set; }
64
68 public CaseInsensitiveString Creator { get; set; }
69
73 public DateTime? Expires { get; set; }
74
78 public DateTime Created { get; set; }
79
83 [DefaultValueNull]
84 public DateTime? Updated { get; set; }
85
90 [DefaultValueNull]
91 public DateTime? From { get; set; }
92
98 [DefaultValueNull]
99 public DateTime? To { get; set; }
100
102 public override bool Equals(object obj)
103 {
104 if (!(obj is PersistedGeoSpatialObjectReference Reference))
105 return false;
106
107 return
108 (this.ObjectId?.Equals(Reference.ObjectId) ?? Reference.ObjectId is null) &&
109 base.Equals(obj);
110 }
111
113 public override int GetHashCode()
114 {
115 int Result = base.GetHashCode();
116 Result ^= Result << 5 ^ (this.ObjectId?.GetHashCode() ?? 0);
117
118 return Result;
119 }
120
125 public void Serialize(StringBuilder Xml)
126 {
127 Xml.Append("<ref id='");
128 Xml.Append(XML.Encode(this.GeoId));
129
130 Xml.Append("' lat='");
131 Xml.Append(CommonTypes.Encode(this.Location.Latitude));
132
133 Xml.Append("' lon='");
134 Xml.Append(CommonTypes.Encode(this.Location.Longitude));
135
136 if (this.Location.Altitude.HasValue)
137 {
138 Xml.Append("' alt='");
139 Xml.Append(CommonTypes.Encode(this.Location.Altitude.Value));
140 }
141
142 if (this.Expires.HasValue)
143 {
144 int Ttl = (int)(this.Expires.Value.Subtract(DateTime.Now).TotalSeconds + 0.5);
145 if (Ttl > 0)
146 {
147 Xml.Append("' ttl='");
148 Xml.Append(Ttl.ToString());
149 }
150 }
151
152 if (!CaseInsensitiveString.IsNullOrEmpty(this.Creator))
153 {
154 Xml.Append("' creator='");
155 Xml.Append(XML.Encode(this.Creator.Value));
156 }
157
158 Xml.Append("' created='");
159 Xml.Append(XML.Encode(this.Created));
160
161 if (this.Updated.HasValue)
162 {
163 Xml.Append("' updated='");
164 Xml.Append(XML.Encode(this.Updated.Value));
165 }
166
167 if (this.From.HasValue)
168 {
169 Xml.Append("' from='");
170 Xml.Append(XML.Encode(this.From.Value));
171 }
172
173 if (this.To.HasValue)
174 {
175 Xml.Append("' to='");
176 Xml.Append(XML.Encode(this.To.Value));
177 }
178
179 if (string.IsNullOrEmpty(this.ContentXml))
180 Xml.Append("'/>");
181 else
182 {
183 Xml.Append("'>");
184 Xml.Append(this.ContentXml);
185 Xml.Append("</ref>");
186 }
187 }
188 }
189}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:596
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
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
double? Altitude
Altitude in meters. Can be null.
Definition: GeoPosition.cs:100
A base class for geo-spatial objects, implementing the basic members of the IGeoSpatialObject interfa...
A base class for geo-spatial object references, implementing the basic members of the IGeoSpatialObje...
string GeoId
The ID of the geo-spatial object.
GeoPosition Location
Gets the geo-spatial location of the object.
bool EphemeralLocation
If the location of the geo-spatial object is ephemeral.
PersistedGeoSpatialObjectReference(GeoSpatialObject Object)
A persisted or persistable geo-spatial object reference.
DateTime? To
Timestamp indicating to what point in time publication is valid. Can be used to publish an expected e...
void Serialize(StringBuilder Xml)
Serializes a geo-spatial object reference to XML.
PersistedGeoSpatialObjectReference()
A persisted or persistable geo-spatial object reference.
static new async Task< PersistedGeoSpatialObjectReference > Create(IGeoSpatialObject Object)
Create a persisted or persistable geo-spatial object reference from a geo-spatial object.
DateTime? From
Timestamp indicating from what point in time publication is valid. Can be used to publish a future lo...
Interface for objects with a geo-spatial location
bool EphemeralLocation
If the location of the geo-spatial object is ephemeral.
Task< GeoPosition > GetLocation()
Gets the geo-spatial location of the object.
string GeoId
The ID of the geo-spatial object.
TypeNameSerialization
How the type name should be serialized.