Beispiel #1
0
        void Process()
        {
            GraphSchema assemblySchema = new GraphSchema("ildependsSchema");
            UnresolvedCategory = assemblySchema.Categories.AddNewCategory("Unresolved");
            AssemblyCategory = assemblySchema.Categories.AddNewCategory("CodeSchema_Assembly");

            string windir = Environment.GetEnvironmentVariable("WINDIR");
            _paths.Add(windir + @"\Microsoft.NET\Framework\v4.0.30319");

            _host = new ConsoleHostEnvironment(_paths.ToArray(), true);

            Graph graph = new Graph();
            graph.AddSchema(assemblySchema);

            GraphConditionalStyle errorStyle = new GraphConditionalStyle(graph);
            GraphCondition condition = new GraphCondition(errorStyle);
            condition.Expression = "HasCategory('Unresolved')";
            GraphSetter setter = new GraphSetter(errorStyle, "Icon");
            setter.Value = "pack://application:,,,/Microsoft.VisualStudio.Progression.GraphControl;component/Icons/kpi_red_sym2_large.png";
            graph.Styles.Add(errorStyle);

            foreach (var dir in _directories)
            {
                foreach (var target in Directory.GetFiles(dir, "*.dll", SearchOption.AllDirectories))
                {
                    _files.Add(Path.GetFileName(target), target);
                }
            }

            foreach (String fileName in this._files.Values)
            {
                String fullPath = Path.GetFullPath(fileName);
                try
                {
                    Console.WriteLine("Processing: " + fullPath);
                    IAssembly assembly = _host.LoadUnitFrom(fileName) as IAssembly;
                    GraphNode root = graph.Nodes.GetOrCreate(GetNodeID(assembly.AssemblyIdentity), assembly.AssemblyIdentity.Name.Value, AssemblyCategory);
                    WalkDependencies(graph, root, assembly, new HashSet<IAssembly>());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("#Error: " + ex.Message);
                }
            }

            graph.Save(output);
        }