diff --git a/Salmon.Core/Depth/StateMachine.cs b/Salmon.Core/Depth/StateMachine.cs index 1a80207..9a575bc 100644 --- a/Salmon.Core/Depth/StateMachine.cs +++ b/Salmon.Core/Depth/StateMachine.cs @@ -81,20 +81,24 @@ public class StateMachine public IEnumerable GetIds() { - if (!Populated) - PopulateWithHistory().Wait(); - lock (Mutex) + { + if (!Populated) + PopulateWithHistory().Wait(); + foreach (var kv in Implementation) yield return kv.Key; + } + } public IEnumerable Get() { - if (!Populated) - PopulateWithHistory().Wait(); - lock (Mutex) + { + if (!Populated) + PopulateWithHistory().Wait(); + foreach (var kv in Implementation) foreach (var kvv in kv.Value) yield return new Triplet @@ -104,17 +108,24 @@ public class StateMachine value = kvv.Value.Value, LastFlush = kvv.Value.When }; + } + } public IEnumerable Get(string key) { - if (!Populated) - PopulateWithHistory().Wait(); - Dictionary dic; + + lock (Mutex) + { + if (!Populated) + PopulateWithHistory().Wait(); + if (!Implementation.TryGetValue(key, out dic)) yield break; + } + foreach(var kv in dic) yield return new Triplet @@ -128,13 +139,19 @@ public class StateMachine public DateTime? GetLastUpdate(string key) { - if (!Populated) - PopulateWithHistory().Wait(); - Dictionary dic; + + + lock (Mutex) + { + if (!Populated) + PopulateWithHistory().Wait(); + if (!Implementation.TryGetValue(key, out dic)) return null; + } + DateTime mostrecent = DateTime.MinValue; foreach (var kv in dic) @@ -149,13 +166,16 @@ public class StateMachine public object? Get(string key, string predicate) { - if (!Populated) - PopulateWithHistory().Wait(); - lock (Mutex) + { + if (!Populated) + PopulateWithHistory().Wait(); + if (Implementation.TryGetValue(key, out var value)) if (value.TryGetValue(predicate, out var ret)) return ret; + } + return null; }