2using System.Collections.Generic;
4using System.Threading.Tasks;
43 !
string.IsNullOrEmpty(GraphUri.Query) ||
44 !
string.IsNullOrEmpty(GraphUri.Fragment) ||
47 return Grade.NotAtAll;
50 string s = GraphUri.AbsolutePath;
51 string[] Parts = s.Split(
'/');
54 if (c <= 1 || !
string.IsNullOrEmpty(Parts[0]))
55 return Grade.NotAtAll;
57 if (
string.IsNullOrEmpty(Parts[c - 1]))
61 return Grade.NotAtAll;
63 return Grade.Excellent;
78 !
string.IsNullOrEmpty(GraphUri.Query) ||
79 !
string.IsNullOrEmpty(GraphUri.Fragment) ||
85 string s = GraphUri.AbsolutePath;
86 string[] Parts = s.Split(
'/');
89 if (c <= 1 || !
string.IsNullOrEmpty(Parts[0]))
92 if (
string.IsNullOrEmpty(Parts[c - 1]))
98 string SourceID = HttpUtility.UrlDecode(Parts[1]);
102 if (!await Source.CanViewAsync(Caller))
115 string NodeID = HttpUtility.UrlDecode(Parts[2]);
124 string Partition = HttpUtility.UrlDecode(Parts[2]);
125 NodeID = HttpUtility.UrlDecode(Parts[3]);
126 NodeObj = await Source.GetNodeAsync(
new ThingReference(NodeID, SourceID, Partition));
134 NodeID = HttpUtility.UrlDecode(Parts[2]);
135 NodeObj = await Source.GetNodeAsync(
new ThingReference(NodeID, SourceID));
139 return await GetNodeActionGraph(Result, NodeObj,
Language, HttpUtility.UrlDecode(Parts[3]),
140 HttpUtility.UrlDecode(Parts[4]), Caller);
143 Partition = HttpUtility.UrlDecode(Parts[2]);
144 NodeID = HttpUtility.UrlDecode(Parts[3]);
145 NodeObj = await Source.GetNodeAsync(
new ThingReference(NodeID, SourceID, Partition));
149 return await GetNodeActionGraph(Result, NodeObj,
Language, HttpUtility.UrlDecode(Parts[4]),
150 HttpUtility.UrlDecode(Parts[5]), Caller);
172 if (!(Caller is
null) && !await Source.
CanViewAsync(Caller))
175 string SourcePath =
"/" + HttpUtility.UrlEncode(Source.
SourceID);
214 IEnumerable<INode> RootNodes = Source.
RootNodes;
216 if (!(RootNodes is
null))
218 foreach (
INode RootNode
in RootNodes)
235 StringBuilder sb =
new StringBuilder();
248 sb.Append(HttpUtility.UrlEncode(Node.
SourceId));
250 if (!
string.IsNullOrEmpty(Node.
Partition))
253 sb.Append(HttpUtility.UrlEncode(Node.
Partition));
257 sb.Append(HttpUtility.UrlEncode(Node.
NodeId));
313 if (!
string.IsNullOrEmpty(Node.
Partition))
321 if (!(Node.
Parent is
null))
362 if (!(Parameters is
null))
370 DisplayableParameters));
372 foreach (DisplayableParameters.Parameter P in Parameters)
377 DisplayableParameters,
379 DisplayableParameter));
382 DisplayableParameter,
387 DisplayableParameter,
392 DisplayableParameter,
398 IEnumerable<DisplayableParameters.Message> NodeMessages = await Node.
GetMessagesAsync(Caller);
399 if (!(NodeMessages is
null))
409 foreach (DisplayableParameters.Message M in NodeMessages)
428 if (!
string.IsNullOrEmpty(M.EventId))
464 IEnumerable<ICommand> NodeCommands = await Node.
Commands;
466 if (!(Commands is
null))
468 foreach (
ICommand Command
in NodeCommands)
470 if (!await Command.CanExecuteAsync(Caller))
511 await Command.GetSuccessStringAsync(
Language));
514 await Command.GetFailureStringAsync(
Language));
517 await Command.GetConfirmationStringAsync(
Language));
530 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Edit, GetOperationUri(Node,
"edit",
"parameters"),
535 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"all"),
538 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"momentary"),
541 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"identity"),
544 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"status"),
547 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"computed"),
550 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"peak"),
553 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"historical"),
556 AddOperation(Result, Operations, ref ItemIndex,
IoTConcentrator.
Read, GetOperationUri(Node,
"read",
"nonHistorical"),
573 if (!
string.IsNullOrEmpty(Value))
582 private static void AddOperation(
InMemorySemanticCube Result,
BlankNode Operations, ref
int ItemIndex, Uri Predicate, Uri Graph,
string Label)
610 StringBuilder sb =
new StringBuilder();
625 sb.Append(HttpUtility.UrlEncode(Command.CommandID));
634 private static Uri GetOperationUri(
INode Node,
string Category,
string Action)
636 StringBuilder sb =
new StringBuilder();
637 GetOperationUri(Node, Category, Action, sb);
648 private static void GetOperationUri(
INode Node,
string Category,
string Action, StringBuilder sb)
670 foreach (
string Part
in Action.Split(
' '))
672 switch (Part.Trim().ToLower())
702 case "nonhistorical":
703 FieldTypes |=
FieldType.AllExceptHistorical;
731 TaskCompletionSource<bool> ReadoutCompleted =
new TaskCompletionSource<bool>();
736 foreach (
Field F
in e.Fields)
738 BlankNode FieldNode = new BlankNode(
"n" + Guid.NewGuid().ToString());
740 Result.Add(new SemanticTriple(
742 new UriNode(Rdf.ListItem(++FieldIndex)),
745 string LocalizedName;
747 if (F.StringIdSteps is null || F.StringIdSteps.Length == 0)
748 LocalizedName = null;
751 Namespace BaseModule;
753 if (string.IsNullOrEmpty(F.Module))
756 BaseModule = await Language.GetNamespaceAsync(F.Module);
758 LocalizedName = await LocalizationStep.TryGetLocalization(Language, BaseModule, F.StringIdSteps);
761 if (
string.IsNullOrEmpty(LocalizedName))
768 else if (LocalizedName == F.Name)
770 Result.Add(new SemanticTriple(
772 new UriNode(RdfSchema.Label),
773 new StringLiteral(F.Name, Language.Code)));
777 Result.Add(new SemanticTriple(
779 new UriNode(RdfSchema.Label),
780 new StringLiteral(F.Name)));
782 Result.Add(new SemanticTriple(
784 new UriNode(RdfSchema.Label),
785 new StringLiteral(LocalizedName, Language.Code)));
798 if (F.QoS.HasFlag(
FieldQoS.Missing))
800 Result.Add(new SemanticTriple(
802 new UriNode(IoTSensorData.QoSUri),
803 new CustomLiteral(nameof(FieldQoS.Missing), IoTSensorData.QoS)));
806 if (F.QoS.HasFlag(
FieldQoS.InProgress))
808 Result.Add(new SemanticTriple(
810 new UriNode(IoTSensorData.QoSUri),
811 new CustomLiteral(nameof(FieldQoS.InProgress), IoTSensorData.QoS)));
814 if (F.QoS.HasFlag(
FieldQoS.AutomaticEstimate))
816 Result.Add(new SemanticTriple(
818 new UriNode(IoTSensorData.QoSUri),
819 new CustomLiteral(nameof(FieldQoS.AutomaticEstimate), IoTSensorData.QoS)));
822 if (F.QoS.HasFlag(
FieldQoS.ManualEstimate))
824 Result.Add(new SemanticTriple(
826 new UriNode(IoTSensorData.QoSUri),
827 new CustomLiteral(nameof(FieldQoS.ManualEstimate), IoTSensorData.QoS)));
830 if (F.QoS.HasFlag(
FieldQoS.ManualReadout))
832 Result.Add(new SemanticTriple(
834 new UriNode(IoTSensorData.QoSUri),
835 new CustomLiteral(nameof(FieldQoS.ManualReadout), IoTSensorData.QoS)));
838 if (F.QoS.HasFlag(
FieldQoS.AutomaticReadout))
840 Result.Add(new SemanticTriple(
842 new UriNode(IoTSensorData.QoSUri),
843 new CustomLiteral(nameof(FieldQoS.AutomaticReadout), IoTSensorData.QoS)));
846 if (F.QoS.HasFlag(
FieldQoS.TimeOffset))
848 Result.Add(new SemanticTriple(
850 new UriNode(IoTSensorData.QoSUri),
851 new CustomLiteral(nameof(FieldQoS.TimeOffset), IoTSensorData.QoS)));
854 if (F.QoS.HasFlag(
FieldQoS.Warning))
856 Result.Add(new SemanticTriple(
858 new UriNode(IoTSensorData.QoSUri),
859 new CustomLiteral(nameof(FieldQoS.Warning), IoTSensorData.QoS)));
864 Result.Add(new SemanticTriple(
866 new UriNode(IoTSensorData.QoSUri),
867 new CustomLiteral(nameof(FieldQoS.Error), IoTSensorData.QoS)));
872 Result.Add(new SemanticTriple(
874 new UriNode(IoTSensorData.QoSUri),
875 new CustomLiteral(nameof(FieldQoS.Signed), IoTSensorData.QoS)));
878 if (F.QoS.HasFlag(
FieldQoS.Invoiced))
880 Result.Add(new SemanticTriple(
882 new UriNode(IoTSensorData.QoSUri),
883 new CustomLiteral(nameof(FieldQoS.Invoiced), IoTSensorData.QoS)));
886 if (F.QoS.HasFlag(
FieldQoS.EndOfSeries))
888 Result.Add(new SemanticTriple(
890 new UriNode(IoTSensorData.QoSUri),
891 new CustomLiteral(nameof(FieldQoS.EndOfSeries), IoTSensorData.QoS)));
894 if (F.QoS.HasFlag(
FieldQoS.PowerFailure))
896 Result.Add(new SemanticTriple(
898 new UriNode(IoTSensorData.QoSUri),
899 new CustomLiteral(nameof(FieldQoS.PowerFailure), IoTSensorData.QoS)));
902 if (F.QoS.HasFlag(
FieldQoS.InvoiceConfirmed))
904 Result.Add(new SemanticTriple(
906 new UriNode(IoTSensorData.QoSUri),
907 new CustomLiteral(nameof(FieldQoS.InvoiceConfirmed), IoTSensorData.QoS)));
917 Result.Add(new SemanticTriple(
919 new UriNode(Rdf.Type),
920 new CustomLiteral(nameof(FieldType.Momentary), IoTSensorData.FieldType)));
925 Result.Add(new SemanticTriple(
927 new UriNode(Rdf.Type),
928 new CustomLiteral(nameof(FieldType.Identity), IoTSensorData.FieldType)));
933 Result.Add(new SemanticTriple(
935 new UriNode(Rdf.Type),
936 new CustomLiteral(nameof(FieldType.Status), IoTSensorData.FieldType)));
941 Result.Add(new SemanticTriple(
943 new UriNode(Rdf.Type),
944 new CustomLiteral(nameof(FieldType.Computed), IoTSensorData.FieldType)));
949 Result.Add(new SemanticTriple(
951 new UriNode(Rdf.Type),
952 new CustomLiteral(nameof(FieldType.Peak), IoTSensorData.FieldType)));
955 if (F.Type.HasFlag(
FieldType.Historical))
957 Result.Add(new SemanticTriple(
959 new UriNode(Rdf.Type),
960 new CustomLiteral(nameof(FieldType.Historical), IoTSensorData.FieldType)));
965 ReadoutCompleted.TrySetResult(
true);
988 if (!
string.IsNullOrEmpty((Error.
NodeId)))
996 if (!
string.IsNullOrEmpty((Error.
SourceId)))
1004 if (!
string.IsNullOrEmpty((Error.
Partition)))
1014 ReadoutCompleted.TrySetResult(
true);
1016 return Task.CompletedTask;
1019 Task Timeout = Task.Delay(60000);
1020 Task T = await Task.WhenAny(ReadoutCompleted.Task, Timeout);
1022 if (!ReadoutCompleted.Task.IsCompleted)
override void Add(ISemanticTriple Triple)
Adds a triple to the cube.
Represents a bool literal.
Represents a custom literal.
Represents a dateTime literal.
Represents a string literal.
Set of semantic elements.
static ISemanticElement Encapsulate(object Value)
Encapsulates an object as a semantic element.
Implements a semantic triple.
Dublin Core Terms namespace
static readonly Uri Updated
http://purl.org/dc/terms/updated
static readonly Uri Type
http://purl.org/dc/terms/type
static Uri ListItem(int Index)
URI representing an item in a list.
static readonly Uri Type
URI representing rdf:type
static readonly Uri Label
http://www.w3.org/2000/01/rdf-schema#label
Static class managing the runtime environment of the IoT Gateway.
static bool IsDomain(string DomainOrHost, bool IncludeAlternativeDomains)
If a domain or host name represents the gateway.
static string GetUrl(string LocalResource)
Gets a URL for a resource.
static ConcentratorServer ConcentratorServer
XMPP Concentrator Server.
The server understood the request, but is refusing to fulfill it. Authorization will not help and the...
Contains information about what sensor data readout parameters have been approved.
FieldType FieldTypes
Approved types to read.
string[] FieldNames
Approved field names to read.
IThingReference[] Nodes
Approved nodes to read.
Manages a chat sensor data readout request.
Contains information about a language.
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Basic access point for runtime language localization.
static async Task< Language > GetDefaultLanguageAsync()
Gets the default language.
Base class for all nodes in a parsed script tree.
Abstract base class for control parameters.
string Description
Description for parameter.
string Name
Parameter Name
Tokens available in request.
string From
Address of caller.
IoT Concentrator Ontology
static readonly Uri Partition
urn:nf:iot:concentrator:1.0:partition
static readonly Uri Confirmation
urn:nf:iot:concentrator:1.0:confirmation
static readonly Uri CommandType
urn:nf:iot:concentrator:1.0:commandType
static readonly Uri NodeState
urn:nf:iot:concentrator:1.0:nodeState
static readonly Uri ChildSource
urn:nf:iot:concentrator:1.0:childSource
static readonly Uri Success
urn:nf:iot:concentrator:1.0:success
static readonly Uri MessageType
urn:nf:iot:concentrator:1.0:messageType
static readonly Uri Control
urn:nf:iot:concentrator:1.0:control
static readonly Uri Failure
urn:nf:iot:concentrator:1.0:failure
static readonly Uri Body
urn:nf:iot:concentrator:1.0:body
static readonly Uri Command
urn:nf:iot:concentrator:1.0:Command
static readonly Uri LocalId
urn:nf:iot:concentrator:1.0:localId
static readonly Uri DisplayableParameters
urn:nf:iot:concentrator:1.0:dispParam
static readonly Uri IsControllable
urn:nf:iot:concentrator:1.0:isControllable
static readonly Uri ChildNode
urn:nf:iot:concentrator:1.0:childNode
static readonly Uri SourceId
urn:nf:iot:concentrator:1.0:sourceId
static readonly Uri Commands
urn:nf:iot:concentrator:1.0:commands
static readonly Uri Read
urn:nf:iot:concentrator:1.0:read
static readonly Uri Node
urn:nf:iot:concentrator:1.0:Node
static readonly Uri ParameterId
urn:nf:iot:concentrator:1.0:parameterId
static readonly Uri HasChildSource
urn:nf:iot:concentrator:1.0:hasChildSource
static readonly Uri RootNode
urn:nf:iot:concentrator:1.0:rootNode
static readonly Uri Messages
urn:nf:iot:concentrator:1.0:messages
static readonly Uri State
urn:nf:iot:concentrator:1.0:state
static readonly Uri ParentNode
urn:nf:iot:concentrator:1.0:parentNode
static readonly Uri Operations
urn:nf:iot:concentrator:1.0:operations
static readonly Uri DataSource
urn:nf:iot:concentrator:1.0:DataSource
static readonly Uri SortCategory
urn:nf:iot:concentrator:1.0:sortCategory
static readonly Uri Edit
urn:nf:iot:concentrator:1.0:edit
static readonly Uri TypeName
urn:nf:iot:concentrator:1.0:typeName
static readonly Uri CommandId
urn:nf:iot:concentrator:1.0:commandId
static readonly Uri EventId
urn:nf:iot:concentrator:1.0:eventId
static readonly Uri LogId
urn:nf:iot:concentrator:1.0:logId
static readonly Uri HasCommands
urn:nf:iot:concentrator:1.0:hasCommands
static readonly Uri IsReadable
urn:nf:iot:concentrator:1.0:isReadable
static readonly Uri SortKey
urn:nf:iot:concentrator:1.0:sortKey
static readonly Uri NodeId
urn:nf:iot:concentrator:1.0:nodeId
static readonly Uri Errors
urn:nf:iot:sd:1.0:errros
static readonly Uri Fields
urn:nf:iot:sd:1.0:fields
static readonly Uri Value
urn:nf:iot:concentrator:1.0:value
static readonly Uri Timestamp
urn:nf:iot:sd:1.0:timestamp
Makes harmonized data sources and nodes available as semantic information.
static async Task AppendNodeInformation(InMemorySemanticCube Result, INode Node, Language Language, RequestOrigin Caller)
Appends semantic information about a node to a graph.
async Task< ISemanticCube > LoadGraph(Uri GraphUri, ScriptNode Node, bool NullIfNotFound, RequestOrigin Caller)
Loads the graph
DataSourceGraph()
Makes harmonized data sources and nodes available as semantic information.
static Uri GetCommandUri(INode Node, ICommand Command)
Gets the Graph URI for a node command.
static async Task AppendSourceInformation(InMemorySemanticCube Result, IDataSource Source, Language Language, RequestOrigin Caller)
Appends semantic information about a data source to a graph.
static Uri GetNodeUri(INode Node)
Gets the Graph URI for a node.
Grade Supports(Uri GraphUri)
How well the source handles a given Graph URI.
Base class for all sensor data fields.
Contains information about an error on a thing
DateTime Timestamp
Timestamp of error.
string ErrorMessage
Error message.
Contains a reference to a thing
string Partition
Optional partition in which the Node ID is unique.
string SourceId
Optional ID of source containing node.
Interface for semantic nodes.
Interface for graph sources.
Interface for actuator nodes.
Interface for datasources that are published through the concentrator interface.
IEnumerable< INode > RootNodes
Root node references. If no root nodes are available, null is returned.
Task< string > GetNameAsync(Language Language)
Gets the name of data source.
Task< bool > CanViewAsync(RequestOrigin Caller)
If the data source is visible to the caller.
bool HasChildren
If the source has any child sources.
DateTime LastChanged
When the source was last updated.
IEnumerable< IDataSource > ChildSources
Child sources. If no child sources are available, null is returned.
string SourceID
ID of data source.
Interface for nodes that are published through the concentrator interface.
Task< IEnumerable< Parameter > > GetDisplayableParametersAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
bool IsControllable
If the node can be controlled.
bool IsReadable
If the node can be read.
bool HasCommands
If the node has registered commands or not.
DateTime LastChanged
When the node was last updated.
NodeState State
Current overall state of the node.
bool HasChildren
If the source has any child sources.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
INode Parent
Parent Node, or null if a root node.
Task< IEnumerable< Message > > GetMessagesAsync(RequestOrigin Caller)
Gets messages logged on the node.
string LogId
If provided, an ID for the node, as it would appear or be used in system logs. Can be null,...
Task< IEnumerable< ICommand > > Commands
Available command objects. If no commands are available, null is returned.
string LocalId
If provided, an ID for the node, but unique locally between siblings. Can be null,...
Task< bool > CanViewAsync(RequestOrigin Caller)
If the node is visible to the caller.
Interface for sensor nodes.
Interface for thing references.
string Partition
Optional partition in which the Node ID is unique.
string SourceId
Optional ID of source containing node.
FieldQoS
Field Quality of Service flags
FieldType
Field Type flags