Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScanRootSources.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using Waher.Events;
8
10{
15 {
21 : base(Concentrator, "1")
22 {
23 }
24
28 public override string CommandID => nameof(ScanRootSources);
29
33 public override CommandType Type => CommandType.Simple;
34
39 public override Task<string> GetNameAsync(Language Language)
40 {
41 return Language.GetStringAsync(typeof(ConcentratorDevice), 52, "Scan Root Sources");
42 }
43
47 public override Task ExecuteCommandAsync()
48 {
49 this.StartSearch();
50 return Task.CompletedTask;
51 }
52
53 private async void StartSearch()
54 {
55 try
56 {
57 ConcentratorClient Client = await this.GetConcentratorClient();
58 string FullJid = this.GetRemoteFullJid(Client.Client);
59
60 DataSourceReference[] Sources = await Client.GetRootDataSourcesAsync(FullJid);
61 Dictionary<string, ConcentratorSourceNode> BySourceId = new Dictionary<string, ConcentratorSourceNode>();
62
63 foreach (INode Child in await this.Concentrator.ChildNodes)
64 {
65 if (Child is ConcentratorSourceNode SourceNode)
66 BySourceId[SourceNode.RemoteSourceID] = SourceNode;
67 }
68
69 LinkedList<ScanSource> NewScans = null;
70
71 foreach (DataSourceReference Source in Sources)
72 {
73 if (BySourceId.ContainsKey(Source.SourceID))
74 continue;
75
77 {
78 NodeId = await MeteringNode.GetUniqueNodeId(Source.SourceID),
79 RemoteSourceID = Source.SourceID
80 };
81
82 await this.Concentrator.AddAsync(SourceNode);
83
84 BySourceId[Source.SourceID] = SourceNode;
85
86 if (NewScans is null)
87 NewScans = new LinkedList<ScanSource>();
88
89 NewScans.AddLast(new ScanSource(this.Concentrator, SourceNode));
90 }
91
92 if (!(NewScans is null))
93 {
94 foreach (ScanSource ScanSource in NewScans)
95 await ScanSource.ExecuteCommandAsync();
96 }
97 }
98 catch (Exception ex)
99 {
100 Log.Exception(ex);
101 }
102 }
103
108 public override ICommand Copy()
109 {
110 return new ScanRootSources(this.Concentrator);
111 }
112 }
113}
Static class managing the application event log. Applications and services log events on this static ...
Definition: Log.cs:13
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Definition: Log.cs:1647
Implements an XMPP concentrator client interface.
async Task< DataSourceReference[]> GetRootDataSourcesAsync(string To)
Gets all root data sources from the server.
XmppClient Client
XMPP Client.
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 class for all metering nodes.
Definition: MeteringNode.cs:28
static async Task< string > GetUniqueNodeId(string NodeId)
Gets a Node ID, based on NodeId that is not already available in the database.
Task< IEnumerable< INode > > ChildNodes
Child nodes. If no child nodes are available, null is returned.
virtual async Task AddAsync(INode Child)
Adds a new child to the node.
Abstract base class for concentrator commands.
ConcentratorDevice Concentrator
Reference to the concentrator node.
async Task< ConcentratorClient > GetConcentratorClient()
Gets the concentrator client, if it exists.
string GetRemoteFullJid(XmppClient Client)
Gets the Full JID of the connected device.
Scans a concentrator node for its root sources.
override Task ExecuteCommandAsync()
Executes the command.
ScanRootSources(ConcentratorDevice Concentrator)
Scans a concentrator node for its root sources.
override CommandType Type
Type of command.
override Task< string > GetNameAsync(Language Language)
Gets the name of data source.
override string CommandID
ID of command.
override ICommand Copy()
Creates a copy of the command object.
Node representing an XMPP concentrator.
Node representing a data source in an XMPP concentrator.
Interface for commands.
Definition: ICommand.cs:32
Interface for nodes that are published through the concentrator interface.
Definition: INode.cs:49
CommandType
Command type.
Definition: ICommand.cs:11