public CompressTypesByNamespaceAlg(TypeDependencyGraph inputGraph)
        {
            this.visitedGraph = inputGraph;

            dfs = new DepthFirstSearchAlgorithm(inputGraph);
            dfs.FinishVertex += new VertexEventHandler(dfs_FinishVertex);
            dfs.DiscoverVertex += new VertexEventHandler(dfs_DiscoverVertex);
            dfs.TreeEdge += new EdgeEventHandler(dfs_TreeEdge);
        }
示例#2
0
        public CompressTypesByNamespaceAlg(TypeDependencyGraph inputGraph)
        {
            this.visitedGraph = inputGraph;

            dfs = new DepthFirstSearchAlgorithm(inputGraph);
            dfs.FinishVertex   += new VertexEventHandler(dfs_FinishVertex);
            dfs.DiscoverVertex += new VertexEventHandler(dfs_DiscoverVertex);
            dfs.TreeEdge       += new EdgeEventHandler(dfs_TreeEdge);
        }
示例#3
0
        public void Execute()
        {
            DetermineClassDeps  dcd = new DetermineClassDeps();
            TypeDependencyGraph tdg = new TypeDependencyGraph(false);

            dcd.AssemblyFile      = AssemblyFileName;
            dcd.IgnoreOutsideRefs = false;
            dcd.Execute();
            tdg.LoadClassDependencies(dcd, true);
            this._graph = tdg.CondenseGraph();

            WritePDBasXML pdbxmlWritterTask = new WritePDBasXML();

            pdbxmlWritterTask.AssemblyName = new TaskItem(this.AssemblyFileName);

            if (pdbxmlWritterTask.Execute())
            {
                this._pDBDataFile = pdbxmlWritterTask.PDBAsXmlFile.ItemSpec;
                pdbXPathDoc       = new XPathDocument(PDBDataFile);
                pdbNav            = pdbXPathDoc.CreateNavigator();
            }



            Directory.CreateDirectory(OutputDirectory);
            foreach (CondensedVertex va in Graph.Vertices)
            {
                if (va.ImutableExternalType)
                {
                    continue;
                }
                va.AssemblyName = GetAssemblyName(va);
                if (va.AssemblyName.StartsWith("<"))
                {
                    continue;
                }

                va.AssemblyGUID = Guid.NewGuid();
                va.ProjectFile  = va.AssemblyName + ".csproj"; // );//Path.Combine(OutputDirectory,
            }

            foreach (CondensedVertex vassem in Graph.Vertices)
            {
                CreateProjectFile(vassem);
            }

            CreateSolutionFile();
        }
示例#4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string output;

            dcd.AssemblyFile = @"..\..\..\MBUnitTests\bin\Debug\MBUnitTests.exe";
            dcd.IgnoreOutsideRefs = false;
            dcd.Execute();
            TypeDependencyGraph tdg = new TypeDependencyGraph(false);
            tdg.LoadClassDependencies(dcd, true);
            output = RenderAnalysisGraph(tdg, imageType, "tdg");

            //			output = RenderAnalysisGraph(tdg, imageType, "NamespaceOutboundG");

            ////CondensedTypeGraph cond_CompNS_CondG = tdg.
            //TypeDependencyGraph Analysistdg;
            //Analysistdg = tdg.TypeDepAnalysis(new List<TypeReference>());
            //RenderAnalysisGraph(Analysistdg, imageType, "Analysistdg");
            //return;
            ////output = RenderCondGraph(cond_CompNS_CondG, imageType, "analysistNew");

            //return;
            CondensedTypeGraph condG = tdg.CondenseGraph();
            output = RenderCondGraph(condG, imageType, "condensedGraph");
            condG.CompactNS(true);
            output = RenderCondGraph(condG, imageType, "compactNS");

            foreach (CondensedVertex v in condG.Vertices)
            {
                Debug.WriteLine(v.ContainedTypes.Count.ToString());
            }

            RenderProjectFiles rpf = new RenderProjectFiles();
            //rpf.PDBDataFile = @"..\..\..\MBUnitTests\bin\Debug\MBUnitTests.pdb.xml";
            GeneratePDBXml(rpf);
            rpf.Graph = condG;
            rpf.OutputDirectory = "Projects";
            rpf.NameHint = "mbuTests";
            rpf.Execute();

            //CondensedTypeGraph NScompressed = condG.CompressNamespaces();
            //CondensedTypeGraph NScompressedandCondensed = NScompressed.CondenseGraph();

            //List<TypeReference> analysisList = cond_CompNS_CondG.FindBigestAssembly().ContainedTypes;
            //			Analysistdg =  tdg.TypeDepAnalysis(analysisList);

            //output = RenderAnalysisGraph(tdg, imageType, "analisisRemoved");

            //output = RenderCondGraph(NScompressedandCondensed, imageType, "NS2");
            //output = RenderCondGraph(condG, imageType, "Cond");
            return;

            //CondensedTypeGraph ccc = tdg.CompressGraph();
            //CondensedTypeGraph cccNS = ccc.CompressNamespaces();
            //= cccNS.CompressGraph();

            //Debug.WriteLine(ccc.VerticesCount.ToString());
            //Debug.WriteLine(tdg.VerticesCount.ToString());
            //Debug.WriteLine(ccc.EdgesCount.ToString());

            //pictureBox1.Load(output);

            ////            return;
            //Debug.WriteLine("Render full graph");
            //return;
            //output = RenderFullGraph(tdg, imageType);
            //pictureBox3.Load(output);
        }
