-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
234 lines (175 loc) · 10.3 KB
/
Program.cs
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using ExplicitArchitectureStructureCreator.FileTemplate.Csproj;
using ExplicitArchitectureStructureCreator.FileTemplate.Solution;
namespace ExplicitArchitectureStructureCreator
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("~ Explicit architecture structure creator ~");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("Name of project (press ENTER to confirm):");
var projectName = Console.ReadLine();
if (string.IsNullOrWhiteSpace(projectName))
{
throw new ArgumentNullException(nameof(projectName));
}
var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
Console.WriteLine($"Creation of {projectName} project in {currentDirectory.FullName}.");
CreateProjectStructure(projectName, currentDirectory);
CreateLibStructure(currentDirectory);
Console.WriteLine("Project structure created. Press ENTER to close.");
_ = Console.ReadLine();
}
private static void CreateTestForProject(string projectName, DirectoryInfo testsDirectory)
{
var directoryName = $"{projectName}.{Constants.CORE}.{Constants.TESTS_PROJECT}";
DirectoryInfo? testsProjDirectory = CreateFolder(testsDirectory, directoryName);
var fileName = $"{directoryName}.{CoreTestTemplate.GetExtension()}";
CreatFile(fileName, testsProjDirectory, CoreTestTemplate.GetContentFile());
}
private static void CreateTestStructure(string projectName, DirectoryInfo projectDirectory)
{
DirectoryInfo? testsDirectory = CreateFolder(projectDirectory, Constants.TESTS_FOLDER);
CreateTestForProject(projectName, testsDirectory);
}
private static void CreateSolution(string projectName, DirectoryInfo srcDirectory)
{
var solutionFileName = $"{projectName}.sln";
CreatFile(solutionFileName, srcDirectory, SolutionTemplate.GetContentFile(projectName));
}
private static void CreateWebAppStructure(string projectName, DirectoryInfo userInterfaceDirectory)
{
var directoryName = $"{projectName}.{Constants.WEB_APP}";
_ = CreateFolder(userInterfaceDirectory, directoryName);
}
private static void CreateWebApiStructure(string projectName, DirectoryInfo userInterfaceDirectory)
{
var directoryName = $"{projectName}.{Constants.WEB_API}";
DirectoryInfo? userInterfaceProjectDirectory = CreateFolder(userInterfaceDirectory, directoryName);
var fileName = $"{directoryName}.{WebApiTemplate.GetExtension()}";
CreatFile(fileName, userInterfaceProjectDirectory, WebApiTemplate.GetContentFile(projectName));
}
private static void CreateUserInterfaceStructure(string projectName, DirectoryInfo srcDirectory)
{
DirectoryInfo? userInterfaceDirectory = CreateFolder(srcDirectory, Constants.USER_INTERFACE);
CreateWebApiStructure(projectName, userInterfaceDirectory);
CreateWebAppStructure(projectName, userInterfaceDirectory);
}
private static void CreateInfrastructureStructure(string projectName, DirectoryInfo srcDirectory)
{
var directoryName = $"{projectName}.{Constants.INFRASTRUCTURE}";
DirectoryInfo? infrastructureDirectory = CreateFolder(srcDirectory, directoryName);
var fileName = $"{directoryName}.{InfrastructureTemplate.GetExtension()}";
CreatFile(fileName, infrastructureDirectory, InfrastructureTemplate.GetContentFile(projectName));
}
private static void CreateSharedKernelStructure(DirectoryInfo coreDirectory)
{
DirectoryInfo? sharedKernelDirectory = CreateFolder(coreDirectory, Constants.SHARED_KERNEL);
DirectoryInfo? valueObjectDirectory = CreateFolder(sharedKernelDirectory, Constants.VALUE_OBJECT);
CreatFile("Default.cs", valueObjectDirectory, string.Empty);
var componentDirectory = CreateFolder(sharedKernelDirectory, Constants.COMPONENT);
DirectoryInfo? defaultComponentDirectory = CreateFolder(componentDirectory, Constants.DEFAULT_COMPONENT);
DirectoryInfo? defaultAggregateDirectory = CreateFolder(defaultComponentDirectory, Constants.DEFAULT_AGGREGATE);
CreatFile("Default.cs", defaultAggregateDirectory, string.Empty);
}
private static void CreateDefaultDomainStructure(DirectoryInfo defaultComponentDirectory)
{
DirectoryInfo? domainDirectory = CreateFolder(defaultComponentDirectory, Constants.DOMAIN);
DirectoryInfo? defaultAggregateDirectory = CreateFolder(domainDirectory, Constants.DEFAULT_AGGREGATE);
CreatFile("Default.cs", defaultAggregateDirectory, string.Empty);
}
private static void CreateDefaultComponetStructure(DirectoryInfo componentDirectory)
{
DirectoryInfo? defaultComponentDirectory = CreateFolder(componentDirectory, Constants.DEFAULT_COMPONENT);
_ = CreateFolder(defaultComponentDirectory, Constants.APPLICATION);
CreateDefaultDomainStructure(defaultComponentDirectory);
}
private static void CreateComponentStructure(DirectoryInfo coreDirectory)
{
DirectoryInfo? componentDirectory = CreateFolder(coreDirectory, Constants.COMPONENT);
CreateDefaultComponetStructure(componentDirectory);
}
private static void CreateCoreStructure(string projectName, DirectoryInfo srcDirectory)
{
var directoryName = $"{projectName}.{Constants.CORE}";
DirectoryInfo? coreDirectory = CreateFolder(srcDirectory, directoryName);
CreateComponentStructure(coreDirectory);
CreateSharedKernelStructure(coreDirectory);
var fileName = $"{directoryName}.{CoreTemplate.GetExtension()}";
CreatFile(fileName, coreDirectory, CoreTemplate.GetContentFile());
}
private static void CreateSrcStructure(string projectName, DirectoryInfo projectDirectory)
{
DirectoryInfo? srcDirectory = CreateFolder(projectDirectory, Constants.SRC);
CreateCoreStructure(projectName, srcDirectory);
CreateInfrastructureStructure(projectName, srcDirectory);
CreateUserInterfaceStructure(projectName, srcDirectory);
CreateSolution(projectName, srcDirectory);
}
private static void CreateProjectStructure(string projectName, DirectoryInfo currentDirectory)
{
DirectoryInfo? projectDirectory = CreateFolder(currentDirectory, projectName);
CreateSrcStructure(projectName, projectDirectory);
CreateTestStructure(projectName, projectDirectory);
}
private static void CreateDotNetExtensionsTestsProjectStructure(DirectoryInfo dotNetExtensionsTestDirectory)
{
DirectoryInfo? dotNetExtensionsTestProjectDirectory = CreateFolder(dotNetExtensionsTestDirectory, Constants.DOT_NET_EXTENSIONS_PROJ_TEST);
var fileName = $"{Constants.DOT_NET_EXTENSIONS_PROJ_TEST}.{DotNetExtensionsTestTemplate.GetExtension()}";
CreatFile(fileName, dotNetExtensionsTestProjectDirectory, DotNetExtensionsTestTemplate.GetContentFile());
}
private static void CreateDotNetExtensionsTestsStructure(DirectoryInfo dotNetExtensionsDirectory)
{
DirectoryInfo? dotNetExtensionsTestDirectory = CreateFolder(dotNetExtensionsDirectory, Constants.TESTS_FOLDER);
CreateDotNetExtensionsTestsProjectStructure(dotNetExtensionsTestDirectory);
}
private static void CreateDotNetExtensionsProjectStructure(DirectoryInfo dotNetExtensionsSrcDirectory)
{
DirectoryInfo? dotNetExtensionsSrcProjectDirectory = CreateFolder(dotNetExtensionsSrcDirectory, Constants.DOT_NET_EXTENSIONS_PROJ);
var fileName = $"{Constants.DOT_NET_EXTENSIONS_PROJ}.{DotNetExtensionsProjectTemplate.GetExtension()}";
CreatFile(fileName, dotNetExtensionsSrcProjectDirectory, DotNetExtensionsProjectTemplate.GetContentFile());
}
private static void CreateDotNetExtensionsSrcStructure(DirectoryInfo dotNetExtensionsDirectory)
{
DirectoryInfo? dotNetExtensionsSrcDirectory = CreateFolder(dotNetExtensionsDirectory, Constants.SRC);
CreateDotNetExtensionsProjectStructure(dotNetExtensionsSrcDirectory);
}
private static void CreateDotNetExtensionsStructure(DirectoryInfo libDirectory)
{
DirectoryInfo? dotNetExtensionsDirectory = CreateFolder(libDirectory, Constants.DOT_NET_EXTENSIONS);
CreateDotNetExtensionsSrcStructure(dotNetExtensionsDirectory);
CreateDotNetExtensionsTestsStructure(dotNetExtensionsDirectory);
}
private static void CreateLibStructure(DirectoryInfo currentDirectory)
{
DirectoryInfo? libDirectory = CreateFolder(currentDirectory, Constants.LIB);
CreateDotNetExtensionsStructure(libDirectory);
}
private static void CreatFile(string fileName, DirectoryInfo sourceDirectory, string content)
{
var filePath = Path.Combine(sourceDirectory.FullName, fileName);
if (!File.Exists(filePath))
{
File.WriteAllText(filePath, contents: content);
}
Console.WriteLine($"{filePath} file created.");
}
private static DirectoryInfo CreateFolder(DirectoryInfo source, string destination)
{
var destinationPath = Path.Combine(source.FullName, destination);
DirectoryInfo? destinationDirectory;
if (!Directory.Exists(destinationPath))
{
destinationDirectory = Directory.CreateDirectory(destinationPath);
Console.WriteLine($"{destinationPath} folder created.");
}
else
{
destinationDirectory = new DirectoryInfo(destinationPath);
}
return destinationDirectory;
}
}
}