private void ProcessAssembly(TypeRelationshipDocument document, InheritanceAnalyzer builder, string assemblyFile)
        {
            try
            {
                var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyFile);
                if (assembly.GetName().ToString() == mySelectedAssemblyName ||
                    assembly.GetReferencedAssemblies().Any(r => r.ToString() == mySelectedAssemblyName))
                {
                    builder.Process(assembly);
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("Failed to load assembly");

                foreach (var loaderEx in ex.LoaderExceptions)
                {
                    sb.Append("  LoaderException (");
                    sb.Append(loaderEx.GetType().Name);
                    sb.Append(") ");
                    sb.AppendLine(loaderEx.Message);
                }

                document.FailedItems.Add(new FailedItem(assemblyFile, sb.ToString().Trim()));
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.Append("Failed to load assembly: ");
                sb.Append(ex.Message);

                document.FailedItems.Add(new FailedItem(assemblyFile, sb.ToString()));
            }
        }
示例#2
0
        internal void WriteTo(string forTypeId, TypeRelationshipDocument document)
        {
            var visitedTypes = new HashSet <TypeDescriptor>();

            TakeSiblingsOf(document, visitedTypes, myIdToTypeMap[forTypeId]);

            foreach (var edge in document.Graph.Edges)
            {
                document.EdgeTypes.Add(edge.Id, myEdgeTypes[edge.Id]);
            }
        }
        public TypeRelationshipDocument Execute()
        {
            Contract.RequiresNotNullNotEmpty(AssemblyLocation, "AssemblyLocation");
            Contract.RequiresNotNull(SelectedType, "SelectedType");

            var assemblyHome = Path.GetDirectoryName(AssemblyLocation);

            mySelectedAssemblyName = AssemblyName.GetAssemblyName(AssemblyLocation).ToString();

            ReportProgress(1);

            var assemblies = Directory.EnumerateFiles(assemblyHome, "*.dll")
                             .Concat(Directory.EnumerateFiles(assemblyHome, "*.exe"))
                             .AsParallel()
                             .Where(file => File.Exists(file))
                             .Where(file => AssemblyUtils.IsManagedAssembly(file))
                             .ToArray();

            double progressCounter = assemblies.Length;

            ReportProgress((int)((assemblies.Length - progressCounter) / assemblies.Length * 100));

            if (IsCancellationRequested)
            {
                return(null);
            }

            var document = new TypeRelationshipDocument();

            var builder = new InheritanceAnalyzer();

            builder.IgnoreDotNetTypes = IgnoreDotNetTypes;

            foreach (var assemblyFile in assemblies)
            {
                ProcessAssembly(document, builder, assemblyFile);

                progressCounter--;

                ReportProgress((int)((assemblies.Length - progressCounter) / assemblies.Length * 100));

                if (IsCancellationRequested)
                {
                    return(null);
                }
            }

            builder.WriteTo(SelectedType.Id, document);

            return(document);
        }
示例#4
0
        private void TakeSiblingsOf(TypeRelationshipDocument document, HashSet <TypeDescriptor> visitedTypes, params TypeDescriptor[] roots)
        {
            if (!roots.Any())
            {
                return;
            }

            var typesToFollow = new HashSet <TypeDescriptor>();

            foreach (var root in roots)
            {
                visitedTypes.Add(root);

                var node = myBuilder.Graph.FindNode(root.Id);

                document.AddNode(root);

                foreach (var edge in node.In)
                {
                    var source = myIdToTypeMap[edge.Source.Id];
                    document.AddEdge(source, root);
                    typesToFollow.Add(source);
                }

                // TODO: down only - otherwise we need a "MaxDepth"
                //foreach( var edge in node.Out )
                //{
                //    var target = myIdToTypeMap[ edge.Target.Id ];
                //    document.AddEdge( root, target );
                //    typesToFollow.Add( target );
                //}
            }

            typesToFollow.ExceptWith(visitedTypes);

            TakeSiblingsOf(document, visitedTypes, typesToFollow.ToArray());
        }