示例#5
0
        private string RenderAnalysisGraph(TypeDependencyGraph tdg, GraphvizImageType imageType,string fileName)
        {
            string output;
            GraphvizAlgorithm renderer;
            renderer = new GraphvizAlgorithm(tdg);
            renderer.ImageType = imageType;
            renderer.GraphFormat.RankDirection = GraphvizRankDirection.LR;
            Color[] colors = {
                Color.Beige,
                Color.Cornsilk,
                Color.DimGray,
                Color.Khaki,
                Color.PeachPuff,
                Color.Wheat,
                Color.Olive,
                Color.Moccasin,
                Color.LightCoral,
                Color.LightGoldenrodYellow,
                Color.LightGray,
                Color.LightGreen,
                Color.LightPink,
                Color.LightSalmon,
                Color.LightSeaGreen,
                Color.LightSkyBlue,
                Color.LightSlateGray,
                Color.LightSteelBlue,
                Color.LightYellow,
                Color.Lime,
                Color.MediumAquamarine,
                Color.MediumBlue,
                Color.MediumOrchid,
                Color.MediumPurple,
                Color.MediumSeaGreen,
                Color.MediumSlateBlue,
                Color.MediumSpringGreen,
                Color.MediumTurquoise,
                Color.MediumVioletRed,
                Color.MintCream,

            };
            int nextColorInd = 0;
            Dictionary<int,Color> colormap = new Dictionary<int,Color>();
            FormatVertexEventHandler fvertex = delegate(Object s, FormatVertexEventArgs args)
            {
                TypeVertex v = (TypeVertex)args.Vertex;
                args.VertexFormatter.Label = v.Name;
                args.VertexFormatter.Font = new Font(FontFamily.GenericSerif, 8);
                if (v.SCCNum>=0)
                {
                    Color c;
                    if (!colormap.TryGetValue(v.SCCNum,out c))
                    {
                        if (nextColorInd > colors.GetUpperBound(0)) nextColorInd = 0;
                        c = colors[nextColorInd++];
                        colormap[v.SCCNum] = c;
                    }
                    args.VertexFormatter.FillColor = c;
                    args.VertexFormatter.Style = GraphvizVertexStyle.Filled;
                }
            };

            FormatEdgeEventHandler Fedge = delegate(Object s, FormatEdgeEventArgs args)
                {
                    args.EdgeFormatter.Head = new GraphvizEdgeExtremity(true);
                    args.EdgeFormatter.HeadArrow = new GraphvizArrow(GraphvizArrowShape.Dot);
                };

            renderer.FormatVertex += fvertex;

            renderer.FormatEdge += Fedge;
            output = renderer.Write(fileName);
            return output;
        }
        public TypeDependencyGraph TypeDepAnalysis(List <TypeReference> typesToExamine)
        {
            TypeDependencyGraph tdg = new TypeDependencyGraph();

            StrongComponentsAlgorithm scgo = new StrongComponentsAlgorithm(this);

            scgo.Compute();
            Dictionary <int, List <IVertex> > sccMap = new Dictionary <int, List <IVertex> >();

            foreach (System.Collections.DictionaryEntry de in scgo.Components)
            {
                IVertex v      = (IVertex)de.Key;
                int     scc_id = (int)de.Value;
                if (!sccMap.ContainsKey(scc_id))
                {
                    sccMap[scc_id] = new List <IVertex>();
                }
                sccMap[scc_id].Add(v);
            }

            Stack <List <TypeVertex> > PendingEdges   = new Stack <List <TypeVertex> >();
            List <TypeVertex>          VertexToRemove = new List <TypeVertex>();
            VertexEventHandler         discV          = delegate(Object s, VertexEventArgs e)
            {
                PendingEdges.Push(new List <TypeVertex>());
                TypeVertex tv = (TypeVertex)e.Vertex;
                if (scgo.Components.Contains(tv) && sccMap[scgo.Components[tv]].Count > 1)
                {
                    tv.SCCNum = scgo.Components[tv];
                    tdg.AddVertex(tv);
                }
                else if (typesToExamine.Contains(tv.TypeRef))
                {
                    tdg.AddVertex(tv);
                }
                else
                {
                    VertexToRemove.Add(tv);
                }
            };

            VertexEventHandler finishV = delegate(Object s, VertexEventArgs e)
            {
                TypeVertex        tv  = (TypeVertex)e.Vertex;
                List <TypeVertex> pes = PendingEdges.Pop();
                if (tdg.ContainsVertex(tv))
                {
                    foreach (TypeVertex target in pes)
                    {
                        if (tdg.ContainsVertex(target) && !tdg.ContainsEdge(tv, target))
                        {
                            tdg.AddEdge(tv, target);
                        }
                    }
                }
            };

            EdgeEventHandler treeedge = delegate(Object o, EdgeEventArgs e)
            {
                PendingEdges.Peek().Add((TypeVertex)e.Edge.Target);
            };


            DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(this);

            dfs.DiscoverVertex += discV;
            dfs.FinishVertex   += finishV;
            dfs.TreeEdge       += treeedge;
            dfs.Compute();


            foreach (TypeVertex v in VertexToRemove)
            {
                this.RemoveVertex(v);
            }

            return(tdg);
        }
        public void Execute()
        {
            DetermineClassDeps dcd = new DetermineClassDeps();
            TypeDependencyGraph tdg = new TypeDependencyGraph(false);
            dcd.AssemblyFile = AssemblyFileName;
            dcd.IgnoreOutsideRefs = false;
            dcd.Execute();
            tdg.LoadClassDependencies(dcd, true);
            this._graph = tdg.CondenseGraph();

            WritePDBasXML pdbxmlWritterTask = new WritePDBasXML();
            pdbxmlWritterTask.AssemblyName = new TaskItem(this.AssemblyFileName);

            if (pdbxmlWritterTask.Execute())
            {
                this._pDBDataFile = pdbxmlWritterTask.PDBAsXmlFile.ItemSpec;
                pdbXPathDoc = new XPathDocument(PDBDataFile);
                pdbNav = pdbXPathDoc.CreateNavigator();
            }

            Directory.CreateDirectory(OutputDirectory);
            foreach (CondensedVertex va in Graph.Vertices)
            {
                if (va.ImutableExternalType) continue;
                va.AssemblyName =  GetAssemblyName(va);
                if (va.AssemblyName.StartsWith("<"))
                    continue;

                va.AssemblyGUID = Guid.NewGuid();
                va.ProjectFile = va.AssemblyName + ".csproj"; // );//Path.Combine(OutputDirectory,
            }

            foreach (CondensedVertex vassem in Graph.Vertices)
            {
                CreateProjectFile(vassem);
            }

            CreateSolutionFile();
        }
        public TypeDependencyGraph TypeDepAnalysis(List<TypeReference> typesToExamine)
        {
            TypeDependencyGraph tdg = new TypeDependencyGraph();

            StrongComponentsAlgorithm scgo = new StrongComponentsAlgorithm(this);
            scgo.Compute();
            Dictionary<int, List<IVertex>> sccMap = new Dictionary<int, List<IVertex>>();
            foreach (System.Collections.DictionaryEntry de in scgo.Components)
            {
                IVertex v = (IVertex)de.Key;
                int scc_id = (int)de.Value;
                if (!sccMap.ContainsKey(scc_id))
                {
                    sccMap[scc_id] = new List<IVertex>();
                }
                sccMap[scc_id].Add(v);
            }

            Stack<List<TypeVertex>> PendingEdges = new Stack<List<TypeVertex>>();
            List<TypeVertex> VertexToRemove = new List<TypeVertex>();
            VertexEventHandler discV = delegate(Object s, VertexEventArgs e)
            {
                PendingEdges.Push(new List<TypeVertex>());
                TypeVertex tv = (TypeVertex)e.Vertex;
                if (scgo.Components.Contains(tv) && sccMap[scgo.Components[tv]].Count > 1)
                {
                    tv.SCCNum = scgo.Components[tv];
                    tdg.AddVertex(tv);
                }
                else if (typesToExamine.Contains(tv.TypeRef))
                {
                    tdg.AddVertex(tv);
                }
                else
                {
                    VertexToRemove.Add(tv);
                }
            };

            VertexEventHandler finishV = delegate(Object s, VertexEventArgs e)
            {
                TypeVertex tv = (TypeVertex)e.Vertex;
                List<TypeVertex> pes = PendingEdges.Pop();
                if (tdg.ContainsVertex(tv))
                {
                    foreach (TypeVertex target in pes)
                    {
                        if (tdg.ContainsVertex(target) && !tdg.ContainsEdge(tv, target))
                            tdg.AddEdge(tv, target);
                    }
                }

            };

            EdgeEventHandler treeedge = delegate(Object o, EdgeEventArgs e)
            {
                PendingEdges.Peek().Add((TypeVertex)e.Edge.Target);
            };

            DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(this);
            dfs.DiscoverVertex += discV;
            dfs.FinishVertex += finishV;
            dfs.TreeEdge += treeedge;
            dfs.Compute();

            foreach (TypeVertex v in VertexToRemove)
            {
                this.RemoveVertex(v);
            }

            return tdg;
        }
