Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SingletonMachineId.cs
1using System;
2using Waher.Script;
5
7{
12 {
17 : base()
18 {
19 }
20
24 public override string LocalName => nameof(SingletonMachineId);
25
30 public override IStateMachineNode Create()
31 {
32 return new SingletonMachineId();
33 }
34
39 public override void CheckReferences(StateMachine Machine, Token Token)
40 {
41 if (!this.tag.IsConstant)
42 throw new Exception("Singleton Machine IDs must be constant tag references.");
43
44 if (!Token.TryGetTagValue(this.tag.Definition, out object Value))
45 throw new Exception("Tag not found: " + this.tag.Definition);
46
47 if (!(Value is string MachineId))
48 throw new Exception("Singleton Machine IDs must be strings.");
49
50 int i = MachineId.IndexOf('@');
51 int j = Token.TokenId.IndexOf('@');
52
53 if (j >= 0)
54 {
55 if (i < 0)
56 MachineId += Token.TokenId.Substring(j);
57 else if (MachineId.Substring(i) != Token.TokenId.Substring(j))
58 throw new Exception("Invalid Singleton Machine ID domain.");
59 }
60
61 Machine.StateMachineId = MachineId;
62 }
63 }
64}
CaseInsensitiveString TokenId
Token ID
Definition: Token.cs:139
bool TryGetTagValue(CaseInsensitiveString TagName, out object Value)
Tries to get a TAG value from the token.
Definition: Token.cs:1201
override IStateMachineNode Create()
Creates a new node of the corresponding type.
override void CheckReferences(StateMachine Machine, Token Token)
Checks references in the node.
Abstract base class for nodes with a value.
Definition: Value.cs:13
Class representing a state machine.
Definition: StateMachine.cs:37