//--------------------<Add dependecy based on the type retrieved>--------------- public void AddDep(string type, ref CsNode <string, string> currentNode) { if (type == "Constructor") { return; } if (!typeTable.Contains(type)) { return; } if (typeTable[type].Count == 1) { CsNode <string, string> child = new CsNode <string, string>(typeTable[type][0].file); child.nodeValue = child.name; if (child.name != currentNode.name && !currentNode.ContainsChild(child.name)) { StringBuilder edge = new StringBuilder(); edge.Append(currentNode.name).Append(" - ").Append(child.name); currentNode.addChild(child, edge.ToString()); Console.WriteLine("{0} added child {1}", currentNode.name, child.name); } } else { foreach (TypeInfo ti in typeTable[type]) { if (nameSpace[type].Contains(ti.nameSpace)) { CsNode <string, string> child = new CsNode <string, string>(typeTable[type][0].file); child.nodeValue = child.name; if (child.name != currentNode.name && !currentNode.ContainsChild(child.name)) { StringBuilder edge = new StringBuilder(); edge.Append(currentNode.name).Append(" - ").Append(child.name); currentNode.addChild(child, edge.ToString()); Console.WriteLine("{0} added child {1}", currentNode.name, child.name); } } } } }
//----< build dependency graph from dependency table >----------- public CsGraph <string, string> buildDependencyGraph() { Repository repo = Repository.getInstance(); CsGraph <string, string> graph = new CsGraph <string, string>("deps"); foreach (var item in repo.dependencyTable.dependencies) { string fileName = item.Key; fileName = System.IO.Path.GetFileName(fileName); CsNode <string, string> node = new CsNode <string, string>(fileName); graph.addNode(node); } DependencyTable dt = new DependencyTable(); foreach (var item in repo.dependencyTable.dependencies) { string fileName = item.Key; fileName = System.IO.Path.GetFileName(fileName); if (!dt.dependencies.ContainsKey(fileName)) { List <string> deps = new List <string>(); dt.dependencies.Add(fileName, deps); } foreach (var elem in item.Value) { string childFile = elem; childFile = System.IO.Path.GetFileName(childFile); dt.dependencies[fileName].Add(childFile); } } foreach (var item in graph.adjList) { CsNode <string, string> node = item; List <string> children = dt.dependencies[node.name]; foreach (var child in children) { int index = graph.findNodeByName(child); if (index != -1) { CsNode <string, string> dep = graph.adjList[index]; node.addChild(dep, "edge"); } } } return(graph); }