示例#9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string output;

            dcd.AssemblyFile      = @"..\..\..\MBUnitTests\bin\Debug\MBUnitTests.exe";
            dcd.IgnoreOutsideRefs = false;
            dcd.Execute();
            TypeDependencyGraph tdg = new TypeDependencyGraph(false);

            tdg.LoadClassDependencies(dcd, true);
            output = RenderAnalysisGraph(tdg, imageType, "tdg");

//			output = RenderAnalysisGraph(tdg, imageType, "NamespaceOutboundG");


            ////CondensedTypeGraph cond_CompNS_CondG = tdg.
            //TypeDependencyGraph Analysistdg;
            //Analysistdg = tdg.TypeDepAnalysis(new List<TypeReference>());
            //RenderAnalysisGraph(Analysistdg, imageType, "Analysistdg");
            //return;
            ////output = RenderCondGraph(cond_CompNS_CondG, imageType, "analysistNew");

            //return;
            CondensedTypeGraph condG = tdg.CondenseGraph();

            output = RenderCondGraph(condG, imageType, "condensedGraph");
            condG.CompactNS(true);
            output = RenderCondGraph(condG, imageType, "compactNS");

            foreach (CondensedVertex v in condG.Vertices)
            {
                Debug.WriteLine(v.ContainedTypes.Count.ToString());
            }

            RenderProjectFiles rpf = new RenderProjectFiles();

            //rpf.PDBDataFile = @"..\..\..\MBUnitTests\bin\Debug\MBUnitTests.pdb.xml";
            GeneratePDBXml(rpf);
            rpf.Graph           = condG;
            rpf.OutputDirectory = "Projects";
            rpf.NameHint        = "mbuTests";
            rpf.Execute();



            //CondensedTypeGraph NScompressed = condG.CompressNamespaces();
            //CondensedTypeGraph NScompressedandCondensed = NScompressed.CondenseGraph();


            //List<TypeReference> analysisList = cond_CompNS_CondG.FindBigestAssembly().ContainedTypes;
