public string GetElements(int mode, int tolerance, bool showAboveOnly) { List <string> linesCsproj = File.ReadAllLines("C:\\Logs\\Identifiers.txt").ToList(); StringBuilder sb = new StringBuilder(); string lastMethod = ""; int lines = 0; if (mode == 0) { sb.Append(" subgraph cluster_Default { "); sb.Append(" style=filled; "); sb.Append(" color=white; "); sb.Append(" node [style=filled,color=yellow]; "); } if (mode == 1) { sb.Append(" subgraph cluster_Default { "); sb.Append(" style=filled; "); sb.Append(" color=lightgrey; "); sb.Append(" node [style=filled,color=yellow]; "); } List <HitRelationInfo> hitInfos = new List <HitRelationInfo>(); MethodHitInfo lastHittedInfo = null; PrepareIdentifiers(); if (mode == 0) { foreach (XNamespace myNamespace in namespaces) { sb.Append(" subgraph cluster_N" + namespaces.IndexOf(myNamespace) + " { "); sb.Append(" style=filled; "); sb.Append(" color=lightgray; "); sb.Append(" node [style=filled,color=yellow]; "); sb.Append(" label = \"" + myNamespace.Name + "\"; "); foreach (XClass myClass in myNamespace.Classes) { sb.Append(" subgraph cluster_N" + namespaces.IndexOf(myNamespace) + "C" + myNamespace.Classes.IndexOf(myClass) + " { "); sb.Append(" style=filled; "); sb.Append(" color=turquoise1; "); sb.Append(" node [style=filled,color=yellow]; "); sb.Append(" label = \"Default\"; "); sb.Append(" label = \"" + myClass.Name + "\"; "); foreach (XRef myFile in myClass.Files) { foreach (XMethod myMethod in myFile.Methods) { sb.AppendLine("\t " + myMethod.ID + "[color=yellow; label=\"" + myMethod.Name + "\"];"); } } sb.Append(" } "); } sb.Append(" } "); } } /* * if (lastHittedInfo != null) * { * HitRelationInfo currentInfo = hitInfos.Where(p => p.Hitted1.Number == lastHittedInfo.Number && p.Hitted2.Number == tn.Number).FirstOrDefault(); * if (currentInfo == null) * { * currentInfo = new HitRelationInfo(); * currentInfo.Hitted1 = lastHittedInfo; * currentInfo.Hitted2 = tn; * currentInfo.Times = 1; * hitInfos.Add(currentInfo); * } * else * { * currentInfo.Times++; * if (mode != 0) * { * if (!showAboveOnly) * { * if (tolerance < 0 || currentInfo.Times <= tolerance) * { * sb.AppendLine("\t " + currentInfo.Hitted1.Number + "[color=" + (currentInfo.Hitted1.Component == 0 ? "greenyellow" : "yellow") + "; label=\"" + currentInfo.Hitted1.Method + "\"];"); * sb.AppendLine("\t " + currentInfo.Hitted2.Number + "[color=" + (currentInfo.Hitted1.Component == 0 ? "greenyellow" : "yellow") + "; label=\"" + * currentInfo.Hitted2.Method + "\"];"); * sb.AppendLine("\t " + currentInfo.Hitted1.Number + " -> " + * currentInfo.Hitted2.Number + * ";"); * } * } * } * } * } * lastHittedInfo = tn; * * if (lines > 10000) * { * //break; * } * } * bool isFirstHit = true; * * foreach (HitRelationInfo currentInfo in hitInfos) * { * if (mode == 0 || (showAboveOnly && currentInfo.Times >= tolerance)) * { * if (isFirstHit) * { * sb.AppendLine("\t " + currentInfo.Hitted1.Number + "[color=" + (currentInfo.Hitted1.Component == 0 ? "greenyellow" : "yellow") + "; label=\"" + * currentInfo.Hitted1.Method + "\"];"); * isFirstHit = false; * } * sb.AppendLine("\t " + currentInfo.Hitted2.Number + "[color=" + (currentInfo.Hitted2.Component == 0 ? "greenyellow" : "yellow") + "; label=\"" + currentInfo.Hitted2.Method + "\"];"); * sb.AppendLine("\t " + currentInfo.Hitted1.Number + " -> " + currentInfo.Hitted2.Number + * "[ label=\"" + * currentInfo.Times + "\" ];"); * } * }*/ sb.Append(" label = \"Default\"; "); sb.Append(" } "); /* * StringBuilder statistics = new StringBuilder(); * hitInfos = hitInfos.OrderBy(o => o.Times).ToList(); * foreach (HitRelationInfo currentInfo in hitInfos) * { * statistics.AppendLine("" + currentInfo.Times + "x " + currentInfo.Hitted1.Class + "." + currentInfo.Hitted1.Method + " -> " + currentInfo.Hitted1.Class + "." + currentInfo.Hitted1.Method + ""); * } * Statistics = statistics.ToString(); */ return(sb.ToString()); }
public static List <XNamespace> GetNamespaces() { CallSequence = new List <CallElement>(); XMethod lastMethod = null; List <string> linesCsproj = File.ReadAllLines(@"C:\Logs\Identifiers.txt").ToList(); StringBuilder sb = new StringBuilder(); int lines = 0; List <HitRelationInfo> hitInfos = new List <HitRelationInfo>(); List <XNamespace> namespaces = new List <XNamespace>(); MethodHitInfo lastHittedInfo = null; foreach (string line in linesCsproj) { if (line.Length < 10) { continue; } string pLine = line; lines++; MethodHitInfo tn = new MethodHitInfo(); if (pLine.Substring(25, 6).Equals("silver")) { tn.Component = 1; } else { tn.Component = 0; } tn.Namespace = pLine.Substring(0, pLine.IndexOf("</span>")); tn.Namespace = tn.Namespace.Substring(tn.Namespace.LastIndexOf(">") + 1); XNamespace currentNamespace = namespaces.Where(p => p.Name.Equals(tn.Namespace)).FirstOrDefault(); if (currentNamespace == null) { currentNamespace = new XNamespace(tn.Namespace); namespaces.Add(currentNamespace); } pLine = pLine.Substring(pLine.IndexOf("</span>") + 7); tn.Class = pLine.Substring(0, pLine.IndexOf("</span>")); tn.Class = tn.Class.Substring(tn.Class.LastIndexOf(">") + 1); XClass currentClass = currentNamespace.Classes.Where(p => p.Name.Equals(tn.Class)).FirstOrDefault(); if (currentClass == null) { currentClass = new XClass(tn.Class); currentNamespace.Classes.Add(currentClass); } pLine = pLine.Substring(pLine.IndexOf("</span>") + 7); tn.Method = pLine.Substring(0, pLine.IndexOf("</b>")); tn.Method = tn.Method.Substring(tn.Method.LastIndexOf(">") + 1); if (tn.Method.Equals(".ctor")) { tn.Method = tn.Class + "()"; } //if (MainForm.Exclusions.Contains(tn.Method)) { //continue; } XMethod currentMethod = currentClass.Methods.Where(p => p.Name.Equals(tn.Method)).FirstOrDefault(); if (currentMethod == null) { currentMethod = new XMethod(tn.Method); currentMethod.Parent = currentClass; currentMethod.Calls = new List <XMethod>(); currentClass.Methods.Add(currentMethod); } if (lastMethod != null) { lastMethod.Calls.Add(currentMethod); //if (XMethod.CallSequence.Count<50) { CallSequence.Add(new CallElement(lastMethod, currentMethod)); } } lastMethod = currentMethod; pLine = pLine.Substring(pLine.IndexOf("</span>") + 7); string milisecondsString = ""; int miliseconds = 0; milisecondsString = pLine.Substring(0, pLine.IndexOf("</span>")); milisecondsString = milisecondsString.Substring(milisecondsString.LastIndexOf(">") + 1); if (int.TryParse(milisecondsString, out miliseconds)) { tn.Time = tn.Time += miliseconds; // no error reported. This method might be not accurate } pLine = pLine.Substring(pLine.IndexOf("</span>") + 7); tn.Number = pLine.Substring(0, pLine.IndexOf("</span>")); tn.Number = tn.Number.Substring(tn.Number.LastIndexOf(">") + 1); int Nr = 0; int.TryParse(tn.Number, out Nr); currentMethod.ID = Nr; } return(namespaces); }