public void SetSensorProviderInfo(TheProviderInfo value) { if (value == null) { this.RemoveProperty(strSource); return; } var providerInfoProp = this.GetProperty(strSource, true); if (value.ProviderMid.HasValue) { providerInfoProp.SetProperty(nameof(TheProviderInfo.ProviderMid), value.ProviderMid.Value, ePropertyTypes.TGuid); } else { providerInfoProp.RemoveProperty(nameof(TheProviderInfo.ProviderMid)); } if (value.Subscription != null) { var subscription = value.Subscription; if (!string.IsNullOrEmpty(subscription.SensorId)) { providerInfoProp.SetProperty(nameof(TheThing.TheSensorSubscription.SensorId), subscription.SensorId, ePropertyTypes.TString); } else { providerInfoProp.RemoveProperty(nameof(TheThing.TheSensorSubscription.SensorId)); } if (subscription.SampleRate.HasValue) { providerInfoProp.SetProperty(nameof(TheThing.TheSensorSubscription.SampleRate), subscription.SampleRate.Value, ePropertyTypes.TNumber); } else { providerInfoProp.RemoveProperty(nameof(TheThing.TheSensorSubscription.SampleRate)); } if (subscription.SubscriptionId.HasValue && subscription.SubscriptionId.Value != Guid.Empty && subscription.SubscriptionId.Value != this.cdeMID) { providerInfoProp.SetProperty(nameof(TheThing.TheSensorSubscription.SubscriptionId), subscription.SubscriptionId.Value, ePropertyTypes.TGuid); } var extensionData = subscription?.GetBaseSubscription()?.ExtensionData; // Make sure any state in derived classes is normalized (into ExtensionData) if (extensionData != null) { // TODO: cleanup deleted properties? providerInfoProp.SetProperties(extensionData, DateTimeOffset.MinValue); } } }
public TheProviderInfo GetSensorProviderInfo() { var providerInfoProp = this.GetProperty(strSource); var subscriptionId = TheCommonUtils.CGuid(providerInfoProp?.GetProperty(nameof(TheThing.TheSensorSubscription.SubscriptionId), false)); var providerInfo = new TheProviderInfo { ProviderMid = TheCommonUtils.CGuidNullable(providerInfoProp?.GetProperty(nameof(TheProviderInfo.ProviderMid), false)), Subscription = new TheThing.TheSensorSubscription { SensorId = TheCommonUtils.CStrNullable(providerInfoProp?.GetProperty(nameof(TheThing.TheSensorSubscription.SensorId), false)), SampleRate = TheCommonUtils.CIntNullable(providerInfoProp?.GetProperty(nameof(TheThing.TheSensorSubscription.SampleRate), false)), SubscriptionId = subscriptionId != Guid.Empty ? subscriptionId : this.cdeMID, TargetThing = new TheThingReference(this.OwnerThing), TargetProperty = cdeP.GetPropertyPath(this), ExtensionData = ReadDictionaryFromProperties(providerInfoProp, TheProviderInfo.KnownProperties), } }; return(providerInfo); }