//			Analysistdg =  tdg.TypeDepAnalysis(analysisList);



            //output = RenderAnalysisGraph(tdg, imageType, "analisisRemoved");


            //output = RenderCondGraph(NScompressedandCondensed, imageType, "NS2");
            //output = RenderCondGraph(condG, imageType, "Cond");
            return;



            //CondensedTypeGraph ccc = tdg.CompressGraph();
            //CondensedTypeGraph cccNS = ccc.CompressNamespaces();
            //= cccNS.CompressGraph();



            //Debug.WriteLine(ccc.VerticesCount.ToString());
            //Debug.WriteLine(tdg.VerticesCount.ToString());
            //Debug.WriteLine(ccc.EdgesCount.ToString());



            //pictureBox1.Load(output);


            ////            return;
            //Debug.WriteLine("Render full graph");
            //return;
            //output = RenderFullGraph(tdg, imageType);
            //pictureBox3.Load(output);
        }
示例#10
0
        private string RenderAnalysisGraph(TypeDependencyGraph tdg, GraphvizImageType imageType, string fileName)
        {
            string            output;
            GraphvizAlgorithm renderer;

            renderer           = new GraphvizAlgorithm(tdg);
            renderer.ImageType = imageType;
            renderer.GraphFormat.RankDirection = GraphvizRankDirection.LR;
            Color[] colors =
            {
                Color.Beige,
                Color.Cornsilk,
                Color.DimGray,
                Color.Khaki,
                Color.PeachPuff,
                Color.Wheat,
                Color.Olive,
                Color.Moccasin,
                Color.LightCoral,
                Color.LightGoldenrodYellow,
                Color.LightGray,
                Color.LightGreen,
                Color.LightPink,
                Color.LightSalmon,
                Color.LightSeaGreen,
                Color.LightSkyBlue,
                Color.LightSlateGray,
                Color.LightSteelBlue,
                Color.LightYellow,
                Color.Lime,
                Color.MediumAquamarine,
                Color.MediumBlue,
                Color.MediumOrchid,
                Color.MediumPurple,
                Color.MediumSeaGreen,
                Color.MediumSlateBlue,
                Color.MediumSpringGreen,
                Color.MediumTurquoise,
                Color.MediumVioletRed,
                Color.MintCream,
            };
            int nextColorInd = 0;
            Dictionary <int, Color>  colormap = new Dictionary <int, Color>();
            FormatVertexEventHandler fvertex  = delegate(Object s, FormatVertexEventArgs args)
            {
                TypeVertex v = (TypeVertex)args.Vertex;
                args.VertexFormatter.Label = v.Name;
                args.VertexFormatter.Font  = new Font(FontFamily.GenericSerif, 8);
                if (v.SCCNum >= 0)
                {
                    Color c;
                    if (!colormap.TryGetValue(v.SCCNum, out c))
                    {
                        if (nextColorInd > colors.GetUpperBound(0))
                        {
                            nextColorInd = 0;
                        }
                        c = colors[nextColorInd++];
                        colormap[v.SCCNum] = c;
                    }
                    args.VertexFormatter.FillColor = c;
                    args.VertexFormatter.Style     = GraphvizVertexStyle.Filled;
                }
            };

            FormatEdgeEventHandler Fedge = delegate(Object s, FormatEdgeEventArgs args)
            {
                args.EdgeFormatter.Head      = new GraphvizEdgeExtremity(true);
                args.EdgeFormatter.HeadArrow = new GraphvizArrow(GraphvizArrowShape.Dot);
            };

            renderer.FormatVertex += fvertex;

            renderer.FormatEdge += Fedge;
            output = renderer.Write(fileName);
            return(output);
        }