AsmSpy.ConsoleVisualizer.Visualize C# (CSharp) Метод

Visualize() публичный Метод

public Visualize ( ) : void
Результат void
        public void Visualize()
        {
            if (_AnalyzerResult.AnalyzedFiles.Length <= 0)
            {
                Console.WriteLine("No assemblies files found in directory");
                return;
            }

            if (OnlyConflicts)
            {
                Console.WriteLine("Detailing only conflicting assembly references.");
            }

            var assemblyGroups = _AnalyzerResult.Assemblies.Values.GroupBy(x => x.AssemblyName.Name);

            foreach (var assemblyGroup in assemblyGroups.OrderBy(i => i.Key))
            {
                if (SkipSystem && (assemblyGroup.Key.StartsWith("System") || assemblyGroup.Key.StartsWith("mscorlib"))) continue;

                var assemblyInfos = assemblyGroup.OrderBy(x => x.AssemblyName.ToString()).ToList();
                if (OnlyConflicts && assemblyInfos.Count <= 1) continue;

                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Reference: ");

                ConsoleColor mainNameColor;
                if (assemblyInfos.Any(x => x.AssemblySource == AssemblySource.Unknown))
                {
                    mainNameColor = AssemblyUnknownColor;
                }
                else if (assemblyInfos.Any(x => x.AssemblySource == AssemblySource.NotFound))
                {
                    mainNameColor = AssemblyNotFoundColor;
                }
                else if (assemblyInfos.Any(x => x.AssemblySource == AssemblySource.GAC))
                {
                    mainNameColor = AssemblyGACColor;
                }
                else
                {
                    mainNameColor = AssemblyLocalColor;
                }

                Console.ForegroundColor = mainNameColor;
                Console.WriteLine("{0}", assemblyGroup.Key);

                for (var i = 0; i < assemblyInfos.Count; i++)
                {
                    var assemblyInfo = assemblyInfos[i];

                    ConsoleColor statusColor;
                    switch (assemblyInfo.AssemblySource)
                    {
                        case AssemblySource.NotFound:
                            statusColor = AssemblyNotFoundColor;
                            break;
                        case AssemblySource.Local:
                            statusColor = AssemblyLocalColor;
                            break;
                        case AssemblySource.GAC:
                            statusColor = AssemblyGACColor;
                            break;
                        case AssemblySource.Unknown:
                            statusColor = AssemblyUnknownColor;
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    Console.ForegroundColor = statusColor;
                    Console.WriteLine("  {0}", assemblyInfo.AssemblyName);
                    Console.Write("  Source: {0}", assemblyInfo.AssemblySource);
                    if (assemblyInfo.AssemblySource != AssemblySource.NotFound)
                    {
                        Console.WriteLine(", Location: {0}", assemblyInfo.ReflectionOnlyAssembly.Location);
                    }
                    else
                    {
                        Console.WriteLine();
                    }

                    foreach (var referer in assemblyInfo.ReferencedBy.OrderBy(x => x.AssemblyName.ToString()))
                    {
                        Console.ForegroundColor = statusColor;
                        Console.Write("    {0}", assemblyInfo.AssemblyName.Version);

                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write(" by ");

                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.WriteLine("{0}", referer.AssemblyName);
                    }
                }

                Console.WriteLine();
            }
            Console.ResetColor();
        }

Usage Example

Пример #1
0
        static void Main(string[] args)
        {
            CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);
            CommandArgument directory = commandLineApplication.Argument("directory", "The directory to search for assemblies");
            CommandOption dgmlExport = commandLineApplication.Option("-dg|--dgml <filename>", "Export to a dgml file", CommandOptionType.SingleValue);
            CommandOption nonsystem = commandLineApplication.Option("-n|--nonsystem", "List system assemblies", CommandOptionType.NoValue);
            CommandOption all = commandLineApplication.Option("-a|--all", "List all assemblies and references.", CommandOptionType.NoValue);
            CommandOption noconsole = commandLineApplication.Option("-nc|--noconsole", "Do not show references on console.", CommandOptionType.NoValue);
            CommandOption silent = commandLineApplication.Option("-s|--silent", "Do not show any message, only warnings and errors will be shown.", CommandOptionType.NoValue);

            commandLineApplication.HelpOption("-? | -h | --help");
            commandLineApplication.OnExecute(() =>
            {
                var consoleLogger = new ConsoleLogger(!silent.HasValue());

                var directoryPath = directory.Value;
                if (!Directory.Exists(directoryPath))
                {
                    consoleLogger.LogMessage(string.Format("Directory: '{0}' does not exist.", directoryPath));
                    return -1;
                }

                var onlyConflicts = !all.HasValue();
                var skipSystem = nonsystem.HasValue();

                IDependencyAnalyzer analyzer = new DependencyAnalyzer() { DirectoryInfo = new DirectoryInfo(directoryPath) };

                consoleLogger.LogMessage(string.Format("Check assemblies in: {0}", analyzer.DirectoryInfo));

                var result = analyzer.Analyze(consoleLogger);

                if (!noconsole.HasValue())
                {
                    IDependencyVisualizer visualizer = new ConsoleVisualizer(result) { SkipSystem = skipSystem, OnlyConflicts = onlyConflicts };
                    visualizer.Visualize();
                }

                if (dgmlExport.HasValue())
                {
                    IDependencyVisualizer export = new DgmlExport(result, string.IsNullOrWhiteSpace(dgmlExport.Value()) ? Path.Combine(analyzer.DirectoryInfo.FullName, "references.dgml") : dgmlExport.Value(), consoleLogger);
                    export.Visualize();
                }

                return 0;
            });
            try
            {
                if (args == null || args.Length == 0)
                    commandLineApplication.ShowHelp();
                else
                    commandLineApplication.Execute(args);
            }
            catch (CommandParsingException cpe)
            {
                Console.WriteLine(cpe.Message);
                commandLineApplication.ShowHelp();
            }
        }
All Usage Examples Of AsmSpy.ConsoleVisualizer::Visualize