3using System.Threading.Tasks;
23 private const string SensorDataNamespace =
"urn:nfi:iot:sd:1.0";
36 this.authenticationSchemes = AuthenticationSchemes;
71 return this.authenticationSchemes;
90 ResourceMap = HttpModule.WebServer
98 await Response.
Write(Html);
110 if (Request.
User is
null)
129 if (!(Payload.
Decoded is XmlDocument Xml) || Xml.DocumentElement is
null)
135 if (Xml.DocumentElement.NamespaceURI != SensorDataNamespace)
141 if (
string.IsNullOrEmpty(Request.
SubPath))
146 this.ResourceName, Request.
User.UserName,
HttpModule.PostPrivileges));
150 if (Xml.DocumentElement.LocalName ==
"resp")
152 foreach (XmlNode N
in Xml.DocumentElement.ChildNodes)
154 if (!(N is XmlElement E))
157 if (E.NamespaceURI != SensorDataNamespace || E.LocalName !=
"nd")
163 if (!await this.ProcessNode(E, Response))
167 else if (Xml.DocumentElement.LocalName ==
"nd")
169 if (!await this.ProcessNode(Xml.DocumentElement, Response))
180 string PrivilegeId = HttpModule.PostPrivileges + Request.
SubPath.Replace(
'/',
'.');
182 if (!Request.
User.HasPrivilege(PrivilegeId))
185 this.ResourceName, Request.
User.UserName, PrivilegeId));
189 if (Xml.DocumentElement.LocalName ==
"ts")
191 string[] Path = Request.
SubPath[1..].Split(
'/');
192 string NodeId = Path[^1];
198 if (!await this.ProcessTimestamp(
ExternalWebNode, Xml.DocumentElement, Response))
201 else if (Node is
null)
206 foreach (
string Part
in Path)
251 else if (!await this.ProcessTimestamp(
ExternalWebNode, Xml.DocumentElement, Response))
267 Response.StatusCode = 204;
268 Response.StatusMessage =
"No content";
273 private async Task<bool> ProcessNode(XmlElement Xml,
HttpResponse Response)
275 string NodeId = Xml.GetAttribute(
"id");
276 string SourceId = Xml.GetAttribute(
"src");
277 string Partition = Xml.GetAttribute(
"pt");
279 if (!
string.IsNullOrEmpty(SourceId) &&
286 if (!
string.IsNullOrEmpty(Partition))
299 if (!(Node is ExternalWebNode ExternalWebNode))
305 foreach (XmlNode N
in Xml.ChildNodes)
307 if (!(N is XmlElement E))
310 if (E.NamespaceURI != SensorDataNamespace || E.LocalName !=
"ts")
316 if (!await this.ProcessTimestamp(ExternalWebNode, E, Response))
323 private async Task<bool> ProcessTimestamp(ExternalWebNode Node, XmlElement Xml,
HttpResponse Response)
325 List<ThingError> Errors =
null;
326 List<Field> Fields =
null;
330 if (Fields is
null && Errors is
null)
336 await Node.NewSensorData(Fields?.ToArray(), Errors?.ToArray());
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Exception Error
Error response.
const string DefaultContentType
Default Content-Type for HTML: text/html
Contains a markdown document. This markdown document class supports original markdown,...
async Task< string > GenerateHTML()
Generates HTML from the markdown text.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
static ForbiddenException AccessDenied(string ObjectId, string ActorId)
Returns a ForbiddenException object, and logs a entry in the event log about the event.
Base class for all HTTP authentication schemes, as defined in RFC-7235: https://datatracker....
Represents an HTTP request.
HttpRequestHeader Header
Request header.
bool HasData
If the request has data.
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
IUser User
Authenticated user, if available, or null if not available.
HttpResource Resource
Resource being accessed.
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
string ResourceName
Name of resource.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Write(byte[] Data)
Returns binary data in the response.
Base class for all synchronous HTTP resources. A synchronous resource responds within the method hand...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Implements an XMPP sensor client interface.
static void ParseTimespan(XmlElement Xml, ThingReference Thing, ref List< Field > Fields, ref List< ThingError > Errors)
Parses a <ts> element and its corresponding fields and errors.
Static class managing loading of resources stored as embedded resources or in content files.
static byte[] LoadResource(string ResourceName)
Loads a resource from an embedded resource.
Static class managing binary representations of strings.
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Node representing an external web node.
Web Service REST API that receives sensor data from external sources.
SensorDataReceptorResource(string ResourceName, params HttpAuthenticationScheme[] AuthenticationSchemes)
Web Service REST API that receives sensor data from external sources.
override bool HandlesSubPaths
If the resource handles sub-paths.
override bool UserSessions
If the resource uses user sessions.
async Task GET(HttpRequest Request, HttpResponse Response)
Executes the GET method on the resource.
bool AllowsPOST
If the POST method is allowed.
bool AllowsGET
If the GET method is allowed.
override HttpAuthenticationScheme[] GetAuthenticationSchemes(HttpRequest Request)
Any authentication schemes used to authenticate users before access is granted to the corresponding r...
async Task POST(HttpRequest Request, HttpResponse Response)
Executes the POST method on the resource.
Base class for all metering nodes.
virtual async Task AddAsync(INode Child)
Adds a new child to the node.
Defines the Metering Topology data source. This data source contains a tree structure of persistent r...
static Task< MeteringNode > GetNode(string NodeId)
Gets a node from the Metering Topology
const string SourceID
Source ID for the metering topology data source.
GET Interface for HTTP resources.
POST Interface for HTTP resources.
Interface for nodes that are published through the concentrator interface.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.