Skip to content

Commit 99f543b

Browse files
authored
Create command files (#2)
* Added new projects * Added yaml file
1 parent 0dc6400 commit 99f543b

28 files changed

Lines changed: 3939 additions & 9 deletions

.devcontainer/openapi.yaml

Lines changed: 521 additions & 0 deletions
Large diffs are not rendered by default.

.devcontainer/test.json

Lines changed: 2021 additions & 0 deletions
Large diffs are not rendered by default.

.devcontainer/test2.json

Whitespace-only changes.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,5 @@ FodyWeavers.xsd
418418
*.msix
419419
*.msm
420420
*.msp
421+
422+
.idea/

DbApiBuilderEntityGenerator.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbApiBuilderEntityGenerator
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbApiBuilderEntityGenerator.Core", "src\DbApiBuilderEntityGenerator.Core\DbApiBuilderEntityGenerator.Core.csproj", "{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}"
1111
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbApiBuilderEntityGenerator.Core.Tests", "tests\DbApiBuilderEntityGenerator.Core.Tests\DbApiBuilderEntityGenerator.Core.Tests.csproj", "{1E6A2D39-C87E-457D-9733-C95A43256055}"
15+
EndProject
1216
Global
1317
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1418
Debug|Any CPU = Debug|Any CPU
@@ -43,12 +47,25 @@ Global
4347
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}.Release|x64.Build.0 = Release|Any CPU
4448
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}.Release|x86.ActiveCfg = Release|Any CPU
4549
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}.Release|x86.Build.0 = Release|Any CPU
50+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x64.ActiveCfg = Debug|Any CPU
53+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x64.Build.0 = Debug|Any CPU
54+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x86.ActiveCfg = Debug|Any CPU
55+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x86.Build.0 = Debug|Any CPU
56+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x64.ActiveCfg = Release|Any CPU
59+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x64.Build.0 = Release|Any CPU
60+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x86.ActiveCfg = Release|Any CPU
61+
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x86.Build.0 = Release|Any CPU
4662
EndGlobalSection
4763
GlobalSection(SolutionProperties) = preSolution
4864
HideSolutionNode = FALSE
4965
EndGlobalSection
5066
GlobalSection(NestedProjects) = preSolution
5167
{033FBC15-D1D8-4ACB-9D7D-4D0C7803345C} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
5268
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
69+
{1E6A2D39-C87E-457D-9733-C95A43256055} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
5370
EndGlobalSection
5471
EndGlobal

