private static DiscoveryResultBase FilterByPriority(
            DiscoveryResultBase result,
            TechnologyManager mgr,
            bool onlyMandatory)
        {
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }
            if (mgr == null)
            {
                throw new ArgumentNullException(nameof(mgr));
            }
            ILookup <string, ITechnologyPolling> lookup = mgr.TechnologyPollingFactory.Items().ToLookup <ITechnologyPolling, string>((Func <ITechnologyPolling, string>)(tp => tp.get_TechnologyPollingID()), (IEqualityComparer <string>)StringComparer.Ordinal);
            List <IDiscoveredObject>             idiscoveredObjectList = new List <IDiscoveredObject>();

            using (IEnumerator <DiscoveryPluginResultBase> enumerator = result.get_PluginResults().GetEnumerator())
            {
                while (((IEnumerator)enumerator).MoveNext())
                {
                    IEnumerable <IDiscoveredObject> discoveredObjects = enumerator.Current.GetDiscoveredObjects();
                    idiscoveredObjectList.AddRange(discoveredObjects);
                }
            }
            List <IDiscoveredObjectWithTechnology> list1 = ((IEnumerable)idiscoveredObjectList).OfType <IDiscoveredObjectWithTechnology>().ToList <IDiscoveredObjectWithTechnology>();

            using (IEnumerator <TechnologyDiscoveryGroup> enumerator1 = DiscoveryFilterResultByTechnology.GetDiscoveryGroupsInternal(mgr).GetEnumerator())
            {
                while (((IEnumerator)enumerator1).MoveNext())
                {
                    TechnologyDiscoveryGroup group = enumerator1.Current;
                    if (!onlyMandatory || group.get_SelectionDisabled())
                    {
                        IEnumerable <IDiscoveredObjectWithTechnology>  list2 = (IEnumerable <IDiscoveredObjectWithTechnology>)((IEnumerable <IDiscoveredObjectWithTechnology>)list1).Where <IDiscoveredObjectWithTechnology>((Func <IDiscoveredObjectWithTechnology, bool>)(n => group.IsMyGroupedObjectType((IDiscoveredObject)n))).ToList <IDiscoveredObjectWithTechnology>();
                        List <List <IDiscoveredObjectWithTechnology> > objectWithTechnologyListList = new List <List <IDiscoveredObjectWithTechnology> >();
                        using (List <IDiscoveredObject> .Enumerator enumerator2 = idiscoveredObjectList.GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                IDiscoveredObject current1 = enumerator2.Current;
                                if (((DiscoveredObjectBase)group).IsChildOf(current1))
                                {
                                    List <IDiscoveredObjectWithTechnology> objectWithTechnologyList = new List <IDiscoveredObjectWithTechnology>();
                                    using (IEnumerator <IDiscoveredObjectWithTechnology> enumerator3 = list2.GetEnumerator())
                                    {
                                        while (((IEnumerator)enumerator3).MoveNext())
                                        {
                                            IDiscoveredObjectWithTechnology current2 = enumerator3.Current;
                                            if (((IDiscoveredObject)current2).IsChildOf(current1))
                                            {
                                                objectWithTechnologyList.Add(current2);
                                            }
                                        }
                                    }
                                    objectWithTechnologyListList.Add(objectWithTechnologyList);
                                }
                            }
                        }
                        using (List <List <IDiscoveredObjectWithTechnology> > .Enumerator enumerator2 = objectWithTechnologyListList.GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                List <IDiscoveredObjectWithTechnology> current = enumerator2.Current;
                                if (onlyMandatory)
                                {
                                    if (((IEnumerable <IDiscoveredObjectWithTechnology>)current).Any <IDiscoveredObjectWithTechnology>((Func <IDiscoveredObjectWithTechnology, bool>)(to => ((IDiscoveredObject)to).get_IsSelected())))
                                    {
                                        continue;
                                    }
                                }
                                else
                                {
                                    current.ForEach((Action <IDiscoveredObjectWithTechnology>)(to => ((IDiscoveredObject)to).set_IsSelected(false)));
                                }
                                DiscoveryFilterResultByTechnology.SelectObjectWithHigherPriority((IEnumerable <IDiscoveredObjectWithTechnology>)current, lookup);
                            }
                        }
                    }
                }
            }
            return(result);
        }
 public static IEnumerable <IDiscoveredObjectGroup> GetDiscoveryGroups(
     TechnologyManager mgr)
 {
     return((IEnumerable <IDiscoveredObjectGroup>)DiscoveryFilterResultByTechnology.GetDiscoveryGroupsInternal(mgr));
 }
