Example #1
0
 /// <summary>
 /// Equality comparison
 /// </summary>
 /// <param name="model"></param>
 /// <param name="that"></param>
 /// <returns></returns>
 public static bool IsSameAs(this DiscovererModel model,
                             DiscovererModel that)
 {
     if (model == that)
     {
         return(true);
     }
     if (model == null || that == null)
     {
         return(false);
     }
     return(that.Id == model.Id);
 }
Example #2
0
 /// <summary>
 /// Deep clone
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static DiscovererModel Clone(this DiscovererModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new DiscovererModel {
         Connected = model.Connected,
         Discovery = model.Discovery,
         DiscoveryConfig = model.DiscoveryConfig.Clone(),
         Id = model.Id,
         OutOfSync = model.OutOfSync,
         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 DiscovererRegistration ToDiscovererRegistration(
            this DiscovererModel model, bool?disabled = null)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            var deviceId = DiscovererModelEx.ParseDeviceId(model.Id,
                                                           out var moduleId);

            return(new DiscovererRegistration {
                IsDisabled = disabled,
                DeviceId = deviceId,
                ModuleId = moduleId,
                LogLevel = model.LogLevel,
                Discovery = model.RequestedMode ?? DiscoveryMode.Off,
                AddressRangesToScan = model.RequestedConfig?.AddressRangesToScan,
                NetworkProbeTimeout = model.RequestedConfig?.NetworkProbeTimeout,
                MaxNetworkProbes = model.RequestedConfig?.MaxNetworkProbes,
                PortRangesToScan = model.RequestedConfig?.PortRangesToScan,
                PortProbeTimeout = model.RequestedConfig?.PortProbeTimeout,
                MaxPortProbes = model.RequestedConfig?.MaxPortProbes,
                IdleTimeBetweenScans = model.RequestedConfig?.IdleTimeBetweenScans,
                MinPortProbesPercent = model.RequestedConfig?.MinPortProbesPercent,
                SecurityModeFilter = model.RequestedConfig?.ActivationFilter?.
                                     SecurityMode,
                TrustListsFilter = model.RequestedConfig?.ActivationFilter?.
                                   TrustLists.EncodeAsDictionary(),
                SecurityPoliciesFilter = model.RequestedConfig?.ActivationFilter?.
                                         SecurityPolicies.EncodeAsDictionary(),
                DiscoveryUrls = model.RequestedConfig?.DiscoveryUrls?.
                                EncodeAsDictionary(),
                Locales = model.RequestedConfig?.Locales?.
                          EncodeAsDictionary(),
                Connected = model.Connected ?? false,
                Version = null,
                SiteId = model.SiteId,
            });
        }