- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
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
usingCommandFlowAnalyzer.Helpers;
usingSpectre.Console;
internalclassProgram
{
staticasyncTaskMain(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;
}
varsolutionPath=args[0].Trim('"',' ');
varsolution=awaitSolutionLoader.LoadAsync(solutionPath);
if(solution==null)
return;
// solution bellekte duruyor
varanalyzer=newCqrsAnalyzer();
// handler içeren projeleri bir kez tespit et
varprojectsWithHandlers=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(inti=0;i<projectsWithHandlers.Count;i++)
AnsiConsole.MarkupLine($" [green]{i+1}.[/] {projectsWithHandlers[i].Name}");
Console.WriteLine();
varprojectIndex=AnsiConsole.Ask<int>("Select project number:");
if(projectIndex<1||projectIndex>projectsWithHandlers.Count)
{
AnsiConsole.MarkupLine("[red]❌ Invalid selection.[/]");
continue;
}
varselectedProject=projectsWithHandlers[projectIndex-1];
AnsiConsole.MarkupLine($"[bold yellow]Analyzing project:[/] [green]{selectedProject.Name}[/]");
varrelations=awaitanalyzer.AnalyzeProjectAsync(selectedProject);
if(relations.Count==0)
{
AnsiConsole.MarkupLine("[yellow]No CQRS relations found in this project.[/]");
}
else
{
Treetree=TreeBuilder.Build(relations);
AnsiConsole.Write(tree);
vartimestamp=DateTime.Now.ToString("yyyyMMdd_HHmmss");
varoutputFileName=$"{selectedProject.Name}-command-tree-{timestamp}.txt";
FileWriter.WriteRelationsToFile(relations,outputFileName);
AnsiConsole.MarkupLine($"[grey]Tree saved to [green]{outputFileName}[/][/]");
}
Console.WriteLine();
varagain=AnsiConsole.Prompt(
newTextPrompt<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.[/]");
}
}