Esempio n. 1
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);
        }
Esempio n. 2
0
 private void DeleteDiscoveryProfileInternal(DiscoveryProfileEntry profile)
 {
     if (profile.get_JobID() != Guid.Empty)
     {
         DiscoveryLogic.log.DebugFormat("Deleting job for profile {0}", (object)profile.get_ProfileID());
         try
         {
             if (this.JobFactory.DeleteJob(profile.get_JobID()))
             {
                 DiscoveryLogic.log.ErrorFormat("Error when deleting job {0}.", (object)profile.get_ProfileID());
             }
             DiscoveryLogic.log.DebugFormat("Job for profile {0} deleted.", (object)profile.get_ProfileID());
         }
         catch (Exception ex)
         {
             DiscoveryLogic.log.ErrorFormat("Exception when deleting job {0}. Exception: {1}", (object)profile.get_ProfileID(), (object)ex);
         }
     }
     DiscoveryLogic.log.DebugFormat("Removing profile {0} from database.", (object)profile.get_ProfileID());
     DiscoveryDatabase.DeleteProfile(profile);
     DiscoveryLogic.log.DebugFormat("Profile {0} removed from database.", (object)profile.get_ProfileID());
 }