Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
MeteringGroupReference.cs
2using System.Threading.Tasks;
5using Waher.Things;
7
9{
14 {
19 {
20 }
21
25 [Header(8, "Group ID:", 10)]
26 [Page(4, "Group", 0)]
27 [ToolTip(9, "Group ID of the group being referenced.")]
28 [Required]
29 public string ReferenceNodeId { get; set; }
30
36 public override Task<string> GetTypeNameAsync(Language Language)
37 {
38 return Language.GetStringAsync(typeof(MeteringGroupReference), 10, "Metering Group Reference");
39 }
40
46 public override Task<bool> AcceptsChildAsync(INode Child)
47 {
48 return Task.FromResult(false);
49 }
50
56 public override Task<bool> AcceptsParentAsync(INode Parent)
57 {
58 return Task.FromResult(Parent is MeteringGroup);
59 }
60
64 public async Task<T[]> FindNodes<T>()
65 where T : INode
66 {
67 ChunkedList<T> Nodes = new ChunkedList<T>();
68 await this.FindNodes(Nodes);
69 return Nodes.ToArray();
70 }
71
76 public async Task FindNodes<T>(ChunkedList<T> Nodes)
77 where T : INode
78 {
79 INode Node = await GroupSource.GetNode(this.ReferenceNodeId);
80
81 if (Node is null)
82 {
83 await this.LogErrorAsync("InvalidReference", "Group not found.");
84 return;
85 }
86
87 if (Node is T TypedNode)
88 Nodes.Add(TypedNode);
89
90 ChunkedList<INode> CheckChildren = new ChunkedList<INode>() { Node };
91
92 while (CheckChildren.HasFirstItem)
93 {
94 Node = CheckChildren.RemoveFirst();
95 IEnumerable<INode> Children = await Node.ChildNodes;
96
97 if (!(Children is null))
98 {
99 foreach (INode Child in Children)
100 {
101 if (Child is T TypedChild)
102 Nodes.Add(TypedChild);
103 else
104 CheckChildren.Add(Child);
105 }
106 }
107 }
108 }
109 }
110}
Base class for all group nodes.
Definition: GroupNode.cs:29
virtual Task LogErrorAsync(string Body)
Logs an error message on the node.
Definition: GroupNode.cs:192
INode Parent
Parent Node, or null if a root node.
Definition: GroupNode.cs:621
Defines the Groups data source. This data source contains a tree structure of groups of nodes
Definition: GroupSource.cs:21
static Task< GroupNode > GetNode(string NodeId)
Gets a node from the Metering Topology
Definition: GroupSource.cs:101
Represents a group of metering nodes.
override Task< bool > AcceptsChildAsync(INode Child)
If the node accepts a presumptive child, i.e. can receive as a child (if that child accepts the node ...
async Task< T[]> FindNodes< T >()
Finds nodes referenced by the group node.
override Task< bool > AcceptsParentAsync(INode Parent)
If the node accepts a presumptive parent, i.e. can be added to that parent (if that parent accepts th...
override Task< string > GetTypeNameAsync(Language Language)
Gets the type name of the node.
A chunked list is a linked list of chunks of objects of type T .
Definition: ChunkedList.cs:54
bool HasFirstItem
If there is a first item in the collection
Definition: ChunkedList.cs:778
T RemoveFirst()
Removes the first item in the collection.
Definition: ChunkedList.cs:876
void Add(T Item)
Adds an item to the collection.
Definition: ChunkedList.cs:272
T[] ToArray()
Returns an array containing all elements of the collection.
Contains information about a language.
Definition: Language.cs:17
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 ...
Definition: Language.cs:209
Base Interface for all metering nodes.
Definition: IGroup.cs:11
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
Definition: INode.cs:140