public string GetOrionDiscoveryJobDescriptionString(
            OrionDiscoveryJobDescription discoveryJobDescription,
            List <DiscoveryPluginInfo> pluginInfos,
            bool jsonFormat = false)
        {
            if (jsonFormat)
            {
                return(SerializationHelper.ToJson((object)discoveryJobDescription));
            }
            DiscoveryPluginInfoCollection pluginInfoCollection1 = new DiscoveryPluginInfoCollection();

            pluginInfoCollection1.set_PluginInfos(pluginInfos);
            DiscoveryPluginInfoCollection pluginInfoCollection2 = pluginInfoCollection1;
            List <Type> typeList = new List <Type>();

            using (List <DiscoveryPluginJobDescriptionBase> .Enumerator enumerator = discoveryJobDescription.get_DiscoveryPluginJobDescriptions().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    DiscoveryPluginJobDescriptionBase current = enumerator.Current;
                    if (!typeList.Contains(((object)current).GetType()))
                    {
                        typeList.Add(((object)current).GetType());
                    }
                }
            }
            return(SerializationHelper.XmlWrap(new List <string>()
            {
                SerializationHelper.ToXmlString((object)pluginInfoCollection2),
                SerializationHelper.ToXmlString((object)discoveryJobDescription, (IEnumerable <Type>)typeList)
            }));
        }
        // Token: 0x0600037A RID: 890 RVA: 0x00015B20 File Offset: 0x00013D20
        public ScheduledJob CreateDiscoveryJob(DiscoveryConfiguration configuration, IDiscoveryPluginFactory pluginFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            Engine engine = this.engineDAL.GetEngine(configuration.EngineId);
            DiscoveryPollingEngineType?discoveryPollingEngineType = OrionDiscoveryJobFactory.GetDiscoveryPollingEngineType(configuration.EngineID, this.engineDAL);
            int maxSnmpReplies;

            if (!int.TryParse(SettingsDAL.Get("SWNetPerfMon-Settings-SNMP MaxReps"), out maxSnmpReplies))
            {
                maxSnmpReplies = 5;
            }
            OrionDiscoveryJobDescription orionDiscoveryJobDescription = new OrionDiscoveryJobDescription
            {
                ProfileId         = configuration.ProfileId,
                EngineId          = configuration.EngineId,
                HopCount          = configuration.HopCount,
                IcmpTimeout       = configuration.SearchTimeout,
                SnmpConfiguration = new DiscoveryCommonSnmpConfiguration
                {
                    MaxSnmpReplies       = maxSnmpReplies,
                    SnmpRetries          = configuration.SnmpRetries,
                    SnmpTimeout          = configuration.SnmpTimeout,
                    SnmpPort             = configuration.SnmpPort,
                    PreferredSnmpVersion = configuration.PreferredSnmpVersion
                },
                DisableICMP                = configuration.DisableICMP,
                PreferredPollingMethod     = configuration.GetDiscoveryPluginConfiguration <CoreDiscoveryPluginConfiguration>().PreferredPollingMethod,
                VulnerabilityCheckDisabled = (SettingsDAL.GetCurrentInt("SWNetPerfMon-Settings-VulnerabilityCheckDisabled", 0) == 1),
                MaxThreadsInDetectionPhase = SettingsDAL.GetCurrentInt("Discovery-MaxThreadsInDetectionPhase", 5),
                MaxThreadsInInventoryPhase = SettingsDAL.GetCurrentInt("Discovery-MaxThreadsInInventoryPhase", 5),
                PreferredDnsAddressFamily  = SettingsDAL.GetCurrentInt("SWNetPerfMon-Settings-Default Preferred AddressFamily DHCP", 4),
                TagFilter     = configuration.TagFilter,
                DefaultProbes = configuration.DefaultProbes
            };
            List <DiscoveryPluginInfo> discoveryPluginInfos = DiscoveryPluginFactory.GetDiscoveryPluginInfos();
            IList <IDiscoveryPlugin>   plugins = pluginFactory.GetPlugins(discoveryPluginInfos);
            List <DiscoveryPluginInfo> list    = new List <DiscoveryPluginInfo>();
            IDictionary <IDiscoveryPlugin, DiscoveryPluginInfo> dictionary = DiscoveryPluginHelper.CreatePairsPluginAndInfo(plugins, discoveryPluginInfos);
            bool flag = RegistrySettings.IsFreePoller();

            foreach (IDiscoveryPlugin discoveryPlugin in plugins)
            {
                if (flag && !(discoveryPlugin is ISupportFreeEngine))
                {
                    OrionDiscoveryJobFactory.log.DebugFormat("Discovery plugin {0} is not supported on FPE machine", discoveryPlugin);
                }
                else if (configuration.ProfileId == null && !(discoveryPlugin is IOneTimeJobSupport))
                {
                    OrionDiscoveryJobFactory.log.DebugFormat("Plugin {0} is not supporting one time job and it's description woun't be added.", discoveryPlugin.GetType().FullName);
                }
                else
                {
                    if (configuration.TagFilter != null && configuration.TagFilter.Any <string>())
                    {
                        IDiscoveryPluginTags discoveryPluginTags = discoveryPlugin as IDiscoveryPluginTags;
                        if (discoveryPluginTags == null)
                        {
                            OrionDiscoveryJobFactory.log.DebugFormat("Discovery job for tags requested, however plugin {0} doesn't support tags, skipping.", discoveryPlugin);
                            continue;
                        }
                        if (!configuration.TagFilter.Intersect(discoveryPluginTags.Tags ?? Enumerable.Empty <string>(), StringComparer.InvariantCultureIgnoreCase).Any <string>())
                        {
                            OrionDiscoveryJobFactory.log.DebugFormat("Discovery job for tags [{0}], however plugin {1} doesn't support any of the tags requested, skipping.", string.Join(",", configuration.TagFilter), discoveryPlugin);
                            continue;
                        }
                    }
                    if (configuration.IsAgentJob)
                    {
                        IAgentPluginJobSupport agentPluginJobSupport = discoveryPlugin as IAgentPluginJobSupport;
                        if (agentPluginJobSupport == null || !configuration.AgentPlugins.Contains(agentPluginJobSupport.PluginId))
                        {
                            OrionDiscoveryJobFactory.log.DebugFormat("Plugin {0} is not contained in supported agent plugins and will not be used.", discoveryPlugin.GetType().FullName);
                            continue;
                        }
                    }
                    if (discoveryPollingEngineType != null && !OrionDiscoveryJobFactory.IsDiscoveryPluginSupportedForDiscoveryPollingEngineType(discoveryPlugin, discoveryPollingEngineType.Value, dictionary))
                    {
                        if (OrionDiscoveryJobFactory.log.IsDebugEnabled)
                        {
                            OrionDiscoveryJobFactory.log.DebugFormat(string.Format("Plugin {0} is not supported for polling engine {1}", discoveryPlugin.GetType().FullName, configuration.EngineID), Array.Empty <object>());
                        }
                    }
                    else
                    {
                        DiscoveryPluginJobDescriptionBase discoveryPluginJobDescriptionBase = null;
                        Exception ex = null;
                        try
                        {
                            discoveryPluginJobDescriptionBase = discoveryPlugin.GetJobDescription(configuration);
                        }
                        catch (Exception ex2)
                        {
                            discoveryPluginJobDescriptionBase = null;
                            ex = ex2;
                        }
                        if (discoveryPluginJobDescriptionBase == null)
                        {
                            string text = "Plugin " + discoveryPlugin.GetType().FullName + " was not able found valid job description.";
                            if (ex != null)
                            {
                                OrionDiscoveryJobFactory.log.Warn(text, ex);
                            }
                            else
                            {
                                OrionDiscoveryJobFactory.log.Warn(text);
                            }
                        }
                        else
                        {
                            orionDiscoveryJobDescription.DiscoveryPluginJobDescriptions.Add(discoveryPluginJobDescriptionBase);
                            DiscoveryPluginInfo item = dictionary[discoveryPlugin];
                            list.Add(item);
                        }
                    }
                }
            }
            JobDescription jobDescription = new JobDescription
            {
                TypeName = typeof(OrionDiscoveryJob).AssemblyQualifiedName,
                JobDetailConfiguration = this.GetOrionDiscoveryJobDescriptionString(orionDiscoveryJobDescription, list, configuration.UseJsonFormat),
                JobNamespace           = "orion",
                ResultTTL       = TimeSpan.FromMinutes(10.0),
                TargetNode      = new HostAddress(IPAddressHelper.ToStringIp(engine.IP), 4),
                LegacyEngine    = engine.ServerName.ToLowerInvariant(),
                EndpointAddress = (configuration.IsAgentJob ? configuration.AgentAddress : null),
                SupportedRoles  = 7
            };

            jobDescription.Timeout = OrionDiscoveryJobFactory.GetDiscoveryJobTimeout(configuration);
            ScheduledJob scheduledJob;

            if (configuration.CronSchedule != null)
            {
                bool   flag2 = false;
                string text2 = configuration.CronSchedule.CronExpression;
                if (string.IsNullOrWhiteSpace(text2))
                {
                    DateTime t = configuration.CronSchedule.StartTime.ToLocalTime();
                    if (t < DateTime.Now)
                    {
                        OrionDiscoveryJobFactory.log.InfoFormat("Profile (ID={0}) with past Once(Cron) schedule. We should not create job for it.", configuration.ProfileID);
                        return(null);
                    }
                    text2 = string.Format("{0} {1} {2} {3} *", new object[]
                    {
                        t.Minute,
                        t.Hour,
                        t.Day,
                        t.Month
                    });
                    flag2 = true;
                }
                scheduledJob              = new ScheduledJob(jobDescription, text2, "net.pipe://localhost/orion/core/scheduleddiscoveryjobsevents2", configuration.ProfileID.ToString());
                scheduledJob.RunOnce      = flag2;
                scheduledJob.TimeZoneInfo = TimeZoneInfo.Local;
                if (!flag2)
                {
                    scheduledJob.Start = configuration.CronSchedule.StartTime.ToUniversalTime();
                    DateTime?endTime  = configuration.CronSchedule.EndTime;
                    DateTime maxValue = DateTime.MaxValue;
                    if ((endTime == null || (endTime != null && endTime.GetValueOrDefault() != maxValue)) && configuration.CronSchedule.EndTime != null)
                    {
                        scheduledJob.End = configuration.CronSchedule.EndTime.Value.ToUniversalTime();
                    }
                }
            }
            else if (!configuration.ScheduleRunAtTime.Equals(DateTime.MinValue))
            {
                scheduledJob = new ScheduledJob(jobDescription, configuration.ScheduleRunAtTime, "net.pipe://localhost/orion/core/scheduleddiscoveryjobsevents2", configuration.ProfileID.ToString());
            }
            else
            {
                scheduledJob = new ScheduledJob(jobDescription, configuration.ScheduleRunFrequency, "net.pipe://localhost/orion/core/scheduleddiscoveryjobsevents2", configuration.ProfileID.ToString());
            }
            return(scheduledJob);
        }