-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
87 lines (70 loc) · 3.05 KB
/
Copy pathProgram.cs
File metadata and controls
87 lines (70 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using CommandFlowAnalyzer.Helpers;
using Spectre.Console;
internal class Program
{
static async Task Main(string[] args)
{
AnsiConsole.MarkupLine("[bold yellow]🔍 CQRS Flow Analyzer (Roslyn Edition)[/]");
Console.WriteLine();
if (args.Length == 0)
{
AnsiConsole.MarkupLine("[red]❌ Usage:[/] cfa \"path-to-solution.sln\"");
return;
}
var solutionPath = args[0].Trim('"', ' ');
var solution = await SolutionLoader.LoadAsync(solutionPath);
if (solution == null)
return;
// solution bellekte duruyor
var analyzer = new CqrsAnalyzer();
// handler içeren projeleri bir kez tespit et
var projectsWithHandlers = solution.Projects
.Where(p => p.Documents.Any(d =>
d.FilePath != null && File.ReadAllText(d.FilePath).Contains("IRequestHandler")))
.ToList();
if (!projectsWithHandlers.Any())
{
AnsiConsole.MarkupLine("[red]❌ No projects with IRequestHandler found in this solution.[/]");
return;
}
while (true)
{
Console.WriteLine();
AnsiConsole.MarkupLine("[bold cyan]Projects in solution:[/]");
for (int i = 0; i < projectsWithHandlers.Count; i++)
AnsiConsole.MarkupLine($" [green]{i + 1}.[/] {projectsWithHandlers[i].Name}");
Console.WriteLine();
var projectIndex = AnsiConsole.Ask<int>("Select project number:");
if (projectIndex < 1 || projectIndex > projectsWithHandlers.Count)
{
AnsiConsole.MarkupLine("[red]❌ Invalid selection.[/]");
continue;
}
var selectedProject = projectsWithHandlers[projectIndex - 1];
AnsiConsole.MarkupLine($"[bold yellow]Analyzing project:[/] [green]{selectedProject.Name}[/]");
var relations = await analyzer.AnalyzeProjectAsync(selectedProject);
if (relations.Count == 0)
{
AnsiConsole.MarkupLine("[yellow]No CQRS relations found in this project.[/]");
}
else
{
Tree tree = TreeBuilder.Build(relations);
AnsiConsole.Write(tree);
var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
var outputFileName = $"{selectedProject.Name}-command-tree-{timestamp}.txt";
FileWriter.WriteRelationsToFile(relations, outputFileName);
AnsiConsole.MarkupLine($"[grey]Tree saved to [green]{outputFileName}[/][/]");
}
Console.WriteLine();
var again = AnsiConsole.Prompt(
new TextPrompt<string>("[yellow]Would you like to analyze another project? (y/n)[/]")
.AllowEmpty()
.DefaultValue("n")
);
if (!again.Equals("y", StringComparison.OrdinalIgnoreCase))
break;
}
AnsiConsole.MarkupLine("[grey]👋 Exiting CQRS Flow Analyzer.[/]");
}
}