private void WriteAsXmlToConsole(DiscoveryResult result) { var serializer = new XmlSerializer(typeof(DiscoveryResult)); using var writeStream = Console.Out; serializer.Serialize(writeStream, result); }
public static string ToString(DiscoveryResult discoveryResult) { using var stringWriter = new StringWriter(); using var writer = new IndentedTextWriter(stringWriter); writer.WriteLine("digraph dependencies {"); writer.Indent++; foreach (var project in discoveryResult.Projects) { writer.WriteLine($"\"{project.Id}\" [label=\"{project.Name}\", fillcolor=\"{ProjectBackgroundColor}\", style=filled];"); } foreach (var package in discoveryResult.Packages) { writer.WriteLine($"\"{package.Id}\" [label=\"{package.Name}\", fillcolor=\"{PackageBackgroundColor}\", style=filled];"); } foreach (var reference in discoveryResult.References) { writer.WriteLine($"\"{reference.From}\" -> \"{reference.To}\";"); } writer.Indent--; writer.WriteLine("}"); writer.Flush(); return(stringWriter.ToString()); }
public DiscoveryResult Discover() { var result = new DiscoveryResult { Packages = new List <Package>(), Projects = new List <Project>(), References = new List <Reference>() }; _includeProjectNamespaces = ParseStringToLowercaseStringArray(IncludeProjectNamespaces); _excludeProjectNamespaces = ParseStringToLowercaseStringArray(ExcludeProjectNamespaces); _includePackageNamespaces = ParseStringToLowercaseStringArray(IncludePackageNamespaces); _excludePackageNamespaces = ParseStringToLowercaseStringArray(ExcludePackageNamespaces); if (!_includeProjectNamespaces.Any()) { _includeProjectNamespaces = new[] { "" } } ; if (!_includePackageNamespaces.Any()) { _includePackageNamespaces = new[] { "" } } ; _shouldIncludePackages = IncludePackages || !string.IsNullOrWhiteSpace(IncludePackageNamespaces) || !string.IsNullOrWhiteSpace(ExcludePackageNamespaces); Discover(SourceFolder, result); return(result); }
private void WriteAsXmlToFile(DiscoveryResult result, string outputPath) { var serializer = new XmlSerializer(typeof(DiscoveryResult)); using var writeStream = File.OpenWrite(outputPath); serializer.Serialize(writeStream, result); Console.WriteLine($"XML output written to {outputPath}"); }
private void WriteAsHtmlToFile(DiscoveryResult result, string outputPath, string title) { var templatePath = Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName, HtmlTemplateName); var template = File.ReadAllText(templatePath); var html = template .Replace(HtmlTemplateToken, JsonConvert.SerializeObject(result, Formatting.Indented)) .Replace(HtmlTitleToken, WebUtility.HtmlEncode(title)); File.WriteAllText(outputPath, html); Console.WriteLine($"HTML output written to {outputPath}"); }
internal void Write(DiscoveryResult result, OutputTypes type, string outputPath, string htmlTitle) { switch (type) { case OutputTypes.Html: case OutputTypes.Xml: case OutputTypes.Json: case OutputTypes.Graphviz: if (string.IsNullOrWhiteSpace(outputPath)) { Console.Error.WriteLine($"output type {type} require specifying {nameof(outputPath)}"); return; } break; } switch (type) { case OutputTypes.Html: WriteAsHtmlToFile(result, outputPath, htmlTitle); break; case OutputTypes.Xml: WriteAsXmlToFile(result, outputPath); break; case OutputTypes.Json: WriteAsJsonToFile(result, outputPath); break; case OutputTypes.Graphviz: WriteAsGraphvizToFile(result, outputPath); break; case OutputTypes.ConsoleJson: WriteAsJsonToConsole(result); break; case OutputTypes.ConsoleXml: WriteAsXmlToConsole(result); break; case OutputTypes.ConsoleGraphviz: WriteAsGraphvizToConsole(result); break; default: throw new Exception($"Unknown {nameof(type)} '{type}'"); } }
private void WriteAsJsonToFile(DiscoveryResult result, string outputPath) { File.WriteAllText(outputPath, JsonConvert.SerializeObject(result, Formatting.Indented)); Console.WriteLine($"JSON output written to {outputPath}"); }
private static void WriteAsGraphvizToFile(DiscoveryResult result, string outputPath) { File.WriteAllText(outputPath, GraphvizSerializer.ToString(result)); Console.WriteLine($"GraphViz output written to {outputPath}"); }
private static void WriteAsGraphvizToConsole(DiscoveryResult result) => Console.WriteLine(GraphvizSerializer.ToString(result));
private void WriteAsJsonToConsole(DiscoveryResult result) => Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
private void Discover(string folder, DiscoveryResult result) { var projectFiles = Directory.EnumerateFiles(folder, "*.csproj") .Concat(Directory.EnumerateFiles(folder, "*.vbproj")); foreach (var file in projectFiles) { var id = file.Replace(SourceFolder, ""); var name = Path.GetFileNameWithoutExtension(file); if (!_includeProjectNamespaces.Any(i => name.ToLower().StartsWith(i))) { continue; } if (_excludeProjectNamespaces.Any(i => name.ToLower().StartsWith(i))) { continue; } // add this project. if (!result.Projects.Any(p => p.Id == id)) { result.Projects.Add(new Project { Id = id, Name = name }); } var(projects, packages) = DiscoverFileReferences(file); projects = projects .Where(p => _includeProjectNamespaces.Any(i => p.Name.ToLower().StartsWith(i)) && !_excludeProjectNamespaces.Any(i => p.Name.ToLower().StartsWith(i))) .ToList(); foreach (var project in projects) { if (!result.Projects.Any(p => p.Id == project.Id)) { result.Projects.Add(project); } result.References.Add(new Reference { From = id, To = project.Id }); } if (!_shouldIncludePackages) { continue; } packages = packages.Where(p => { return(_includePackageNamespaces.Any(i => p.Name.ToLower().StartsWith(i)) && !_excludePackageNamespaces.Any(i => p.Name.ToLower().StartsWith(i))); }).ToList(); foreach (var package in packages) { if (!result.Packages.Any(p => p.Id == package.Id)) { result.Packages.Add(package); } result.References.Add(new Reference { From = id, To = package.Id }); } } var directories = Directory.EnumerateDirectories(folder); foreach (var directory in directories) { Discover(directory, result); } }