-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigLoader.cs
More file actions
192 lines (170 loc) · 6.48 KB
/
ConfigLoader.cs
File metadata and controls
192 lines (170 loc) · 6.48 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
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
using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
public class ConfigLoader
{
public GeneratorConfig TryParse(string filename)
{
var lines = File.ReadAllLines(filename);
var withoutComments = lines.Where(l => !l.TrimStart().StartsWith("//"));
var config = JsonConvert.DeserializeObject<GeneratorConfig>(string.Join(" ", withoutComments));
foreach (var m in config.Models)
{
if (m.Fields == null) m.Fields = new GeneratorConfig.ModelField[0];
if (m.Features == null) m.Features = new string[0];
if (m.HasMany == null) m.HasMany = new string[0];
if (m.HasOne == null) m.HasOne = new string[0];
if (m.MaybeHasOne == null) m.MaybeHasOne = new string[0];
}
return config;
}
}
public class GeneratorConfig
{
public enum FailedToFindStrategy
{
useNullObject,
useErrorCode
}
public class ConfigSection
{
[Check(CheckType.NotEmpty)]
public string GenerateNamespace { get; set; }
public string HeaderComment { get; set; }
public ConfigOutputSection Output { get; set; }
public ConfigDatabaseSection Database { get; set; }
public ConfigGraphQlSection GraphQl { get; set; }
public ConfigIntegrationTestSection IntegrationTests { get; set; }
[Check(CheckType.OneOf, "int", "string")]
public string IdType { get; set; }
[Check(CheckType.ParsesTo, typeof(FailedToFindStrategy))]
public string FailedToFindStrategy { get; set; }
[Check(CheckType.NotEmpty)]
public string SelfRefNavigationPropertyPrefix { get; set; }
public string[] SourcePackages { get; set; }
public string[] IntegrationTestPackages { get; set; }
public string[] UnitTestPackages { get; set; }
public FailedToFindStrategy GetFailedToFindStrategy()
{
return Enum.Parse<FailedToFindStrategy>(FailedToFindStrategy);
}
}
public class ConfigOutputSection
{
[Check(CheckType.NotEmpty)]
public string ProjectRoot { get; set; }
[Check(CheckType.NotEmpty)]
public string SourceFolder { get; set; }
[Check(CheckType.NotEmpty)]
public string IntegrationTestFolder { get; set; }
[Check(CheckType.NotEmpty)]
public string UnitTestFolder { get; set; }
[Check(CheckType.NotEmpty)]
public string GeneratedFolder { get; set; }
[Check(CheckType.NotEmpty)]
public string DataTypeObjectsSubFolder { get; set; }
[Check(CheckType.NotEmpty)]
public string DatabaseSubFolder { get; set; }
[Check(CheckType.NotEmpty)]
public string GraphQlSubFolder { get; set; }
}
public class ConfigDatabaseSection
{
[Check(CheckType.NotEmpty)]
public string DbContextClassName { get; set; }
[Check(CheckType.NotEmpty)]
public string DbContextFileName { get; set; }
[Check(CheckType.NotEmpty)]
public string DbAccesserClassName { get; set; }
[Check(CheckType.NotEmpty)]
public string DbAccesserFileName { get; set; }
[Check(CheckType.NotEmpty)]
public string DbContainerName { get; set; }
public ConfigDatabaseConnectionLocalSection LocalDev { get; set; }
public ConfigDatabaseConnectionDockerSection Docker { get; set; }
}
public class ConfigDatabaseConnectionLocalSection : ConfigDatabaseConnectionDockerSection
{
[Check(CheckType.NotEmpty)]
public string DbHost { get; set; }
}
public class ConfigDatabaseConnectionDockerSection
{
[Check(CheckType.NotEmpty)]
public string DbName { get; set; }
[Check(CheckType.NotEmpty)]
public string DbUsername { get; set; }
[Check(CheckType.NotEmpty)]
public string DbPassword { get; set; }
}
public class ConfigGraphQlSection
{
[Check(CheckType.NotEmpty)]
public string GqlTypesFileName { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlQueriesClassName { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlQueriesFileName { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlMutationsClassName { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlMutationsFilename { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlMutationsInputTypePostfix { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlMutationsCreateMethod { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlMutationsUpdateMethod { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlMutationsDeleteMethod { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlSubscriptionsClassName { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlSubscriptionsFilename { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlSubscriptionCreatedMethod { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlSubscriptionUpdatedMethod { get; set; }
[Check(CheckType.NotEmpty)]
public string GqlSubscriptionDeletedMethod { get; set; }
}
public class ConfigIntegrationTestSection
{
[Check(CheckType.NotEmpty)]
public string TestCategory { get; set; }
[Check(CheckType.NotEmpty)]
public string UtilsFolder { get; set; }
}
public class ModelConfig
{
[Check(CheckType.NotEmpty)]
public string Name { get; set; }
public string[] Features { get; set; }
public ModelField[] Fields { get; set; }
public string[] HasMany { get; set; }
public string[] HasOne { get; set; }
public string[] MaybeHasOne { get; set; }
public bool HasPagingFeature()
{
return Features.Any(f => f.ToLowerInvariant() == "paging");
}
public bool HasSortingFeature()
{
return Features.Any(f => f.ToLowerInvariant() == "sorting");
}
public bool HasFilteringFeature()
{
return Features.Any(f => f.ToLowerInvariant() == "filtering");
}
}
public class ModelField
{
[Check(CheckType.NotEmpty)]
public string Name { get; set; }
[Check(CheckType.OneOfSupportedTypes)]
public string Type { get; set; }
}
public ConfigSection Config { get; set; }
public ModelConfig[] Models { get; set; }
}