diff --git a/src/Participant.cs b/src/Participant.cs
index feb2f05..3c13c1a 100644
--- a/src/Participant.cs
+++ b/src/Participant.cs
@@ -11,10 +11,6 @@ namespace RoboidControl {
/// It also maintains the communcation information to contact the participant.
/// It is used as a basis for the local participant, but also as a reference to remote participants.
public class Participant {
- ///
- /// Default constructor
- ///
- public Participant() { }
///
/// Create a new participant with the given communcation info
///
@@ -35,7 +31,7 @@ namespace RoboidControl {
public int port = 0;
///
- /// The network ID of the participant
+ /// he network Id to identify the participant
///
public byte networkId = 0;
@@ -44,6 +40,48 @@ namespace RoboidControl {
///
public readonly List things = new();
+ ///
+ /// Get the thing with the given properties
+ ///
+ /// The ID of the thing
+ /// The thing when it is found, null in other cases.
+ public Thing Get(byte thingId) {
+ Thing thing = things.Find(aThing => aThing.id == thingId);
+ //Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
+ // if (thing == null)
+ // Console.WriteLine($"Could not find thing {ipAddress}:{port}[{networkId}/{thingId}]");
+ return thing;
+ }
+
+ ///
+ /// Add a new thing for this participant
+ ///
+ /// The thing to add
+ /// If true, the thing.id is regenerated if it is zero
+ public void Add(Thing thing, bool checkId = true) {
+ if (checkId && thing.id == 0) {
+ thing.id = (byte)(this.things.Count + 1);
+ this.things.Add(thing);
+ }
+ else {
+ Thing foundThing = Get(thing.id);
+ if (foundThing == null)
+ this.things.Add(thing);
+ }
+ }
+
+ ///
+ /// Remove a thing for this participant
+ ///
+ /// The thing to remove
+ public void Remove(Thing thing) {
+ this.things.Remove(thing);
+ }
+
+ ///
+ /// Update all things for this participant
+ ///
+ /// The current time in milliseconds (optional)
public virtual void Update(ulong currentTimeMS = 0) {
int n = this.things.Count;
for (int ix = 0; ix < n; ix++) {
@@ -111,58 +149,6 @@ namespace RoboidControl {
Participant.participants.Add(participant);
}
- ///
- /// Get a thing with the given ids
- ///
- /// The network ID of the thing
- /// The ID of the thing
- /// The thing when it is found, null in other cases.
- public Thing Get(byte networkId, byte thingId) {
- Thing thing = things.Find(aThing => aThing.id == thingId);
- //Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
- // if (thing == null)
- // Console.WriteLine($"Could not find thing {ipAddress}:{port}[{networkId}/{thingId}]");
- return thing;
- }
-
- ///
- /// Add a new thing for this participant
- ///
- /// The thing to add
- /// Invoke an notification event when the thing has been added
- public void Add(Thing thing, bool checkId = true, bool invokeEvent = true) {
- if (checkId && thing.id == 0) {
- thing.id = (byte)(this.things.Count + 1);
- this.things.Add(thing);
- }
- // Console.WriteLine($"added thing [{thing.networkId}/{thing.id}]");
- Thing foundThing = Get(thing.networkId, thing.id);
-
- if (foundThing == null) {
- this.things.Add(thing);
-
- // if (invokeEvent)
- // Thing.InvokeNewThing(thing);
- // Console.Write($"Add thing {ipAddress}:{port}[{networkId}/{thing.id}]");
- }
- // else {
- // if (thing != foundThing) {
- // // should be: find first non-existing id...
- // thing.id = (byte)this.things.Count;
- // things.Add(thing);
- // // Console.Write($"Add thing, updated thing id to [{thing.networkId}/{thing.id}]");
- // }
- // }
- }
-
- ///
- /// Remove a thing for this participant
- ///
- /// The thing to remove
- public void Remove(Thing thing) {
- this.things.Remove(thing);
- }
-
}
}
\ No newline at end of file