Exemplo n.º 1
0
        public void ImportDiscoveryResultForProfile(
            int profileID,
            bool deleteProfileAfterImport,
            DiscoveryImportManager.CallbackDiscoveryImportFinished callback = null,
            bool checkLicenseLimits = false,
            Guid?importID           = null)
        {
            IList <IDiscoveryPlugin> discoveryPlugins = DiscoveryHelper.GetOrderedDiscoveryPlugins();
            SortedDictionary <int, List <IDiscoveryPlugin> > orderedPlugins = DiscoveryPluginHelper.GetOrderedPlugins(discoveryPlugins, (IList <DiscoveryPluginInfo>)DiscoveryHelper.GetDiscoveryPluginInfos());
            DiscoveryResultBase result1 = this.FilterIgnoredItems(DiscoveryResultManager.GetDiscoveryResult(profileID, discoveryPlugins));
            Guid importId = Guid.NewGuid();

            if (importID.HasValue)
            {
                importId = importID.Value;
            }
            DiscoveryImportManager.CallbackDiscoveryImportFinished callbackAfterImport = callback;
            if (deleteProfileAfterImport)
            {
                callbackAfterImport = (DiscoveryImportManager.CallbackDiscoveryImportFinished)((result, id, status) =>
                {
                    this.DeleteOrionDiscoveryProfile(result.get_ProfileID());
                    if (callback == null)
                    {
                        return;
                    }
                    callback(result, id, status);
                });
            }
            DiscoveryImportManager.StartImport(importId, result1, orderedPlugins, checkLicenseLimits, callbackAfterImport);
        }
        // Token: 0x06000622 RID: 1570 RVA: 0x00024EF0 File Offset: 0x000230F0
        public void ImportDiscoveryResultForProfile(int profileID, bool deleteProfileAfterImport, DiscoveryImportManager.CallbackDiscoveryImportFinished callback = null, bool checkLicenseLimits = false, Guid?importID = null)
        {
            IList <IDiscoveryPlugin> orderedDiscoveryPlugins = DiscoveryHelper.GetOrderedDiscoveryPlugins();
            SortedDictionary <int, List <IDiscoveryPlugin> > orderedPlugins = DiscoveryPluginHelper.GetOrderedPlugins(orderedDiscoveryPlugins, DiscoveryHelper.GetDiscoveryPluginInfos());
            DiscoveryResultBase discoveryResult = DiscoveryResultManager.GetDiscoveryResult(profileID, orderedDiscoveryPlugins);
            DiscoveryResultBase result2         = this.FilterIgnoredItems(discoveryResult);
            Guid importId = Guid.NewGuid();

            if (importID != null)
            {
                importId = importID.Value;
            }
            DiscoveryImportManager.CallbackDiscoveryImportFinished callbackAfterImport = callback;
            if (deleteProfileAfterImport)
            {
                callbackAfterImport = delegate(DiscoveryResultBase result, Guid id, StartImportStatus status)
                {
                    this.DeleteOrionDiscoveryProfile(result.ProfileID);
                    if (callback != null)
                    {
                        callback(result, id, status);
                    }
                };
            }
            DiscoveryImportManager.StartImport(importId, result2, orderedPlugins, checkLicenseLimits, callbackAfterImport);
        }
        public ScheduledJob CreateDiscoveryJob(
            DiscoveryConfiguration configuration,
            IDiscoveryPluginFactory pluginFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            Engine engine = this.engineDAL.GetEngine(((DiscoveryConfigurationBase)configuration).get_EngineId());
            DiscoveryPollingEngineType?pollingEngineType = OrionDiscoveryJobFactory.GetDiscoveryPollingEngineType(configuration.get_EngineID(), this.engineDAL);
            int result;

            if (!int.TryParse(SettingsDAL.Get("SWNetPerfMon-Settings-SNMP MaxReps"), out result))
            {
                result = 5;
            }
            OrionDiscoveryJobDescription discoveryJobDescription1 = new OrionDiscoveryJobDescription();

            discoveryJobDescription1.set_ProfileId(((DiscoveryConfigurationBase)configuration).get_ProfileId());
            discoveryJobDescription1.set_EngineId(((DiscoveryConfigurationBase)configuration).get_EngineId());
            discoveryJobDescription1.set_HopCount(configuration.get_HopCount());
            discoveryJobDescription1.set_IcmpTimeout(configuration.get_SearchTimeout());
            DiscoveryCommonSnmpConfiguration snmpConfiguration = new DiscoveryCommonSnmpConfiguration();

            snmpConfiguration.set_MaxSnmpReplies(result);
            snmpConfiguration.set_SnmpRetries(configuration.get_SnmpRetries());
            snmpConfiguration.set_SnmpTimeout(configuration.get_SnmpTimeout());
            snmpConfiguration.set_SnmpPort(configuration.get_SnmpPort());
            snmpConfiguration.set_PreferredSnmpVersion(configuration.get_PreferredSnmpVersion());
            discoveryJobDescription1.set_SnmpConfiguration(snmpConfiguration);
            discoveryJobDescription1.set_DisableICMP(configuration.get_DisableICMP());
            discoveryJobDescription1.set_PreferredPollingMethod(((CoreDiscoveryPluginConfiguration)((DiscoveryConfigurationBase)configuration).GetDiscoveryPluginConfiguration <CoreDiscoveryPluginConfiguration>()).get_PreferredPollingMethod());
            discoveryJobDescription1.set_VulnerabilityCheckDisabled(SettingsDAL.GetCurrentInt("SWNetPerfMon-Settings-VulnerabilityCheckDisabled", 0) == 1);
            discoveryJobDescription1.set_MaxThreadsInDetectionPhase(SettingsDAL.GetCurrentInt("Discovery-MaxThreadsInDetectionPhase", 5));
            discoveryJobDescription1.set_MaxThreadsInInventoryPhase(SettingsDAL.GetCurrentInt("Discovery-MaxThreadsInInventoryPhase", 5));
            discoveryJobDescription1.set_PreferredDnsAddressFamily(SettingsDAL.GetCurrentInt("SWNetPerfMon-Settings-Default Preferred AddressFamily DHCP", 4));
            discoveryJobDescription1.set_TagFilter(configuration.get_TagFilter());
            discoveryJobDescription1.set_DefaultProbes(configuration.get_DefaultProbes());
            OrionDiscoveryJobDescription discoveryJobDescription2 = discoveryJobDescription1;
            List <DiscoveryPluginInfo>   discoveryPluginInfos     = DiscoveryPluginFactory.GetDiscoveryPluginInfos();
            IList <IDiscoveryPlugin>     plugins     = pluginFactory.GetPlugins((IList <DiscoveryPluginInfo>)discoveryPluginInfos);
            List <DiscoveryPluginInfo>   pluginInfos = new List <DiscoveryPluginInfo>();
            IDictionary <IDiscoveryPlugin, DiscoveryPluginInfo> pairsPluginAndInfo = DiscoveryPluginHelper.CreatePairsPluginAndInfo((IEnumerable <IDiscoveryPlugin>)plugins, (IEnumerable <DiscoveryPluginInfo>)discoveryPluginInfos);
            bool flag1 = RegistrySettings.IsFreePoller();

            using (IEnumerator <IDiscoveryPlugin> enumerator = ((IEnumerable <IDiscoveryPlugin>)plugins).GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    IDiscoveryPlugin current = enumerator.Current;
                    if (flag1 && !(current is ISupportFreeEngine))
                    {
                        OrionDiscoveryJobFactory.log.DebugFormat("Discovery plugin {0} is not supported on FPE machine", (object)current);
                    }
                    else if (!((DiscoveryConfigurationBase)configuration).get_ProfileId().HasValue&& !(current is IOneTimeJobSupport))
                    {
                        OrionDiscoveryJobFactory.log.DebugFormat("Plugin {0} is not supporting one time job and it's description woun't be added.", (object)((object)current).GetType().FullName);
                    }
                    else
                    {
                        if (configuration.get_TagFilter() != null && configuration.get_TagFilter().Any <string>())
                        {
                            if (!(current is IDiscoveryPluginTags idiscoveryPluginTags))
                            {
                                OrionDiscoveryJobFactory.log.DebugFormat("Discovery job for tags requested, however plugin {0} doesn't support tags, skipping.", (object)current);
                                continue;
                            }
                            if (!configuration.get_TagFilter().Intersect <string>(idiscoveryPluginTags.get_Tags() ?? Enumerable.Empty <string>(), (IEqualityComparer <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.", (object)string.Join(",", (IEnumerable <string>)configuration.get_TagFilter()), (object)current);
                                continue;
                            }
                        }
                        if (configuration.get_IsAgentJob() && (!(current is IAgentPluginJobSupport pluginJobSupport) || !((IEnumerable <string>)configuration.get_AgentPlugins()).Contains <string>(pluginJobSupport.get_PluginId())))
                        {
                            OrionDiscoveryJobFactory.log.DebugFormat("Plugin {0} is not contained in supported agent plugins and will not be used.", (object)((object)current).GetType().FullName);
                        }
Exemplo n.º 4
0
        public void ImportDiscoveryResultsForConfiguration(
            DiscoveryImportConfiguration importCfg,
            Guid importID)
        {
            DiscoveryLogic.log.DebugFormat("Loading discovery results.", Array.Empty <object>());
            if (DiscoveryProfileEntry.GetProfileByID(importCfg.get_ProfileID()) == null)
            {
                throw new Exception(string.Format("Requested profile {0} not found.", (object)importCfg.get_ProfileID()));
            }
            DiscoveryImportManager.UpdateProgress(importID, "ImportDiscoveryResults Started", "Loading Plugins", false);
            IList <IDiscoveryPlugin> discoveryPlugins = DiscoveryHelper.GetOrderedDiscoveryPlugins();
            SortedDictionary <int, List <IDiscoveryPlugin> > orderedPlugins = DiscoveryPluginHelper.GetOrderedPlugins(discoveryPlugins, (IList <DiscoveryPluginInfo>)DiscoveryHelper.GetDiscoveryPluginInfos());
            DiscoveryResultBase discoveryResult = DiscoveryResultManager.GetDiscoveryResult(importCfg.get_ProfileID(), discoveryPlugins);
            DiscoveryResultBase result1;

            if (importCfg.get_NodeIDs().Count > 0)
            {
                DiscoveryLogic.log.DebugFormat("Nodes to be imported : {0}", (object)importCfg.get_NodeIDs().Count);
                using (List <DiscoveredNode> .Enumerator enumerator = ((CoreDiscoveryPluginResult)discoveryResult.GetPluginResultOfType <CoreDiscoveryPluginResult>()).get_DiscoveredNodes().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DiscoveredNode current = enumerator.Current;
                        if (importCfg.get_NodeIDs().Contains(current.get_NodeID()))
                        {
                            ((DiscoveredObjectBase)current).set_IsSelected(true);
                        }
                        else
                        {
                            ((DiscoveredObjectBase)current).set_IsSelected(false);
                        }
                    }
                }
                using (List <DiscoveryPluginResultBase> .Enumerator enumerator = this.Linearize((IEnumerable <DiscoveryPluginResultBase>)discoveryResult.get_PluginResults()).GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DiscoveryPluginResultBase current          = enumerator.Current;
                        DiscoveryPluginResultBase pluginResultBase = !(current is IDiscoveryPluginResultContextFiltering contextFiltering) ? current.GetFilteredPluginResult() : contextFiltering.GetFilteredPluginResultFromContext(discoveryResult);
                        discoveryResult.get_PluginResults().Remove(current);
                        discoveryResult.get_PluginResults().Add(pluginResultBase);
                        DiscoveryLogic.log.DebugFormat("Applying filters for pluggin - {0}.", (object)current.get_PluginTypeName());
                    }
                }
                result1 = this.FilterIgnoredItems(discoveryResult);
            }
            else
            {
                result1 = discoveryResult;
            }
            result1.set_ProfileID(importCfg.get_ProfileID());
            DiscoveryLogic.log.DebugFormat("Importing started.", Array.Empty <object>());
            if (importCfg.get_DeleteProfileAfterImport())
            {
                DiscoveryImportManager.StartImport(importID, result1, orderedPlugins, false, (DiscoveryImportManager.CallbackDiscoveryImportFinished)((result, importId, importStatus) => this.DeleteOrionDiscoveryProfile(result.get_ProfileID())));
            }
            else
            {
                DiscoveryImportManager.StartImport(importID, result1, orderedPlugins);
            }
        }
        // Token: 0x06000624 RID: 1572 RVA: 0x00024FD4 File Offset: 0x000231D4
        public void ImportDiscoveryResultsForConfiguration(DiscoveryImportConfiguration importCfg, Guid importID)
        {
            DiscoveryLogic.log.DebugFormat("Loading discovery results.", Array.Empty <object>());
            if (DiscoveryProfileEntry.GetProfileByID(importCfg.ProfileID) == null)
            {
                throw new Exception(string.Format("Requested profile {0} not found.", importCfg.ProfileID));
            }
            DiscoveryImportManager.UpdateProgress(importID, "ImportDiscoveryResults Started", "Loading Plugins", false);
            IList <IDiscoveryPlugin> orderedDiscoveryPlugins = DiscoveryHelper.GetOrderedDiscoveryPlugins();
            SortedDictionary <int, List <IDiscoveryPlugin> > orderedPlugins = DiscoveryPluginHelper.GetOrderedPlugins(orderedDiscoveryPlugins, DiscoveryHelper.GetDiscoveryPluginInfos());
            DiscoveryResultBase discoveryResult = DiscoveryResultManager.GetDiscoveryResult(importCfg.ProfileID, orderedDiscoveryPlugins);
            DiscoveryResultBase discoveryResultBase;

            if (importCfg.NodeIDs.Count > 0)
            {
                DiscoveryLogic.log.DebugFormat("Nodes to be imported : {0}", importCfg.NodeIDs.Count);
                foreach (DiscoveredNode discoveredNode in discoveryResult.GetPluginResultOfType <CoreDiscoveryPluginResult>().DiscoveredNodes)
                {
                    if (importCfg.NodeIDs.Contains(discoveredNode.NodeID))
                    {
                        discoveredNode.IsSelected = true;
                    }
                    else
                    {
                        discoveredNode.IsSelected = false;
                    }
                }
                foreach (DiscoveryPluginResultBase discoveryPluginResultBase in this.Linearize(discoveryResult.PluginResults))
                {
                    IDiscoveryPluginResultContextFiltering discoveryPluginResultContextFiltering = discoveryPluginResultBase as IDiscoveryPluginResultContextFiltering;
                    DiscoveryPluginResultBase discoveryPluginResultBase2;
                    if (discoveryPluginResultContextFiltering != null)
                    {
                        discoveryPluginResultBase2 = discoveryPluginResultContextFiltering.GetFilteredPluginResultFromContext(discoveryResult);
                    }
                    else
                    {
                        discoveryPluginResultBase2 = discoveryPluginResultBase.GetFilteredPluginResult();
                    }
                    discoveryResult.PluginResults.Remove(discoveryPluginResultBase);
                    discoveryResult.PluginResults.Add(discoveryPluginResultBase2);
                    DiscoveryLogic.log.DebugFormat("Applying filters for pluggin - {0}.", discoveryPluginResultBase.PluginTypeName);
                }
                discoveryResultBase = this.FilterIgnoredItems(discoveryResult);
            }
            else
            {
                discoveryResultBase = discoveryResult;
            }
            discoveryResultBase.ProfileID = importCfg.ProfileID;
            DiscoveryLogic.log.DebugFormat("Importing started.", Array.Empty <object>());
            if (importCfg.DeleteProfileAfterImport)
            {
                DiscoveryImportManager.StartImport(importID, discoveryResultBase, orderedPlugins, false, delegate(DiscoveryResultBase result, Guid importId, StartImportStatus importStatus)
                {
                    this.DeleteOrionDiscoveryProfile(result.ProfileID);
                });
                return;
            }
            DiscoveryImportManager.StartImport(importID, discoveryResultBase, orderedPlugins);
        }
        // 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);
        }