private IEnumerable <TheThing> GetMatchingThings(Subscription subscription) { var things = new List <TheThing>(); if (_thingReference.ThingMID.HasValue && _thingReference.ThingMID != Guid.Empty) { var thing = TheThingRegistry.GetThingByMID(_thingReference.ThingMID.Value, true); if (thing != null) { things.Add(thing); } return(things); } IBaseEngine baseEngine = null; List <TheThing> matchingThings = null; if (!string.IsNullOrEmpty(_thingReference.EngineName)) { baseEngine = TheThingRegistry.GetBaseEngine(_thingReference.EngineName); if (baseEngine == null) { TheCDEngines.RegisterNewMiniRelay(_thingReference.EngineName); baseEngine = TheThingRegistry.GetBaseEngine(_thingReference.EngineName); } if (baseEngine != null) { subscription?.AddSubscription(baseEngine, this); matchingThings = TheThingRegistry.GetThingsOfEngine(_thingReference.EngineName, true, true); } } else { object deviceTypeObj = null; if (_thingReference.PropertiesToMatch?.TryGetValue("DeviceType", out deviceTypeObj) == true) { var deviceType = TheCommonUtils.CStr(deviceTypeObj); if (!string.IsNullOrEmpty(deviceType)) { matchingThings = TheThingRegistry.GetThingsByFunc("*", t => t.DeviceType.Equals(deviceType, StringComparison.Ordinal), true); } } } if (matchingThings != null) { foreach (var thing in matchingThings) { if (Matches(thing)) { if (baseEngine == null) { subscription?.AddSubscription(thing.GetBaseEngine(), this); } things.Add(thing); } } } return(things); }