Exemplo n.º 3
0
        public static DiscoveryResultBase GetDiscoveryResult(
            int profileId,
            IList <IDiscoveryPlugin> discoveryPlugins)
        {
            if (discoveryPlugins == null)
            {
                throw new ArgumentNullException(nameof(discoveryPlugins));
            }
            if (profileId <= 0)
            {
                throw new ArgumentException(string.Format("Invalid profile ID [{0}]", (object)profileId));
            }
            DiscoveryResultBase discoveryResultBase = new DiscoveryResultBase();

            try
            {
                DiscoveryProfileEntry profileById = DiscoveryProfileEntry.GetProfileByID(profileId);
                discoveryResultBase.set_EngineId(profileById.get_EngineID());
                discoveryResultBase.set_ProfileID(profileById.get_ProfileID());
            }
            catch (Exception ex)
            {
                string message = string.Format("Unable to load profile {0}", (object)profileId);
                DiscoveryResultManager.log.Error((object)message, ex);
                throw new Exception(message, ex);
            }
            if (((ICollection <IDiscoveryPlugin>)discoveryPlugins).Count == 0)
            {
                return(discoveryResultBase);
            }
            int  millisecondsTimeout = 300000;
            bool flag = Environment.StackTrace.Contains("ServiceModel");

            if (flag)
            {
                try
                {
                    System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(configuration.FilePath);
                    XmlNode xmlNode = xmlDocument.SelectSingleNode("/configuration/system.serviceModel/bindings/netTcpBinding/binding[@name=\"Core.NetTcpBinding\"]");
                    if (xmlNode != null)
                    {
                        if (xmlNode.Attributes != null)
                        {
                            millisecondsTimeout = (int)TimeSpan.Parse(xmlNode.Attributes["receiveTimeout"].Value).TotalMilliseconds;
                        }
                    }
                }
                catch (Exception ex)
                {
                    DiscoveryResultManager.log.Warn((object)"Unable to read WCF timeout from Config file.");
                }
            }
            Thread thread = new Thread(new ParameterizedThreadStart(DiscoveryResultManager.LoadResults));

            DiscoveryResultManager.LoadResultsArgs loadResultsArgs = new DiscoveryResultManager.LoadResultsArgs()
            {
                discoveryPlugins = discoveryPlugins,
                profileId        = profileId,
                result           = discoveryResultBase
            };
            thread.Start((object)loadResultsArgs);
            if (flag)
            {
                if (!thread.Join(millisecondsTimeout))
                {
                    DiscoveryResultManager.log.Error((object)"Loading results takes more time than WCF timeout is set. Enable debug logging to see which plugin takes too long.");
                    return(discoveryResultBase);
                }
            }
            else
            {
                thread.Join();
            }
            DiscoveryResultBase result = loadResultsArgs.result;

            DiscoveryFilterResultByTechnology.FilterByPriority(result, TechnologyManager.Instance);
            Stopwatch stopwatch = Stopwatch.StartNew();
            List <DiscoveryPluginResultBase> list = ((IEnumerable <DiscoveryPluginResultBase>)result.get_PluginResults()).ToList <DiscoveryPluginResultBase>();

            result.get_PluginResults().Clear();
            using (List <DiscoveryPluginResultBase> .Enumerator enumerator = list.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    DiscoveryPluginResultBase current = enumerator.Current;
                    result.get_PluginResults().Add(current.GetFilteredPluginResult());
                }
            }
            DiscoveryResultManager.log.DebugFormat("Filtering results took {0} milliseconds.", (object)stopwatch.ElapsedMilliseconds);
            GC.Collect();
            return(result);
        }
 public static DiscoveryResultBase FilterMandatoryByPriority(
     DiscoveryResultBase result,
     TechnologyManager mgr)
 {
     return(DiscoveryFilterResultByTechnology.FilterByPriority(result, mgr, true));
 }
Exemplo n.º 5
0
        // Token: 0x060002A4 RID: 676 RVA: 0x0001028C File Offset: 0x0000E48C
        private static DiscoveryResultBase FilterByPriority(DiscoveryResultBase result, TechnologyManager mgr, bool onlyMandatory)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (mgr == null)
            {
                throw new ArgumentNullException("mgr");
            }
            ILookup <string, ITechnologyPolling> technologyPollingsById = mgr.TechnologyPollingFactory.Items().ToLookup((ITechnologyPolling tp) => tp.TechnologyPollingID, StringComparer.Ordinal);
            List <IDiscoveredObject>             list = new List <IDiscoveredObject>();

            foreach (DiscoveryPluginResultBase discoveryPluginResultBase in result.PluginResults)
            {
                IEnumerable <IDiscoveredObject> discoveredObjects = discoveryPluginResultBase.GetDiscoveredObjects();
                list.AddRange(discoveredObjects);
            }
            List <IDiscoveredObjectWithTechnology> source = list.OfType <IDiscoveredObjectWithTechnology>().ToList <IDiscoveredObjectWithTechnology>();

            foreach (TechnologyDiscoveryGroup group2 in DiscoveryFilterResultByTechnology.GetDiscoveryGroupsInternal(mgr))
            {
                TechnologyDiscoveryGroup group = group2;
                if (!onlyMandatory || group.SelectionDisabled)
                {
                    IEnumerable <IDiscoveredObjectWithTechnology> enumerable = (from n in source
                                                                                where @group.IsMyGroupedObjectType(n)
                                                                                select n).ToList <IDiscoveredObjectWithTechnology>();
                    List <List <IDiscoveredObjectWithTechnology> > list2 = new List <List <IDiscoveredObjectWithTechnology> >();
                    foreach (IDiscoveredObject discoveredObject in list)
                    {
                        if (group.IsChildOf(discoveredObject))
                        {
                            List <IDiscoveredObjectWithTechnology> list3 = new List <IDiscoveredObjectWithTechnology>();
                            foreach (IDiscoveredObjectWithTechnology discoveredObjectWithTechnology in enumerable)
                            {
                                if (discoveredObjectWithTechnology.IsChildOf(discoveredObject))
                                {
                                    list3.Add(discoveredObjectWithTechnology);
                                }
                            }
                            list2.Add(list3);
                        }
                    }
                    foreach (List <IDiscoveredObjectWithTechnology> list4 in list2)
                    {
                        if (onlyMandatory)
                        {
                            if (list4.Any((IDiscoveredObjectWithTechnology to) => to.IsSelected))
                            {
                                continue;
                            }
                        }
                        else
                        {
                            list4.ForEach(delegate(IDiscoveredObjectWithTechnology to)
                            {
                                to.IsSelected = false;
                            });
                        }
                        DiscoveryFilterResultByTechnology.SelectObjectWithHigherPriority(list4, technologyPollingsById);
                    }
                }
            }
            return(result);
        }