Exemplo n.º 1
0
        public async Task Run(ReferencesOptions no)
        {
            if (string.IsNullOrWhiteSpace(no.RootPath))
            {
                no.RootPath = Directory.GetCurrentDirectory();
            }
            if (!Directory.Exists(no.RootPath))
            {
                ConsoleEx.WriteErrorLine($"Path {no.RootPath} not exists");
                return;
            }

            var sm      = new SolutionManager(null);
            var results = sm.FindAllReferences(no.RootPath, no.SourceProject, no.ClassName);

            if (no.IsTableView)
            {
                var result = await results.ToListAsync();

                var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);
                var doc             = new Document(new Span(no.ClassName)
                {
                    Color = Yellow
                }, "\n",
                                                   new Grid
                {
                    Color    = Gray,
                    Columns  = { GridLength.Star(1), GridLength.Auto, GridLength.Auto, GridLength.Auto, GridLength.Auto, GridLength.Auto },
                    Children =
                    {
                        new Cell("Project")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("File")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Block")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Namespace")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Class")
                        {
                            Stroke = headerThickness
                        },
                        new Cell("Line")
                        {
                            Stroke = headerThickness
                        },
                        result.Select(item => new[]
                        {
                            new Cell(item.ProjectName),
                            new Cell(item.FileName),
                            new Cell(item.Block),
                            new Cell(item.Namespace),
                            new Cell(item.ClassName),
                            new Cell(item.LineNumber),
                        })
                    }
                }
                                                   );

                ConsoleRenderer.RenderDocument(doc);
            }
            else
            {
                await foreach (var r in results)
                {
                    ConsoleEx.WriteOKLine($"{r.ProjectName} [{r.FileName}->{r.Namespace}.{r.ClassName}:{r.LineNumber}]");
                }
            }
        }
Exemplo n.º 2
0
        public async Task Run(SolutionOptions so)
        {
            if (string.IsNullOrWhiteSpace(so.RootPath))
            {
                so.RootPath = Directory.GetCurrentDirectory();
            }

            if (!Directory.Exists(so.RootPath))
            {
                ConsoleEx.WriteErrorLine($"Path {so.RootPath} not exists");
                return;
            }

            var sm        = new SolutionManager(null);
            var solutions = sm.FindSolutions(so.RootPath);

            int i = 0;

            await foreach (var s in solutions)
            {
                bool solution = false;

                if (so.ListProjects || so.ListNugets)
                {
                    var projects = await sm.ReadSolution(s);

                    foreach (var p in projects)
                    {
                        if ((so.ShowOnlyCore && !p.IsNetCore) || (so.ShowOnlyFull && p.IsNetCore))
                        {
                            continue;
                        }

                        if (!string.IsNullOrWhiteSpace(so.ProjectName) && p.Name.IndexOf(so.ProjectName.Trim(), System.StringComparison.InvariantCultureIgnoreCase) == -1)
                        {
                            continue;
                        }

                        if (so.ListProjects)
                        {
                            if (!solution)
                            {
                                solution = true;
                                ConsoleEx.WriteOKLine($"{i}. {s}");
                            }

                            ConsoleEx.WriteTitleLine($"  - {p.Name}");
                        }
                        else if (so.ListNugets)
                        {
                            bool project = false;

                            foreach (var n in p.Nugets)
                            {
                                if (so.IgnoreSystemNugets && n.Name.IsSystemNuget())
                                {
                                    continue;
                                }

                                if (!string.IsNullOrWhiteSpace(so.NugetName) && n.Name.IndexOf(so.NugetName.Trim(), System.StringComparison.InvariantCultureIgnoreCase) == -1)
                                {
                                    continue;
                                }

                                if (!solution)
                                {
                                    solution = true;
                                    ConsoleEx.WriteOKLine($"{i}. {s}");
                                }
                                if (!project)
                                {
                                    project = true;
                                    ConsoleEx.WriteTitleLine($"  - {p.Name}");
                                }
                                ConsoleEx.WriteDebugLine($"    - {n.Name} [{n.Version}]");
                            }
                        }
                    }
                }
                i++;
            }
        }
Exemplo n.º 3
0
        public async Task Run(NugetOptions no)
        {
            if (string.IsNullOrWhiteSpace(no.RootPath))
            {
                no.RootPath = Directory.GetCurrentDirectory();
            }
            if (!Directory.Exists(no.RootPath))
            {
                ConsoleEx.WriteErrorLine($"Path {no.RootPath} not exists");
                return;
            }

            var sm = new SolutionManager(null);

            var projects = new List <ProjectDetails>();

            await foreach (var solution in sm.FindSolutions(no.RootPath))
            {
                projects.AddRange(await sm.ReadSolution(solution));
            }

            var nugets = projects.Distinct().SelectMany(p => p.Nugets.Select(n => new
            {
                Name    = n.Name,
                Version = n.Version,
                Project = p.Name
            }));

            if (no.IgnoreSystemNugets)
            {
                nugets = nugets.Where(x => !x.Name.IsSystemNuget());
            }

            var grouped = nugets.GroupBy(n => n.Name).OrderBy(n => n.Key).Select(nuget => new NugetGroup
            {
                Min   = nuget.Min(n => n.Version),
                Max   = nuget.Max(n => n.Version),
                Count = nuget.Count(),
                Name  = nuget.Key
            });

            if (no.OnlyDiff)
            {
                grouped = grouped.Where(x => x.Min != x.Max);
            }

            var headerThickness = new LineThickness(LineWidth.Double, LineWidth.Single);

            var doc = new Document(new Span("Nugets:")
            {
                Color = Yellow
            }, "\n",
                                   new Grid
            {
                Color    = Gray,
                Columns  = { GridLength.Star(1), GridLength.Auto, GridLength.Auto, GridLength.Auto },
                Children =
                {
                    new Cell("Name")
                    {
                        Stroke = headerThickness
                    },
                    new Cell("Min")
                    {
                        Stroke = headerThickness
                    },
                    new Cell("Max")
                    {
                        Stroke = headerThickness
                    },
                    new Cell("Count")
                    {
                        Stroke = headerThickness
                    },
                    grouped.Select(item => new[]
                    {
                        new Cell(item.Name)
                        {
                            Color = ColumnColor(item)
                        },
                        new Cell(item.Min)
                        {
                            Color = ColumnColor(item)
                        },
                        new Cell(item.Max)
                        {
                            Color = ColumnColor(item)
                        },
                        new Cell(item.Count)
                        {
                            Color = ColumnColor(item)
                        },
                    })
                }
            }
                                   );

            ConsoleRenderer.RenderDocument(doc);
        }