src/DbApiBuilderEntityGenerator.Core/Class1.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using System;
2+
using DbApiBuilderEntityGenerator.Core.Serialization;
3+
using Microsoft.Extensions.Logging;
4+
using YamlDotNet.Serialization;
5+
using YamlDotNet.Serialization.NamingConventions;
6+
7+
namespace DbApiBuilderEntityGenerator.Core;
8+
9+
/// <summary>
10+
/// Serialization and Deserialization for the <see cref="Generator"/> class
11+
/// </summary>
12+
public class ConfigurationSerializer : IConfigurationSerializer
13+
{
14+
private readonly ILogger<ConfigurationSerializer> _logger;
15+
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="ConfigurationSerializer"/> class.
18+
/// </summary>
19+
/// <param name="logger">The logger.</param>
20+
public ConfigurationSerializer(ILogger<ConfigurationSerializer> logger)
21+
{
22+
_logger = logger;
23+
}
24+
25+
/// <summary>
26+
/// The options file name. Default 'generation.yml'
27+
/// </summary>
28+
public const string OptionsFileName = "generation.yml";
29+
30+
/// <summary>
31+
/// Loads the options file using the specified <paramref name="directory"/> and <paramref name="file"/>.
32+
/// </summary>
33+
/// <param name="directory">The directory where the file is located.</param>
34+
/// <param name="file">The name of the options file.</param>
35+
/// <returns>An instance of <see cref="Generator"/> if the file exists; otherwise <c>null</c>.</returns>
36+
public GeneratorModel? Load(string? directory = null, string file = OptionsFileName)
37+
{
38+
var path = GetPath(directory, file);
39+
if (!File.Exists(path))
40+
{
41+
_logger.LogWarning("Option file not found: {file}", file);
42+
return null;
43+
}
44+
45+
_logger.LogInformation("Loading options file: {file}", file);
46+
using var reader = File.OpenText(path);
47+
48+
return Load(reader);
49+
}
50+
51+
/// <summary>
52+
/// Loads the options using the specified <paramref name="reader" />
53+
/// </summary>
54+
/// <param name="reader">The reader.</param>
55+
/// <returns>
56+
/// An instance of <see cref="Generator" />.
57+
/// </returns>
58+
public GeneratorModel? Load(TextReader reader)
59+
{
60+
if (reader == null)
61+
return null;
62+
63+
var deserializer = new DeserializerBuilder()
64+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
65+
.Build();
66+
67+
// use Serialization model for better yaml support
68+
return deserializer.Deserialize<GeneratorModel>(reader);
69+
}
70+
71+
/// <summary>
72+
/// Saves the generator options to the specified <paramref name="directory"/> and <paramref name="file"/>.
73+
/// </summary>
74+
/// <param name="generatorOptions">The generator options to save.</param>
75+
/// <param name="directory">The directory where the file is located.</param>
76+
/// <param name="file">The name of the options file.</param>
77+
/// <returns>The full path of the options file.</returns>
78+
public string Save(GeneratorModel generatorOptions, string? directory = null, string file = OptionsFileName)
79+
{
80+
if (string.IsNullOrWhiteSpace(directory))
81+
directory = Environment.CurrentDirectory;
82+
83+
if (string.IsNullOrWhiteSpace(file))
84+
file = OptionsFileName;
85+
86+
if (!Directory.Exists(directory))
87+
{
88+
_logger.LogTrace($"Creating Directory: {directory}");
89+
Directory.CreateDirectory(directory);
90+
}
91+
92+
_logger.LogInformation($"Saving options file: {file}");
93+
94+
var path = Path.Combine(directory, file);
95+
96+
var serializer = new SerializerBuilder()
97+
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
98+
.WithNamingConvention(CamelCaseNamingConvention.Instance)
99+
.Build();
100+
101+
using (var streamWriter = File.CreateText(path))
102+
serializer.Serialize(streamWriter, generatorOptions);
103+
104+
return path;
105+
}
106+
107+
/// <summary>
108+
/// Determines if the specified options file exists.
109+
/// </summary>
110+
/// <param name="directory">The directory where the file is located.</param>
111+
/// <param name="file">The name of the options file.</param>
112+
/// <returns><c>true</c> if options file exits; otherwise <c>false</c>.</returns>
113+
public bool Exists(string? directory = null, string file = OptionsFileName)
114+
{
115+
var path = GetPath(directory, file);
116+
return File.Exists(path);
117+
}
118+
119+
120+
private static string GetPath(string? directory, string? file)
121+
{
122+
if (string.IsNullOrWhiteSpace(directory))
123+
directory = Environment.CurrentDirectory;
124+
125+
if (string.IsNullOrWhiteSpace(file))
126+
file = OptionsFileName;
127+
128+
var path = Path.Combine(directory, file);
129+
return path;
130+
}
131+
132+
}

src/DbApiBuilderEntityGenerator.Core/DbApiBuilderEntityGenerator.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@
2323
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="9.0.0-preview.3.efcore.9.0.0" />
2424
<PackageReference Include="YamlDotNet" Version="16.3.0" />
2525
</ItemGroup>
26+
<ItemGroup>
27+
<Folder Include="Serialization\" />
28+
</ItemGroup>
2629
</Project>

0 commit comments

Comments
 (0)