/// <summary> /// Convert to service model /// </summary> /// <param name="registration"></param> /// <returns></returns> public static SupervisorModel ToServiceModel(this SupervisorRegistration registration) { return(new SupervisorModel { Id = SupervisorModelEx.CreateSupervisorId(registration.DeviceId, registration.ModuleId), SiteId = registration.SiteId, Certificate = registration.Certificate?.DecodeAsByteArray(), LogLevel = registration.LogLevel, Connected = registration.IsConnected() ? true : (bool?)null, OutOfSync = registration.IsConnected() && !registration._isInSync ? true : (bool?)null }); }
/// <summary> /// Convert to service model /// </summary> /// <param name="registration"></param> /// <returns></returns> public static SupervisorModel ToServiceModel(this SupervisorRegistration registration) { if (registration == null) { return(null); } return(new SupervisorModel { Id = SupervisorModelEx.CreateSupervisorId(registration.DeviceId, registration.ModuleId), SiteId = registration.SiteId, LogLevel = registration.LogLevel, Connected = registration.IsConnected() ? true : (bool?)null, OutOfSync = registration.IsConnected() && !registration._isInSync ? true : (bool?)null }); }
/// <summary> /// Patch this registration and create patch twin model to upload /// </summary> /// <param name="model"></param> /// <param name="disabled"></param> public static SupervisorRegistration ToSupervisorRegistration( this SupervisorModel model, bool?disabled = null) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var deviceId = SupervisorModelEx.ParseDeviceId(model.Id, out var moduleId); return(new SupervisorRegistration { IsDisabled = disabled, SupervisorId = model.Id, DeviceId = deviceId, ModuleId = moduleId, LogLevel = model.LogLevel, Discovery = model.Discovery ?? DiscoveryMode.Off, AddressRangesToScan = model.DiscoveryConfig?.AddressRangesToScan, NetworkProbeTimeout = model.DiscoveryConfig?.NetworkProbeTimeout, MaxNetworkProbes = model.DiscoveryConfig?.MaxNetworkProbes, PortRangesToScan = model.DiscoveryConfig?.PortRangesToScan, PortProbeTimeout = model.DiscoveryConfig?.PortProbeTimeout, MaxPortProbes = model.DiscoveryConfig?.MaxPortProbes, IdleTimeBetweenScans = model.DiscoveryConfig?.IdleTimeBetweenScans, MinPortProbesPercent = model.DiscoveryConfig?.MinPortProbesPercent, Certificate = model.Certificate?.EncodeAsDictionary(), DiscoveryCallbacks = model.DiscoveryConfig?.Callbacks. EncodeAsDictionary(), SecurityModeFilter = model.DiscoveryConfig?.ActivationFilter?. SecurityMode, TrustListsFilter = model.DiscoveryConfig?.ActivationFilter?. TrustLists.EncodeAsDictionary(), SecurityPoliciesFilter = model.DiscoveryConfig?.ActivationFilter?. SecurityPolicies.EncodeAsDictionary(), DiscoveryUrls = model.DiscoveryConfig?.DiscoveryUrls?. EncodeAsDictionary(), Locales = model.DiscoveryConfig?.Locales?. EncodeAsDictionary(), Connected = model.Connected ?? false, Thumbprint = model.Certificate?.ToSha1Hash(), SiteId = model.SiteId, }); }
/// <summary> /// Patch this registration and create patch twin model to upload /// </summary> /// <param name="model"></param> /// <param name="disabled"></param> public static SupervisorRegistration ToSupervisorRegistration( this SupervisorModel model, bool?disabled = null) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var deviceId = SupervisorModelEx.ParseDeviceId(model.Id, out var moduleId); return(new SupervisorRegistration { IsDisabled = disabled, DeviceId = deviceId, ModuleId = moduleId, LogLevel = model.LogLevel, Connected = model.Connected ?? false, SiteId = model.SiteId, }); }
/// <summary> /// Patch this registration and create patch twin model to upload /// </summary> /// <param name="model"></param> /// <param name="disabled"></param> public static SupervisorRegistration ToSupervisorRegistration( this SupervisorModel model, bool?disabled = null) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var deviceId = SupervisorModelEx.ParseDeviceId(model.Id, out var moduleId); return(new SupervisorRegistration { IsDisabled = disabled, DeviceId = deviceId, ModuleId = moduleId, LogLevel = model.LogLevel, Certificate = model.Certificate?.EncodeAsDictionary(), Connected = model.Connected ?? false, Thumbprint = model.Certificate?.ToSha1Hash(), SiteId = model.SiteId, }); }