public void TestMethods() { string assemblyFolder = "temp"; string[] systemAssemblies = Utility.GetSystemAssemblies(); //string[] systemAssemblies = new string[] { @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.EnterpriseServices.dll" }; Utility.CreateAssemblyFolder(assemblyFolder, systemAssemblies); foreach (string assemblyPath in systemAssemblies) { string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath); string query = string.Format("SELECT METHODS FROM ASSEMBLIES \"{0}\" ORDER BY NbMethods", assemblyName); NDependProject project = new NDependProject("MethodProject", assemblyFolder, null); NDependResults result = project.AnalyzeQuery(null, query); CodeAnalysis analysis = new CodeAnalysis(new string[] { assemblyPath }); Console.WriteLine("{0} ( {1} , {2} )", assemblyName, result.Count, analysis.Methods.Count); //Assert.True(result.Count <= analysis.Methods.Count); } }
public NDependResults[] AnalyzeQueries(NDependProject compareToProject, string[] queries) { string filePath = _createProjectXml(compareToProject, queries); string args = string.Format("\"{0}\" /Silent", filePath); _executeProcess(NDEPEND_APPLICATION_PATH, args); if (queries != null) { NDependResults[] results = new NDependResults[queries.Length]; string cqlResults = Path.Combine(_assemblyPath, Path.Combine(_projectName, "CQLResult.xml")); XElement root = XElement.Load(cqlResults); for (int i = 0; i < results.Length; i++) { results[i] = _parseQueryResults(root, "Query" + i); } return results; } return null; }
private string _createProjectXml(NDependProject compareToProject, string[] queries) { XElement root = new XElement("NDepend", new XAttribute("AppName", _projectName)); XElement output = new XElement("OutputDir", new XAttribute("KeepHistoric", false)); output.Add(Path.Combine(_assemblyPath, _projectName)); root.Add(output); XElement dirs = new XElement("Dirs", new XElement("Dir", _assemblyPath)); root.Add(dirs); if (_assemblies != null) { XElement assemblies = new XElement("Assemblies"); foreach (string assembly in _assemblies) { string assemblyName = Path.GetFileNameWithoutExtension(assembly); assemblies.Add(new XElement("Name", assemblyName)); } root.Add(assemblies); } if (_frameworkAssemblies != null) { XElement frameworkAssemblies = new XElement("FrameworkAssemblies"); foreach (string frameworkAssembly in _frameworkAssemblies) { string assemblyName = Path.GetFileNameWithoutExtension(frameworkAssembly); frameworkAssemblies.Add(new XElement("Name", assemblyName)); string assemblyDir = Path.GetDirectoryName(Path.GetFullPath(frameworkAssembly)); dirs.Add(new XElement("Dir", assemblyDir)); } root.Add(frameworkAssemblies); } if (compareToProject != null) { string comparePath = Path.Combine(compareToProject._assemblyPath, compareToProject._projectName); XElement compare = new XElement("BuildComparisonSetting"); compare.Add(new XAttribute("ProjectMode", "AnotherProject")); compare.Add(new XAttribute("BuildMode", "BuildMadeNDaysAgo")); compare.Add(new XAttribute("NDaysAgo", "1")); compare.Add(new XAttribute("ProjectFileToCompareWith", comparePath + ".xml")); compare.Add(new XAttribute("BuildFileToCompareWith", Path.Combine(comparePath, "VisualNDepend.bin"))); root.Add(compare); } if (queries != null) { XElement cql = new XElement("CQLQueries"); for (int i = 0; i < queries.Length; i++) { XElement group = new XElement("CQLGroup"); XAttribute active = new XAttribute("Active", true); group.Add(active, new XAttribute("Name", "Query" + i)); XElement query = new XElement("CQLQuery"); query.Add(active, new XAttribute("DisplayList", true)); query.Add("WARN IF Count > 0 IN " + queries[i]); group.Add(query); cql.Add(group); } root.Add(cql); } string filePath = Path.Combine(_assemblyPath, _projectName + ".xml"); root.Save(filePath); return filePath; }
public NDependResults AnalyzeQuery(NDependProject compareToProject, string query) { string[] queries = (query == null ? null : new string[] { query }); NDependResults[] results = AnalyzeQueries(compareToProject, queries); return (results == null ? null : results[0]); }