3using System.Threading.Tasks;
27 private static readonly Dictionary<string, IDataSource> sources =
new Dictionary<string, IDataSource>();
28 private static readonly Dictionary<string, GroupNode> nodes =
new Dictionary<string, GroupNode>();
29 private static Root root =
null;
33 private DateTime lastChanged;
48 string IDataSource.SourceID =>
SourceID;
65 get => this.lastChanged;
68 if (this.lastChanged != value)
70 this.lastChanged = value;
101 public static Task<GroupNode>
GetNode(
string NodeId)
126 if (nodes.TryGetValue(NodeRef.NodeId, out
GroupNode Node))
130 nodes[NodeRef.NodeId] = Node2;
149 nodes[Node.
NodeId] = Node;
165 if (!nodes.TryGetValue(OldId, out
GroupNode Node2) || Node2 != Node)
168 if (nodes.TryGetValue(Node.
NodeId, out Node2))
172 nodes[Node.
NodeId] = Node;
178 internal static void UnregisterNode(
GroupNode Node)
184 if (nodes.TryGetValue(Node.
NodeId, out
GroupNode Node2) && Node == Node2)
185 nodes.Remove(Node.
NodeId);
210 return new INode[] { root };
228 private static async Task LoadRoot()
256 NodeType = Result.GetType().FullName,
264 ParentId =
string.Empty,
265 ParentPartition =
string.Empty,
267 State = Result.
State,
273 Timestamp = DateTime.UtcNow
279 nodes[Result.
NodeId] = Result;
292 if (MaxAge <= TimeSpan.Zero)
293 throw new ArgumentException(
"Age must be positive.", nameof(MaxAge));
295 DateTime Limit = DateTime.Now.Subtract(MaxAge);
302 KeyValuePair<string, object>[] Tags =
new KeyValuePair<string, object>[]
304 new KeyValuePair<string, object>(
"Limit", Limit),
305 new KeyValuePair<string, object>(
"NrEvents", NrEvents)
320 public event EventHandlerAsync<SourceEvent>
OnEvent =
null;
325 await (instance?.
OnEvent?.Raise(instance,
Event) ?? Task.CompletedTask);
342 if (ParentNode is
null)
349 nodes.Remove(Node.
NodeId);
367 if (sources.TryGetValue(SourceId, out Source))
368 return !(Source is
null);
371 if (dataSources is
null)
374 if (dataSources is
null || !dataSources.TryGetDataSource(SourceId, out Source))
379 sources[SourceId] = Source;
382 return !(Source is
null);
Class representing an event.
Static class managing the application event log. Applications and services log events on this static ...
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Base class for all group nodes.
NodeState State
Current overall state of the node.
virtual bool IsControllable
If the node can be controlled.
virtual string LocalId
If provided, an ID for the node, but unique locally between siblings. Can be null,...
virtual bool IsReadable
If the node can be read.
string Partition
Optional partition in which the Node ID is unique.
virtual bool HasCommands
If the node has registered commands or not.
Guid ParentId
Object ID of parent node in persistence layer.
string SourceId
Optional ID of source containing node.
virtual bool ChildrenOrdered
If the children of the node have an intrinsic order (true), or if the order is not important (false).
virtual string LogId
If provided, an ID for the node, as it would appear or be used in system logs. Can be null,...
DateTime Updated
When node was last updated. If it has not been updated, value will be DateTime.MinValue.
async Task< Parameter[]> GetDisplayableParameterAraryAsync(Language Language, RequestOrigin Caller)
Gets displayable parameters.
bool HasChildren
If the source has any child sources.
Defines the Groups data source. This data source contains a tree structure of groups of nodes
static async Task< GroupNode > GetNode(IThingReference NodeRef)
Gets a node from the Metering Topology
Task< bool > CanViewAsync(RequestOrigin Caller)
If the data source is visible to the caller.
IEnumerable< IDataSource > ChildSources
Child sources. If no child sources are available, null is returned.
Task< string > GetNameAsync(Language Language)
Gets the name of data source.
static async Task< int > DeleteOldEvents(TimeSpan MaxAge)
Deletes old data source events.
static Root Root
Root node.
GroupSource()
Defines the Metering Topology data source. This data source contains a tree structure of persistent r...
bool HasChildren
If the source has any child sources.
IEnumerable< INode > RootNodes
Root node references. If no root nodes are available, null is returned.
DateTime LastChanged
When the source was last updated.
async Task< INode > GetNodeAsync(IThingReference NodeRef)
Gets the node, given a reference to it.
static bool TryGetDataSource(string SourceId, out IDataSource Source)
Tries to get a data source, given its Source ID.
const string SourceID
Source ID for the groups data source.
static Task< GroupNode > GetNode(string NodeId)
Gets a node from the Metering Topology
EventHandlerAsync< SourceEvent > OnEvent
Event raised when a data source event has been raised.
static async Task< int > DeleteOrphans()
Deletes orphaned nodes in the metering topology source.
Class for the root node of the Groups data source.
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static async Task Delete(object Object)
Deletes an object in the database.
static Task< IEnumerable< object > > Find(string Collection, params string[] SortOrder)
Finds objects in a given collection.
static async Task Insert(object Object)
Inserts an object into the default collection of the database.
static Task< object > TryLoadObject(string CollectionName, object ObjectId)
Tries to load an object given its Object ID ObjectId and its collection name CollectionName .
This filter selects objects that conform to all child-filters provided.
This filter selects objects that have a named field equal to a given value.
This filter selects objects that have a named field lesser or equal to a given value.
Static class that dynamically manages types and interfaces available in the runtime environment.
static bool TryGetModuleParameter(string Name, out object Value)
Tries to get a module parameter value.
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.
Static class managing persistent settings.
static string Get(string Key, string DefaultValue)
Gets a string-valued setting.
static async Task< bool > SetAsync(string Key, string Value)
Sets a string-valued setting.
Tokens available in request.
static readonly RequestOrigin Empty
Empty request origin.
bool HasPrivilege(string Privilege)
If the origin has a given privilege.
static string EmptyIfSame(string Id1, string Id2)
Returns Id1 if different, string.Empty if the same.
Abstract base class for all data source events.
Contains a reference to a thing
Interface for datasources that are published through the concentrator interface.
Interface for collections of data sources.
Interface for nodes that are published through the concentrator interface.
Interface for thing references.
string Partition
Optional partition in which the Node ID is unique.
string SourceId
Optional ID of source containing node.