Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ThingReference.cs
1using System.Text;
3
4namespace Waher.Things
5{
9 [CollectionName("ThingReferences")]
10 [ArchivingTime]
11 [Index("NodeId", "SourceId", "Partition")]
13 {
14 private static readonly ThingReference empty = new ThingReference(string.Empty, string.Empty, string.Empty);
15
16 private string objectId = null;
17 private string nodeId;
18 private string sourceId;
19 private string partition;
20
25 : this(string.Empty, string.Empty, string.Empty)
26 {
27 }
28
33 public ThingReference(string NodeId)
34 : this(NodeId, string.Empty, string.Empty)
35 {
36 }
37
43 public ThingReference(string NodeId, string SourceId)
44 : this(NodeId, SourceId, string.Empty)
45 {
46 }
47
54 public ThingReference(string NodeId, string SourceId, string Partition)
55 {
56 this.nodeId = NodeId;
57 this.sourceId = SourceId;
58 this.partition = Partition;
59 }
60
66 {
67 this.nodeId = Reference.NodeId;
68 this.sourceId = Reference.SourceId;
69 this.partition = Reference.Partition;
70 }
71
75 [ObjectId]
76 public string ObjectId
77 {
78 get => this.objectId;
79 set => this.objectId = value;
80 }
81
85 [ShortName("n")]
86 public string NodeId
87 {
88 get => this.nodeId;
89 set => this.nodeId = value;
90 }
91
95 [ShortName("s")]
96 public string SourceId
97 {
98 get => this.sourceId;
99 set => this.sourceId = value;
100 }
101
105 [ShortName("p")]
106 public string Partition
107 {
108 get => this.partition;
109 set => this.partition = value;
110 }
111
115 public bool IsEmpty
116 {
117 get { return string.IsNullOrEmpty(this.nodeId) && string.IsNullOrEmpty(this.sourceId) && string.IsNullOrEmpty(this.partition); }
118 }
119
123 public string Key
124 {
125 get
126 {
127 StringBuilder sb = new StringBuilder();
128
129 if (!string.IsNullOrEmpty(this.nodeId))
130 {
131 sb.Append(this.nodeId);
132
133 if (!string.IsNullOrEmpty(this.sourceId))
134 {
135 sb.Append(", ");
136 sb.Append(this.sourceId);
137
138 if (!string.IsNullOrEmpty(this.partition))
139 {
140 sb.Append(", ");
141 sb.Append(this.partition);
142 }
143 }
144 }
145
146 return sb.ToString();
147 }
148 }
149
155 public bool SameThing(IThingReference Ref)
156 {
157 return this.nodeId == Ref.NodeId && this.sourceId == Ref.SourceId && this.partition == Ref.Partition;
158 }
159
165 public override bool Equals(object obj)
166 {
167 if (obj is IThingReference Ref)
168 return this.SameThing(Ref);
169 else
170 return false;
171 }
172
177 public override int GetHashCode()
178 {
179 return this.nodeId.GetHashCode() ^
180 this.sourceId.GetHashCode() ^
181 this.partition.GetHashCode();
182 }
183
187 public static ThingReference Empty { get { return empty; } }
188
190 public override string ToString()
191 {
192 StringBuilder Output = new StringBuilder();
193
194 if (!string.IsNullOrEmpty(this.objectId))
195 {
196 Output.Append(this.objectId);
197 Output.Append(": ");
198 }
199
200 Output.Append(this.nodeId);
201
202 if (!string.IsNullOrEmpty(this.sourceId))
203 {
204 Output.Append(", ");
205 Output.Append(this.sourceId);
206
207 if (!string.IsNullOrEmpty(this.partition))
208 {
209 Output.Append(", ");
210 Output.Append(this.partition);
211 }
212 }
213
214 return Output.ToString();
215 }
216 }
217}
Contains a reference to a thing
ThingReference()
Contains a reference to a thing
static ThingReference Empty
Empty thing reference. Can be used by sensors that are not part of a concentrator during readout.
bool SameThing(IThingReference Ref)
Checks if the thing reference is equal to other thing reference.
string NodeId
ID of node.
ThingReference(string NodeId, string SourceId, string Partition)
Contains a reference to a thing
string Partition
Optional partition in which the Node ID is unique.
bool IsEmpty
If the reference is an empty reference.
ThingReference(IThingReference Reference)
Contains a reference to a thing
override string ToString()
ThingReference(string NodeId)
Contains a reference to a thing
string ObjectId
Persisted object ID. Is null if object not persisted.
override int GetHashCode()
Serves as the default hash function.
override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
ThingReference(string NodeId, string SourceId)
Contains a reference to a thing
string SourceId
Optional ID of source containing node.
string Key
Key for thing reference: [NodeId[, SourceId[, Partition]]]
Interface for thing references.
string Partition
Optional partition in which the Node ID is unique.
string SourceId
Optional ID of source containing node.