From 6d6a8fa9ffbe775e82ca5d72e38e2873ace7552b Mon Sep 17 00:00:00 2001 From: KY Date: Tue, 14 Jan 2020 16:40:37 +0100 Subject: [PATCH 1/4] Core - force all parameters to start with a dash - always a command is needed (to generate from generator.json, use "run -configuration=" - easier generator create syntax (used in CLI) - command parameters reduced to single type (instead of with and without value) - command parameter reader error handling added --- Angular/KY.Generator.Angular.csproj | 2 +- .../Results/GeneratorController.cs.result | 29 ++--- AspDotNet/KY.Generator.AspDotNet.csproj | 2 +- .../KY.Generator.CLI.Core.Full.csproj | 2 +- CLI.Core.Full/Program.cs | 34 +++--- CLI.Core.Full/nuget.nuspec | 24 ++-- CLI.Core.Full/nuget.targets | 4 +- .../KY.Generator.CLI.Core.Minimal.csproj | 2 +- CLI.Core.Minimal/Program.cs | 18 +-- CLI.Core.Minimal/nuget.nuspec | 2 +- CLI.Core.Minimal/nuget.targets | 4 +- .../KY.Generator.CLI.Core.Standalone.csproj | 2 +- CLI.Core.Standalone/Program.cs | 36 +++--- CLI.Core.Standalone/nuget.nuspec | 2 +- CLI.Core/KY.Generator.CLI.Core.csproj | 2 +- CLI.Core/Program.cs | 36 +++--- CLI.Core/nuget.nuspec | 2 +- CLI.Core/nuget.targets | 4 +- CLI.Full/Program.cs | 34 +++--- CLI.Full/Properties/AssemblyInfo.cs | 4 +- CLI.Full/nuget.nuspec | 24 ++-- CLI.Full/nuget.targets | 4 +- CLI.Minimal/Program.cs | 12 +- CLI.Minimal/Properties/AssemblyInfo.cs | 4 +- CLI.Minimal/nuget.nuspec | 2 +- CLI.Minimal/nuget.targets | 4 +- CLI.Standalone/Program.cs | 36 +++--- CLI.Standalone/Properties/AssemblyInfo.cs | 4 +- CLI.Standalone/nuget.nuspec | 2 +- CLI/Program.cs | 36 +++--- CLI/Properties/AssemblyInfo.cs | 4 +- CLI/nuget.nuspec | 2 +- CLI/nuget.targets | 4 +- Core/Command/CommandConfiguration.cs | 4 +- Core/Command/CommandParameter.cs | 27 ++++- Core/Command/CommandReader.cs | 25 ++-- Core/Command/CommandValueParameter.cs | 34 ------ .../Extensions/ConfigurationBaseExtension.cs | 3 +- Core/Command/ParameterListExtension.cs | 12 +- Core/Commands/RunCommand.cs | 3 - Core/Generator.cs | 108 +++++------------- Core/KY.Generator.Core.csproj | 2 +- Core/Module/GeneratorModule.cs | 21 ---- Core/Syntax/IGeneratorAfterRunSyntax.cs | 8 ++ Core/Syntax/IGeneratorRunSyntax.cs | 2 +- Csharp/KY.Generator.CSharp.csproj | 2 +- .../KY.Generator.EntityFramework.csproj | 2 +- Json/KY.Generator.Json.csproj | 2 +- OData/KY.Generator.OData.csproj | 2 +- OData/ODataModule.cs | 4 +- OpenApi/KY.Generator.OpenApi.csproj | 2 +- ...KY.Generator.Reflection.Annotations.csproj | 2 +- Reflection.Tests/InterfaceTest.cs | 30 +++-- Reflection/KY.Generator.Reflection.csproj | 2 +- Reflection/ReflectionModule.cs | 15 +-- Tsql/KY.Generator.Tsql.csproj | 2 +- Tsql/TsqlModule.cs | 4 +- TypeScript/KY.Generator.TypeScript.csproj | 2 +- Watchdog/Commands/WatchdogCommand.cs | 6 +- Watchdog/KY.Generator.Watchdog.csproj | 2 +- 60 files changed, 289 insertions(+), 422 deletions(-) delete mode 100644 Core/Command/CommandValueParameter.cs delete mode 100644 Core/Module/GeneratorModule.cs create mode 100644 Core/Syntax/IGeneratorAfterRunSyntax.cs diff --git a/Angular/KY.Generator.Angular.csproj b/Angular/KY.Generator.Angular.csproj index 6d169abf..868616b0 100644 --- a/Angular/KY.Generator.Angular.csproj +++ b/Angular/KY.Generator.Angular.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 3.3.0 + 4.0.0-rc.0 2020 - KY-Programming Angular Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/AspDotNet.Tests/Results/GeneratorController.cs.result b/AspDotNet.Tests/Results/GeneratorController.cs.result index d16e1ed8..fd2f81fb 100644 --- a/AspDotNet.Tests/Results/GeneratorController.cs.result +++ b/AspDotNet.Tests/Results/GeneratorController.cs.result @@ -1,21 +1,18 @@ - cache = new Dictionary(); - - [HttpPost("[action]")] + [ValidateInput(false)] public string Create(string configuration) { string id = Guid.NewGuid().ToString(); @@ -29,11 +26,10 @@ namespace KY.Generator.Test.Controllers generator.ParseConfiguration(configuration); generator.Run(); - cache[id] = output; + HttpContext.Current.Cache[id] = output; return id; } - [HttpPost("[action]")] public string Command(string command) { string id = Guid.NewGuid().ToString(); @@ -47,36 +43,33 @@ namespace KY.Generator.Test.Controllers generator.ParseCommand(command); generator.Run(); - cache[id] = output; + HttpContext.Current.Cache[id] = output; return id; } - [HttpPost("[action]")] public string GetFiles(string id) { if (id == null) { return null; } - MemoryOutput output = cache[id]; + MemoryOutput output = HttpContext.Current.Cache[id] as MemoryOutput; return output == null ? null : string.Join(Environment.NewLine, output.Files.Select(x => x.Key)); } - [HttpPost("[action]")] public string GetFile(string id, string path) { if (id == null) { return null; } - MemoryOutput output = cache[id]; + MemoryOutput output = HttpContext.Current.Cache[id] as MemoryOutput; return output == null || ! output.Files.ContainsKey(path) ? null : output.Files[path]; } - [HttpGet("[action]")] public bool Available() { return true; } } -}> \ No newline at end of file +} \ No newline at end of file diff --git a/AspDotNet/KY.Generator.AspDotNet.csproj b/AspDotNet/KY.Generator.AspDotNet.csproj index 62778801..3b3b7605 100644 --- a/AspDotNet/KY.Generator.AspDotNet.csproj +++ b/AspDotNet/KY.Generator.AspDotNet.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.3.0 + 4.0.0-rc.0 KY.Generator ASP.net Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj b/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj index 9c3e9749..356b6d02 100644 --- a/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj +++ b/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj @@ -3,7 +3,7 @@ Exe netcoreapp2.2 - 3.3.0 + 4.0.0-rc.0 KY-Programming KY.Generator 2020 - KY-Programming diff --git a/CLI.Core.Full/Program.cs b/CLI.Core.Full/Program.cs index a4e9c156..0119e5a2 100644 --- a/CLI.Core.Full/Program.cs +++ b/CLI.Core.Full/Program.cs @@ -18,26 +18,20 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI.Core.Full/nuget.nuspec b/CLI.Core.Full/nuget.nuspec index 3c1b8c10..2ca4591e 100644 --- a/CLI.Core.Full/nuget.nuspec +++ b/CLI.Core.Full/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI.Core.Full - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming @@ -17,17 +17,17 @@ Generate classes from oData, .NET assembly, JSON or TSQL to C# or TypeScript. Su Copyright 2020 KY-Generator KY Generator .netCore CLI - - - - - - - - - - - + + + + + + + + + + + diff --git a/CLI.Core.Full/nuget.targets b/CLI.Core.Full/nuget.targets index 4d14ad96..9e7ff4d5 100644 --- a/CLI.Core.Full/nuget.targets +++ b/CLI.Core.Full/nuget.targets @@ -1,12 +1,12 @@  - - diff --git a/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj b/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj index cdd536c8..0341fb8f 100644 --- a/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj +++ b/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj @@ -3,7 +3,7 @@ Exe netcoreapp2.2 - 3.3.0 + 4.0.0-rc.0 KY-Programming KY.Generator 2020 - KY-Programming diff --git a/CLI.Core.Minimal/Program.cs b/CLI.Core.Minimal/Program.cs index 0cc13ff6..d6290b2e 100644 --- a/CLI.Core.Minimal/Program.cs +++ b/CLI.Core.Minimal/Program.cs @@ -3,19 +3,13 @@ namespace KY.Generator { - class Program + internal class Program { - static void Main(string[] args) + private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) @@ -26,4 +20,4 @@ static void Main(string[] args) #endif } } -} +} \ No newline at end of file diff --git a/CLI.Core.Minimal/nuget.nuspec b/CLI.Core.Minimal/nuget.nuspec index acf0d8cf..57226ad7 100644 --- a/CLI.Core.Minimal/nuget.nuspec +++ b/CLI.Core.Minimal/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI.Core.Minimal - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming diff --git a/CLI.Core.Minimal/nuget.targets b/CLI.Core.Minimal/nuget.targets index 69b91bdf..22f74c10 100644 --- a/CLI.Core.Minimal/nuget.targets +++ b/CLI.Core.Minimal/nuget.targets @@ -1,12 +1,12 @@  - - diff --git a/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj b/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj index 9c3e9749..356b6d02 100644 --- a/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj +++ b/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj @@ -3,7 +3,7 @@ Exe netcoreapp2.2 - 3.3.0 + 4.0.0-rc.0 KY-Programming KY.Generator 2020 - KY-Programming diff --git a/CLI.Core.Standalone/Program.cs b/CLI.Core.Standalone/Program.cs index 6db74c3c..45d1bbb9 100644 --- a/CLI.Core.Standalone/Program.cs +++ b/CLI.Core.Standalone/Program.cs @@ -18,27 +18,21 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetStandalone() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .SetStandalone() + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI.Core.Standalone/nuget.nuspec b/CLI.Core.Standalone/nuget.nuspec index af4d6e21..4219e056 100644 --- a/CLI.Core.Standalone/nuget.nuspec +++ b/CLI.Core.Standalone/nuget.nuspec @@ -2,7 +2,7 @@ KY.Generator.CLI.Core.Standalone - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming diff --git a/CLI.Core/KY.Generator.CLI.Core.csproj b/CLI.Core/KY.Generator.CLI.Core.csproj index 9c3e9749..356b6d02 100644 --- a/CLI.Core/KY.Generator.CLI.Core.csproj +++ b/CLI.Core/KY.Generator.CLI.Core.csproj @@ -3,7 +3,7 @@ Exe netcoreapp2.2 - 3.3.0 + 4.0.0-rc.0 KY-Programming KY.Generator 2020 - KY-Programming diff --git a/CLI.Core/Program.cs b/CLI.Core/Program.cs index 6db74c3c..45d1bbb9 100644 --- a/CLI.Core/Program.cs +++ b/CLI.Core/Program.cs @@ -18,27 +18,21 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetStandalone() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .SetStandalone() + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI.Core/nuget.nuspec b/CLI.Core/nuget.nuspec index c5fde705..a2b1c522 100644 --- a/CLI.Core/nuget.nuspec +++ b/CLI.Core/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI.Core - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming diff --git a/CLI.Core/nuget.targets b/CLI.Core/nuget.targets index 21b099f6..166c9e68 100644 --- a/CLI.Core/nuget.targets +++ b/CLI.Core/nuget.targets @@ -1,12 +1,12 @@  - - diff --git a/CLI.Full/Program.cs b/CLI.Full/Program.cs index b3cd5c1e..aaf25b60 100644 --- a/CLI.Full/Program.cs +++ b/CLI.Full/Program.cs @@ -18,26 +18,20 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI.Full/Properties/AssemblyInfo.cs b/CLI.Full/Properties/AssemblyInfo.cs index fee6b4e0..4d4a30b0 100644 --- a/CLI.Full/Properties/AssemblyInfo.cs +++ b/CLI.Full/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.0")] -[assembly: AssemblyFileVersion("3.3.0.0")] +[assembly: AssemblyVersion("4.0.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] diff --git a/CLI.Full/nuget.nuspec b/CLI.Full/nuget.nuspec index 1b20bfe1..a9d4adaa 100644 --- a/CLI.Full/nuget.nuspec +++ b/CLI.Full/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI.Full - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming @@ -17,17 +17,17 @@ Generate classes from oData, .NET assembly, JSON or TSQL to C# or TypeScript. Su Copyright 2020 KY-Generator KY Generator CLI - - - - - - - - - - - + + + + + + + + + + + diff --git a/CLI.Full/nuget.targets b/CLI.Full/nuget.targets index 42e340ef..7d3f567c 100644 --- a/CLI.Full/nuget.targets +++ b/CLI.Full/nuget.targets @@ -1,12 +1,12 @@  - - diff --git a/CLI.Minimal/Program.cs b/CLI.Minimal/Program.cs index 0b4a16c5..d6290b2e 100644 --- a/CLI.Minimal/Program.cs +++ b/CLI.Minimal/Program.cs @@ -7,15 +7,9 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI.Minimal/Properties/AssemblyInfo.cs b/CLI.Minimal/Properties/AssemblyInfo.cs index 1e7e719e..1acd7e1a 100644 --- a/CLI.Minimal/Properties/AssemblyInfo.cs +++ b/CLI.Minimal/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.0")] -[assembly: AssemblyFileVersion("3.3.0.0")] +[assembly: AssemblyVersion("4.0.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] diff --git a/CLI.Minimal/nuget.nuspec b/CLI.Minimal/nuget.nuspec index 8c9de959..53b5f6e8 100644 --- a/CLI.Minimal/nuget.nuspec +++ b/CLI.Minimal/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI.Minimal - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming diff --git a/CLI.Minimal/nuget.targets b/CLI.Minimal/nuget.targets index 2fd05aca..a9da7e9e 100644 --- a/CLI.Minimal/nuget.targets +++ b/CLI.Minimal/nuget.targets @@ -1,12 +1,12 @@  - - diff --git a/CLI.Standalone/Program.cs b/CLI.Standalone/Program.cs index 6db74c3c..45d1bbb9 100644 --- a/CLI.Standalone/Program.cs +++ b/CLI.Standalone/Program.cs @@ -18,27 +18,21 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetStandalone() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .SetStandalone() + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI.Standalone/Properties/AssemblyInfo.cs b/CLI.Standalone/Properties/AssemblyInfo.cs index adb3bafa..376f9c01 100644 --- a/CLI.Standalone/Properties/AssemblyInfo.cs +++ b/CLI.Standalone/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.0")] -[assembly: AssemblyFileVersion("3.3.0.0")] +[assembly: AssemblyVersion("4.0.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] diff --git a/CLI.Standalone/nuget.nuspec b/CLI.Standalone/nuget.nuspec index 76609c94..325dffaa 100644 --- a/CLI.Standalone/nuget.nuspec +++ b/CLI.Standalone/nuget.nuspec @@ -2,7 +2,7 @@ KY.Generator.CLI.Standalone - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming diff --git a/CLI/Program.cs b/CLI/Program.cs index 6db74c3c..45d1bbb9 100644 --- a/CLI/Program.cs +++ b/CLI/Program.cs @@ -18,27 +18,21 @@ internal class Program { private static void Main(string[] args) { - Generator.InitializeLogger(args); - - bool success = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetStandalone() - .SetParameters(args) - .Run(); - if (!success) - { - Environment.ExitCode = 1; - } + Generator.Create(args) + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .PreloadModule() + .SetStandalone() + .Run() + .SetExitCode(); #if DEBUG if (Logger.Console.IsConsoleAvailable) diff --git a/CLI/Properties/AssemblyInfo.cs b/CLI/Properties/AssemblyInfo.cs index 1e7e719e..1acd7e1a 100644 --- a/CLI/Properties/AssemblyInfo.cs +++ b/CLI/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.0")] -[assembly: AssemblyFileVersion("3.3.0.0")] +[assembly: AssemblyVersion("4.0.0")] +[assembly: AssemblyFileVersion("4.0.0.0")] diff --git a/CLI/nuget.nuspec b/CLI/nuget.nuspec index aa778717..e6384119 100644 --- a/CLI/nuget.nuspec +++ b/CLI/nuget.nuspec @@ -3,7 +3,7 @@ KY.Generator.CLI - 3.3.0 + 4.0.0-rc.0 Codestin Search App KY-Programming KY-Programming diff --git a/CLI/nuget.targets b/CLI/nuget.targets index c2b39ee4..6f47aaa2 100644 --- a/CLI/nuget.targets +++ b/CLI/nuget.targets @@ -1,11 +1,11 @@  - - diff --git a/Core/Command/CommandConfiguration.cs b/Core/Command/CommandConfiguration.cs index a1cac17c..6df8a861 100644 --- a/Core/Command/CommandConfiguration.cs +++ b/Core/Command/CommandConfiguration.cs @@ -10,10 +10,10 @@ public class CommandConfiguration : ConfigurationBase public string Command { get; } public List Parameters { get; } - public CommandConfiguration(string command) + public CommandConfiguration(string command, List parameters = default) { this.Command = command; - this.Parameters = new List(); + this.Parameters = parameters ?? new List(); this.Language = new ForwardFileLanguage(); } } diff --git a/Core/Command/CommandParameter.cs b/Core/Command/CommandParameter.cs index 1b4edfe4..7f650f10 100644 --- a/Core/Command/CommandParameter.cs +++ b/Core/Command/CommandParameter.cs @@ -1,17 +1,40 @@ -namespace KY.Generator.Command +using System; +using System.Text.RegularExpressions; + +namespace KY.Generator.Command { public class CommandParameter { + private static readonly Regex regex = new Regex(@"^-(?[\w-]+)(=(?.+))?$"); public string Name { get; } + public string Value { get; } public CommandParameter(string name) { this.Name = name; } + public CommandParameter(string name, string value) + : this(name) + { + this.Value = value; + } + + public static CommandParameter Parse(string text) + { + Match match = regex.Match(text); + if (!match.Success) + { + throw new InvalidOperationException($"Invalid parameter '{text}'"); + } + string name = match.Groups["name"].Value; + string value = match.Groups["value"].Value; + return new CommandParameter(name, value); + } + public override string ToString() { - return this.Name; + return string.IsNullOrEmpty(this.Value) ? $"-{this.Name}" : $"-{this.Name}=\"{this.Value}\""; } } } \ No newline at end of file diff --git a/Core/Command/CommandReader.cs b/Core/Command/CommandReader.cs index 576f54bb..888fd265 100644 --- a/Core/Command/CommandReader.cs +++ b/Core/Command/CommandReader.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using KY.Core; using KY.Generator.Command.Extensions; using KY.Generator.Languages; @@ -14,20 +15,30 @@ public CommandReader(List languages) this.languages = languages; } - public CommandConfiguration Read(params string[] arguments) + public CommandConfiguration Read(params string[] parameters) { - CommandConfiguration configuration = new CommandConfiguration(arguments.First()); - SetParameters(configuration, arguments.Skip(1)); + if (parameters.Length == 0) + { + Logger.Error("No command found. Provide at least one command like 'run -configuration=\"\"'"); + return null; + } + List commandList = parameters.Where(x => !x.StartsWith("-")).ToList(); + if (commandList.Count > 1) + { + Logger.Error($"Only one command is allowed. All parameters has to start with a dash (-). Commands found: {string.Join(", ", commandList)}"); + return null; + } + List commandParameters = this.ReadParameters(parameters.Where(x => x.StartsWith("-"))).ToList(); + CommandConfiguration configuration = new CommandConfiguration(commandList.Single(), commandParameters); configuration.ReadFromParameters(configuration.Parameters, this.languages); return configuration; } - public static void SetParameters(CommandConfiguration configuration, IEnumerable parameters) + private IEnumerable ReadParameters(IEnumerable parameters) { - foreach (string chunk in parameters) + foreach (string parameter in parameters) { - string parameter = chunk.Trim(); - configuration.Parameters.Add(parameter[0] == '-' ? CommandValueParameter.Parse(parameter) : new CommandParameter(parameter)); + yield return CommandParameter.Parse(parameter.Trim()); } } } diff --git a/Core/Command/CommandValueParameter.cs b/Core/Command/CommandValueParameter.cs deleted file mode 100644 index 892f6218..00000000 --- a/Core/Command/CommandValueParameter.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Text.RegularExpressions; - -namespace KY.Generator.Command -{ - public class CommandValueParameter : CommandParameter - { - private static readonly Regex regex = new Regex(@"^-(?[\w-]+)(=(?.+))?$"); - public string Value { get; } - - public CommandValueParameter(string name, string value) - : base(name) - { - this.Value = value; - } - - public static CommandValueParameter Parse(string text) - { - Match match = regex.Match(text); - if (!match.Success) - { - throw new InvalidOperationException($"Invalid parameter '{text}'"); - } - string name = match.Groups["name"].Value; - string value = match.Groups["value"].Value; - return new CommandValueParameter(name, value); - } - - public override string ToString() - { - return $"-{this.Name}=\"{this.Value}\""; - } - } -} \ No newline at end of file diff --git a/Core/Command/Extensions/ConfigurationBaseExtension.cs b/Core/Command/Extensions/ConfigurationBaseExtension.cs index f2d166be..456fb9b7 100644 --- a/Core/Command/Extensions/ConfigurationBaseExtension.cs +++ b/Core/Command/Extensions/ConfigurationBaseExtension.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using KY.Generator.Configuration; using KY.Generator.Configurations; using KY.Generator.Languages; @@ -12,7 +11,7 @@ public static class ConfigurationBaseExtension public static void ReadFromParameters(this ConfigurationBase configuration, List parameters, List languages) { configuration.VerifySsl = parameters.GetBool(nameof(ConfigurationBase.VerifySsl), configuration.VerifySsl); - configuration.Language = languages.FirstOrDefault(x => x.Name.Equals(parameters.GetString(nameof(ConfigurationBase.Language)), StringComparison.InvariantCultureIgnoreCase))?? configuration.Language; + configuration.Language = languages.FirstOrDefault(x => x.Name.Equals(parameters.GetString(nameof(ConfigurationBase.Language)), StringComparison.InvariantCultureIgnoreCase)) ?? configuration.Language; configuration.AddHeader = parameters.GetBool(nameof(ConfigurationBase.AddHeader), configuration.AddHeader); configuration.AddHeader = !parameters.Exists("skipHeader") && configuration.AddHeader; } diff --git a/Core/Command/ParameterListExtension.cs b/Core/Command/ParameterListExtension.cs index 12c2c2b7..76674277 100644 --- a/Core/Command/ParameterListExtension.cs +++ b/Core/Command/ParameterListExtension.cs @@ -6,17 +6,17 @@ namespace KY.Generator.Command { public static class ParameterListExtension { - public static bool Exists(this IList list, string parameter) + public static bool Exists(this IEnumerable list, string parameter) { return list.Any(x => parameter.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase)); } - public static string GetString(this IList list, string parameter) + public static string GetString(this IEnumerable list, string parameter) { - return list.OfType().FirstOrDefault(x => parameter.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.Value; + return list.FirstOrDefault(x => parameter.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.Value; } - public static bool GetBool(this IList list, string parameter, bool defaultValue = false) + public static bool GetBool(this IEnumerable list, string parameter, bool defaultValue = false) { string value = list.GetString(parameter); if (bool.TrueString.Equals(value, StringComparison.InvariantCultureIgnoreCase) || string.Empty.Equals(value)) @@ -30,13 +30,13 @@ public static bool GetBool(this IList list, string parameter, return defaultValue; } - public static int GetInt(this IList list, string parameter, int defaultValue = default) + public static int GetInt(this IEnumerable list, string parameter, int defaultValue = default) { string value = list.GetString(parameter); return int.TryParse(value, out int result) ? result : defaultValue; } - public static TimeSpan GetTimeSpan(this IList list, string parameter, TimeSpan defaultValue = default) + public static TimeSpan GetTimeSpan(this IEnumerable list, string parameter, TimeSpan defaultValue = default) { string value = list.GetString(parameter); if (string.IsNullOrEmpty(value)) diff --git a/Core/Commands/RunCommand.cs b/Core/Commands/RunCommand.cs index 2c8529a1..eef6efc0 100644 --- a/Core/Commands/RunCommand.cs +++ b/Core/Commands/RunCommand.cs @@ -7,7 +7,6 @@ using KY.Core.Module; using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Module; using KY.Generator.Output; namespace KY.Generator.Commands @@ -90,13 +89,11 @@ private bool Run(List configurations, CommandConfiguration con Logger.Trace("No configuration loaded. Provide at least one entry like: ...\"generate\": [{\"write\": \"demo\"}]..."); return false; } - this.modules.OfType().ForEach(x => x.BeforeRun()); if (configurations.Any(x => x.Configurations.Any(y => !y.VerifySsl))) { ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; } bool success = this.runner.Run(configurations, output, isBeforeBuild); - this.modules.OfType().ForEach(x => x.AfterRun()); Logger.Trace("All configurations generated"); return success; } diff --git a/Core/Generator.cs b/Core/Generator.cs index 64cb0788..4d748b84 100644 --- a/Core/Generator.cs +++ b/Core/Generator.cs @@ -3,14 +3,12 @@ using System.Linq; using System.Reflection; using KY.Core; -using KY.Core.DataAccess; using KY.Core.Dependency; using KY.Core.Module; using KY.Generator.Command; using KY.Generator.Configuration; using KY.Generator.Configurations; using KY.Generator.Mappings; -using KY.Generator.Module; using KY.Generator.Output; using KY.Generator.Syntax; using KY.Generator.Transfer.Readers; @@ -18,20 +16,21 @@ namespace KY.Generator { - public class Generator : IGeneratorRunSyntax + public class Generator : IGeneratorRunSyntax, IGeneratorAfterRunSyntax { private IOutput output; private readonly DependencyResolver resolver; - private bool standalone; - private CommandConfiguration command; + private readonly CommandConfiguration command; + private bool success; private IList Modules { get; } - public Generator() + public Generator(params string[] parameters) { - Logger.CatchAll(); + InitializeLogger(parameters); Logger.Trace($"KY-Generator v{Assembly.GetCallingAssembly().GetName().Version}"); Logger.Trace("Current Directory: " + Environment.CurrentDirectory); Logger.Trace("Log Directory: " + Logger.File.Path); + Logger.Trace($"Parameters: {string.Join(" ", parameters)}"); NugetPackageDependencyLoader.Activate(); @@ -55,11 +54,14 @@ public Generator() } this.Modules.ForEach(module => this.resolver.Bind().To(module)); this.Modules.ForEach(module => module.Initialize()); + + CommandReader reader = this.resolver.Create(); + this.command = reader.Read(parameters); } - public static Generator Initialize() + public static Generator Create(params string[] parameters) { - return new Generator(); + return new Generator(parameters); } public Generator PreloadModule() where T : ModuleBase @@ -106,98 +108,50 @@ public Generator RegisterWriter(string name) return this; } - public IGeneratorRunSyntax ReadConfiguration(string path) - { - Logger.Trace($"Read configuration from {path}"); - this.Modules.OfType().ForEach(x => x.BeforeConfigure()); - this.command = new CommandConfiguration("run"); - this.command.Parameters.Add(new CommandValueParameter("path", path)); - this.command.Standalone = this.standalone; - return this; - } - - public IGeneratorRunSyntax ParseConfiguration(string configuration) + public Generator SetStandalone() { - Logger.Trace($"Parse configuration {configuration}"); - this.Modules.OfType().ForEach(x => x.BeforeConfigure()); - this.command = new CommandConfiguration("run"); - this.command.Parameters.Add(new CommandValueParameter("configuration", configuration)); - this.command.Standalone = this.standalone; + this.command.Standalone = true; return this; } - public IGeneratorRunSyntax ParseCommand(params string[] arguments) + public IGeneratorAfterRunSyntax Run() { - Logger.Trace($"Parse command {string.Join(" ", arguments)}"); - this.Modules.OfType().ForEach(x => x.BeforeConfigure()); - CommandReader reader = this.resolver.Create(); - this.command = reader.Read(arguments); - this.command.Standalone = this.standalone; - CommandValueParameter outputParameter = this.command.Parameters.OfType().FirstOrDefault(x => x.Name.Equals("output", StringComparison.CurrentCultureIgnoreCase)); - if (outputParameter != null) + try { - this.SetOutput(outputParameter.Value); + this.success = this.resolver.Get().Run(this.command, this.output); } - return this; - } - - public IGeneratorRunSyntax SetParameters(params string[] parameters) - { - if (parameters.Length == 0) + catch (Exception exception) { - Logger.Error("No parameters found. Provide at least a command or a path to a configuration file. Generation aborted!"); - return this; + Logger.Error(exception); + this.success = false; } - if (FileSystem.FileExists(parameters.First())) + finally { - this.SetOutput(parameters.Skip(1).FirstOrDefault() ?? FileSystem.Parent(parameters.First())) - .ReadConfiguration(parameters.First()); - CommandReader.SetParameters(this.command, parameters.Skip(2)); - return this; + Logger.Trace("==============================="); } - if (parameters.First().Contains(":\\")) + if (!this.success && Logger.ErrorTargets.Contains(Logger.MsBuildOutput)) { - Logger.Error($"'{parameters.First()}' not found"); - return this; + Logger.Error($"See the full log in: {Logger.File.Path}"); } - return this.ParseCommand(parameters); + return this; } - public Generator SetStandalone() + public bool GetResult() { - this.standalone = true; - if (this.command != null) - { - this.command.Standalone = true; - } - return this; + return this.success; } - public bool Run() + public void SetExitCode() { - bool result; - try - { - result = this.resolver.Get().Run(this.command, this.output); - } - catch (Exception exception) + if (!this.success) { - Logger.Error(exception); - result = false; - } - finally - { - Logger.Trace("==============================="); + Environment.ExitCode = 1; } - if (!result && Logger.ErrorTargets.Contains(Logger.MsBuildOutput)) - { - Logger.Error($"See the full log in: {Logger.File.Path}"); - } - return result; } - public static void InitializeLogger(string[] parameters) + private static void InitializeLogger(string[] parameters) { + Logger.CatchAll(); Logger.AllTargets.Add(Logger.VisualStudioOutput); if (parameters.Any(parameter => parameter.ToLowerInvariant().Contains("forwardlogging"))) { diff --git a/Core/KY.Generator.Core.csproj b/Core/KY.Generator.Core.csproj index bd8ecc5c..3a520516 100644 --- a/Core/KY.Generator.Core.csproj +++ b/Core/KY.Generator.Core.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 3.4.0-rc.1 + 4.0.0-rc.0 Core elements for KY-Generator Download KY.Generator.CLI to use this module 2020 - KY-Programming diff --git a/Core/Module/GeneratorModule.cs b/Core/Module/GeneratorModule.cs deleted file mode 100644 index 14acb55c..00000000 --- a/Core/Module/GeneratorModule.cs +++ /dev/null @@ -1,21 +0,0 @@ -using KY.Core.Dependency; -using KY.Core.Module; - -namespace KY.Generator.Module -{ - public abstract class GeneratorModule : ModuleBase - { - protected GeneratorModule(IDependencyResolver dependencyResolver) - : base(dependencyResolver) - { } - - public virtual void BeforeConfigure() - { } - - public virtual void BeforeRun() - { } - - public virtual void AfterRun() - { } - } -} \ No newline at end of file diff --git a/Core/Syntax/IGeneratorAfterRunSyntax.cs b/Core/Syntax/IGeneratorAfterRunSyntax.cs new file mode 100644 index 00000000..f46415a4 --- /dev/null +++ b/Core/Syntax/IGeneratorAfterRunSyntax.cs @@ -0,0 +1,8 @@ +namespace KY.Generator.Syntax +{ + public interface IGeneratorAfterRunSyntax + { + bool GetResult(); + void SetExitCode(); + } +} \ No newline at end of file diff --git a/Core/Syntax/IGeneratorRunSyntax.cs b/Core/Syntax/IGeneratorRunSyntax.cs index 9a6579ef..1a446613 100644 --- a/Core/Syntax/IGeneratorRunSyntax.cs +++ b/Core/Syntax/IGeneratorRunSyntax.cs @@ -2,6 +2,6 @@ { public interface IGeneratorRunSyntax { - bool Run(); + IGeneratorAfterRunSyntax Run(); } } \ No newline at end of file diff --git a/Csharp/KY.Generator.CSharp.csproj b/Csharp/KY.Generator.CSharp.csproj index 6f5120c2..294587a5 100644 --- a/Csharp/KY.Generator.CSharp.csproj +++ b/Csharp/KY.Generator.CSharp.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 3.3.0 + 4.0.0-rc.0 C# Module for KY-Generator Download KY.Generator.CLI to use this module 2020 - KY-Programming diff --git a/EntityFramework/KY.Generator.EntityFramework.csproj b/EntityFramework/KY.Generator.EntityFramework.csproj index a856296a..7e6e71d7 100644 --- a/EntityFramework/KY.Generator.EntityFramework.csproj +++ b/EntityFramework/KY.Generator.EntityFramework.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 3.3.0 + 4.0.0-rc.0 2020 - KY-Programming EntityFramework Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/Json/KY.Generator.Json.csproj b/Json/KY.Generator.Json.csproj index d93f55fb..549e3088 100644 --- a/Json/KY.Generator.Json.csproj +++ b/Json/KY.Generator.Json.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.3.0 + 4.0.0-rc.0 KY.Generator JSON Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/OData/KY.Generator.OData.csproj b/OData/KY.Generator.OData.csproj index 7a33a960..33cbc412 100644 --- a/OData/KY.Generator.OData.csproj +++ b/OData/KY.Generator.OData.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.4.0-rc.1 + 4.0.0-rc.0 KY.Generator oData Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/OData/ODataModule.cs b/OData/ODataModule.cs index 35d93335..29dea03c 100644 --- a/OData/ODataModule.cs +++ b/OData/ODataModule.cs @@ -1,14 +1,14 @@ using KY.Core.Dependency; +using KY.Core.Module; using KY.Generator.Configuration; using KY.Generator.Mappings; -using KY.Generator.Module; using KY.Generator.OData.Configurations; using KY.Generator.OData.Extensions; using KY.Generator.OData.Readers; namespace KY.Generator.OData { - public class ODataModule : GeneratorModule + public class ODataModule : ModuleBase { public ODataModule(IDependencyResolver dependencyResolver) : base(dependencyResolver) diff --git a/OpenApi/KY.Generator.OpenApi.csproj b/OpenApi/KY.Generator.OpenApi.csproj index 0f8026d8..b842f3a5 100644 --- a/OpenApi/KY.Generator.OpenApi.csproj +++ b/OpenApi/KY.Generator.OpenApi.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.3.0 + 4.0.0-rc.0 KY.Generator OpenApi Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj b/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj index 48ee13a0..f2d852a8 100644 --- a/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj +++ b/Reflection.Annotations/KY.Generator.Reflection.Annotations.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.3.0 + 4.0.0-rc.0 KY.Generator Annotations for Reflection Module for KY-Generator 2020 - KY-Programming diff --git a/Reflection.Tests/InterfaceTest.cs b/Reflection.Tests/InterfaceTest.cs index f57e8202..f717dbe8 100644 --- a/Reflection.Tests/InterfaceTest.cs +++ b/Reflection.Tests/InterfaceTest.cs @@ -9,18 +9,12 @@ namespace KY.Generator.Reflection.Tests [TestClass] public class InterfaceTest { - private Generator generator; private MemoryOutput output; [TestInitialize] public void Initialize() { this.output = new MemoryOutput(); - this.generator = Generator.Initialize() - .PreloadModule() - .PreloadModule() - .PreloadModule() - .SetOutput(this.output); } [TestMethod] @@ -113,16 +107,20 @@ public void ExportedTypeWithPrimitiveTypeTest() private bool RunByTypeName(string typeName) { - return this.generator.SetParameters( - "reflection", - "-name=" + typeName, - "-namespace=KY.Generator.Reflection.Tests", - "-language=TypeScript", - "-skipNamespace", - "-propertiesToFields", - "-formatNames", - "-skipHeader" - ).Run(); + return Generator.Create("reflection", + "-name=" + typeName, + "-namespace=KY.Generator.Reflection.Tests", + "-language=TypeScript", + "-skipNamespace", + "-propertiesToFields", + "-formatNames", + "-skipHeader") + .PreloadModule() + .PreloadModule() + .PreloadModule() + .SetOutput(this.output) + .Run() + .GetResult(); } } } \ No newline at end of file diff --git a/Reflection/KY.Generator.Reflection.csproj b/Reflection/KY.Generator.Reflection.csproj index 2890ed83..50973102 100644 --- a/Reflection/KY.Generator.Reflection.csproj +++ b/Reflection/KY.Generator.Reflection.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.3.0 + 4.0.0-rc.0 KY.Generator Reflection Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/Reflection/ReflectionModule.cs b/Reflection/ReflectionModule.cs index a7a86800..be2c66e3 100644 --- a/Reflection/ReflectionModule.cs +++ b/Reflection/ReflectionModule.cs @@ -1,8 +1,8 @@ using KY.Core.Dependency; +using KY.Core.Module; using KY.Generator.Command; using KY.Generator.Configuration; using KY.Generator.Mappings; -using KY.Generator.Module; using KY.Generator.Reflection.Commands; using KY.Generator.Reflection.Configurations; using KY.Generator.Reflection.Extensions; @@ -11,7 +11,7 @@ namespace KY.Generator.Reflection { - public class ReflectionModule : GeneratorModule + public class ReflectionModule : ModuleBase { public ReflectionModule(IDependencyResolver dependencyResolver) : base(dependencyResolver) @@ -19,9 +19,8 @@ public ReflectionModule(IDependencyResolver dependencyResolver) public override void Initialize() { - //this.DependencyResolver.Bind().ToSingleton(); + this.DependencyResolver.Bind().To(); this.DependencyResolver.Get().Initialize(); - //StaticResolver.GeneratorConfiguration = this.DependencyResolver.Get(); this.DependencyResolver.Bind().ToSelf(); this.DependencyResolver.Bind().ToSelf(); this.DependencyResolver.Bind().ToSelf(); @@ -29,13 +28,5 @@ public override void Initialize() .Map("reflection") .Map("reflection"); } - - public override void BeforeConfigure() - { - //ReflectionGeneratorConfiguration configuration = this.DependencyResolver.Get(); - //this.DependencyResolver.Bind().To(configuration.Generator ?? (IGenerator)this.DependencyResolver.Create(configuration.GeneratorType)); - //this.DependencyResolver.Bind().To(configuration.ConfigurationReader ?? (IConfigurationReader)this.DependencyResolver.Create(configuration.ConfigurationReaderType)); - this.DependencyResolver.Bind().To(); - } } } \ No newline at end of file diff --git a/Tsql/KY.Generator.Tsql.csproj b/Tsql/KY.Generator.Tsql.csproj index 1bcbab0c..5dfc60ca 100644 --- a/Tsql/KY.Generator.Tsql.csproj +++ b/Tsql/KY.Generator.Tsql.csproj @@ -5,7 +5,7 @@ KY-Programming KY-Programming KY.Generator - 3.3.0 + 4.0.0-rc.0 TSQL Module for KY-Generator Download KY.Generator.CLI to use this module 2020 - KY-Programming diff --git a/Tsql/TsqlModule.cs b/Tsql/TsqlModule.cs index 65afc2c5..72ddb657 100644 --- a/Tsql/TsqlModule.cs +++ b/Tsql/TsqlModule.cs @@ -1,14 +1,14 @@ using KY.Core.Dependency; +using KY.Core.Module; using KY.Generator.Configuration; using KY.Generator.Mappings; -using KY.Generator.Module; using KY.Generator.Tsql.Configurations; using KY.Generator.Tsql.Language; using KY.Generator.Tsql.Readers; namespace KY.Generator.Tsql { - public class TsqlModule : GeneratorModule + public class TsqlModule : ModuleBase { public TsqlModule(IDependencyResolver dependencyResolver) : base(dependencyResolver) diff --git a/TypeScript/KY.Generator.TypeScript.csproj b/TypeScript/KY.Generator.TypeScript.csproj index 973de654..92c5dacb 100644 --- a/TypeScript/KY.Generator.TypeScript.csproj +++ b/TypeScript/KY.Generator.TypeScript.csproj @@ -4,7 +4,7 @@ netstandard2.0 KY-Programming KY-Programming - 3.3.0 + 4.0.0-rc.0 KY.Generator TypeScript Module for KY-Generator Download KY.Generator.CLI to use this module diff --git a/Watchdog/Commands/WatchdogCommand.cs b/Watchdog/Commands/WatchdogCommand.cs index 1e065ec1..bdb608e8 100644 --- a/Watchdog/Commands/WatchdogCommand.cs +++ b/Watchdog/Commands/WatchdogCommand.cs @@ -91,11 +91,7 @@ public bool Generate(CommandConfiguration configuration, ref IOutput output) private CommandParameter MapParameter(CommandParameter parameter, string command) { string name = parameter.Name.TrimStart($"{command}-"); - if (parameter is CommandValueParameter valueParameter) - { - return new CommandValueParameter(name, valueParameter.Value); - } - return new CommandParameter(name); + return new CommandParameter(name, parameter.Value); } } } \ No newline at end of file diff --git a/Watchdog/KY.Generator.Watchdog.csproj b/Watchdog/KY.Generator.Watchdog.csproj index af01ec49..6379d71b 100644 --- a/Watchdog/KY.Generator.Watchdog.csproj +++ b/Watchdog/KY.Generator.Watchdog.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 3.3.0 + 4.0.0-rc.0 KY-Programming KY-Programming KY.Generator From cc83d849e3db16fbfa1ef9b529b63e4571fe94e5 Mon Sep 17 00:00:00 2001 From: KY Date: Fri, 17 Jan 2020 05:48:11 +0100 Subject: [PATCH 2/4] Core - replace transfer reader/writer with command (incomplete) - read configurations from command parameters - command parameter converters added - command register added WARNING: this commit does not builds --- .../KY.Generator.Angular.Tests.csproj | 2 +- Angular/KY.Generator.Angular.csproj | 2 +- Angular/Templates/generator.json | 17 ---- .../KY.Generator.AspDotNet.Tests.csproj | 2 +- AspDotNet/KY.Generator.AspDotNet.csproj | 2 +- .../KY.Generator.CLI.Core.Full.csproj | 2 +- .../KY.Generator.CLI.Core.Minimal.csproj | 2 +- .../KY.Generator.CLI.Core.Standalone.csproj | 2 +- CLI.Core/KY.Generator.CLI.Core.csproj | 2 +- CLI.Full/KY.Generator.CLI.Full.csproj | 4 +- CLI.Full/packages.config | 2 +- CLI.Minimal/KY.Generator.CLI.Minimal.csproj | 4 +- CLI.Minimal/packages.config | 2 +- .../KY.Generator.CLI.Standalone.csproj | 4 +- CLI.Standalone/packages.config | 2 +- CLI/KY.Generator.CLI.csproj | 4 +- CLI/packages.config | 2 +- Core.Tests/CaseTest.cs | 4 + Core.Tests/CommandReaderTests.cs | 84 +++++++++++++++++++ Core.Tests/CommandRegisterTests.cs | 83 ++++++++++++++++++ Core.Tests/KY.Generator.Core.Tests.csproj | 2 +- Core.Tests/Models/TestCommand.cs | 13 +++ Core.Tests/Models/TestConfiguration.cs | 3 + Core/Client/GeneratorClient.cs | 7 -- Core/Command/CommandConfiguration.cs | 20 ----- Core/Command/CommandParameterConverters.cs | 41 +++++++++ Core/Command/CommandReader.cs | 63 +++++++++++--- Core/Command/CommandRegister.cs | 81 ++++++++++++++++++ Core/Command/CommandRunner.cs | 19 ++--- .../Extensions/ConfigurationBaseExtension.cs | 19 ----- Core/Command/IGeneratorCommand.cs | 5 +- Core/Command/ParameterListExtension.cs | 54 ------------ Core/Command/VariableCommandGenerator.cs | 41 --------- Core/{ => Commands}/Client/ClientCommand.cs | 0 .../Client/GeneratorClientConfiguration.cs | 0 .../Client/GeneratorConfiguration.cs | 0 .../Client/GeneratorGenerator.cs | 0 .../Template}/TemplateSyntax.cs | 0 Core/Commands/VersionCommand.cs | 13 +-- .../Configuration/ConfigurationEnvironment.cs | 5 ++ .../ConfigurationIgnoreAttribute.cs | 9 ++ .../ConfigurationPropertyAttribute.cs | 15 ++++ .../ConfigurationPropertyConverter.cs | 7 ++ ...ConfigurationPropertyConverterAttribute.cs | 15 ++++ Core/Configurations/ConfigurationBase.cs | 20 ++++- Core/Configurations/IConfiguration.cs | 3 + Core/Configurations/TemplateConfiguration.cs | 5 ++ Core/Configurations/VersionConfiguration.cs | 10 +++ Core/CoreModule.cs | 12 ++- Core/Exceptions/AmbiguousCommandException.cs | 11 +++ Core/Exceptions/CommandNotFoundException.cs | 11 +++ ...mandParameterConverterNotFoundException.cs | 12 +++ ...ConfigurationParameterReadOnlyException.cs | 11 +++ Core/Extensions/StringExtensions.cs | 23 ++++- Core/Generator.cs | 44 +++------- Core/KY.Generator.Core.csproj | 2 +- Csharp.Tests/KY.Generator.Csharp.Tests.csproj | 2 +- Csharp/KY.Generator.CSharp.csproj | 2 +- .../KY.Generator.EntityFramework.csproj | 2 +- Json.Tests/KY.Generator.Json.Tests.csproj | 2 +- Json/KY.Generator.Json.csproj | 2 +- OData.Tests/KY.Generator.OData.Tests.csproj | 2 +- OData/KY.Generator.OData.csproj | 2 +- OpenApi/KY.Generator.OpenApi.csproj | 2 +- .../KY.Generator.Reflection.Tests.csproj | 2 +- Reflection/KY.Generator.Reflection.csproj | 2 +- Tests/KY.Generator.Tests.csproj | 2 +- Tsql.Tests/KY.Generator.Tsql.Tests.csproj | 2 +- Tsql/KY.Generator.Tsql.csproj | 2 +- .../KY.Generator.TypeScript.Tests.csproj | 2 +- TypeScript/KY.Generator.TypeScript.csproj | 2 +- .../Configurations/WatchdogConfiguration.cs | 17 ++++ Watchdog/KY.Generator.Watchdog.csproj | 2 +- 73 files changed, 604 insertions(+), 269 deletions(-) delete mode 100644 Angular/Templates/generator.json create mode 100644 Core.Tests/CommandReaderTests.cs create mode 100644 Core.Tests/CommandRegisterTests.cs create mode 100644 Core.Tests/Models/TestCommand.cs delete mode 100644 Core/Client/GeneratorClient.cs delete mode 100644 Core/Command/CommandConfiguration.cs create mode 100644 Core/Command/CommandParameterConverters.cs create mode 100644 Core/Command/CommandRegister.cs delete mode 100644 Core/Command/Extensions/ConfigurationBaseExtension.cs delete mode 100644 Core/Command/ParameterListExtension.cs delete mode 100644 Core/Command/VariableCommandGenerator.cs rename Core/{ => Commands}/Client/ClientCommand.cs (100%) rename Core/{ => Commands}/Client/GeneratorClientConfiguration.cs (100%) rename Core/{ => Commands}/Client/GeneratorConfiguration.cs (100%) rename Core/{ => Commands}/Client/GeneratorGenerator.cs (100%) rename Core/{Command => Commands/Template}/TemplateSyntax.cs (100%) create mode 100644 Core/Configuration/ConfigurationIgnoreAttribute.cs create mode 100644 Core/Configuration/ConfigurationPropertyAttribute.cs create mode 100644 Core/Configuration/ConfigurationPropertyConverter.cs create mode 100644 Core/Configuration/ConfigurationPropertyConverterAttribute.cs create mode 100644 Core/Configurations/TemplateConfiguration.cs create mode 100644 Core/Configurations/VersionConfiguration.cs create mode 100644 Core/Exceptions/AmbiguousCommandException.cs create mode 100644 Core/Exceptions/CommandNotFoundException.cs create mode 100644 Core/Exceptions/CommandParameterConverterNotFoundException.cs create mode 100644 Core/Exceptions/ConfigurationParameterReadOnlyException.cs create mode 100644 Watchdog/Configurations/WatchdogConfiguration.cs diff --git a/Angular.Tests/KY.Generator.Angular.Tests.csproj b/Angular.Tests/KY.Generator.Angular.Tests.csproj index 2c03559b..d68a7c72 100644 --- a/Angular.Tests/KY.Generator.Angular.Tests.csproj +++ b/Angular.Tests/KY.Generator.Angular.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Angular/KY.Generator.Angular.csproj b/Angular/KY.Generator.Angular.csproj index 868616b0..3a4e336e 100644 --- a/Angular/KY.Generator.Angular.csproj +++ b/Angular/KY.Generator.Angular.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Angular/Templates/generator.json b/Angular/Templates/generator.json deleted file mode 100644 index 34f2d73b..00000000 --- a/Angular/Templates/generator.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "Generator": { - "Connection": "$url$/Generator", - "VerifySsl": false - }, - "Language": "TypeScript", - "OData": { - "Connection": "$url$/odata/$metadata", - "SkipNamespace": true, - "DataContext": { - "RelativePath": "src\\models" - }, - "Models": { - "RelativePath": "src\\models" - } - } -} \ No newline at end of file diff --git a/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj b/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj index a188443a..c779a640 100644 --- a/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj +++ b/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/AspDotNet/KY.Generator.AspDotNet.csproj b/AspDotNet/KY.Generator.AspDotNet.csproj index 3b3b7605..9d576b70 100644 --- a/AspDotNet/KY.Generator.AspDotNet.csproj +++ b/AspDotNet/KY.Generator.AspDotNet.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj b/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj index 356b6d02..fd75ece2 100644 --- a/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj +++ b/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj b/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj index 0341fb8f..5ec53a39 100644 --- a/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj +++ b/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj b/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj index 356b6d02..fd75ece2 100644 --- a/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj +++ b/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Core/KY.Generator.CLI.Core.csproj b/CLI.Core/KY.Generator.CLI.Core.csproj index 356b6d02..fd75ece2 100644 --- a/CLI.Core/KY.Generator.CLI.Core.csproj +++ b/CLI.Core/KY.Generator.CLI.Core.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Full/KY.Generator.CLI.Full.csproj b/CLI.Full/KY.Generator.CLI.Full.csproj index b1b54fdc..81d7db68 100644 --- a/CLI.Full/KY.Generator.CLI.Full.csproj +++ b/CLI.Full/KY.Generator.CLI.Full.csproj @@ -35,8 +35,8 @@ 4 - - ..\packages\KY.Core.Common.4.8.0\lib\netstandard2.0\KY.Core.Common.dll + + ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI.Full/packages.config b/CLI.Full/packages.config index 9f911f48..208d971b 100644 --- a/CLI.Full/packages.config +++ b/CLI.Full/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/CLI.Minimal/KY.Generator.CLI.Minimal.csproj b/CLI.Minimal/KY.Generator.CLI.Minimal.csproj index 9c814ad1..68a3e308 100644 --- a/CLI.Minimal/KY.Generator.CLI.Minimal.csproj +++ b/CLI.Minimal/KY.Generator.CLI.Minimal.csproj @@ -36,8 +36,8 @@ 4 - - ..\packages\KY.Core.Common.4.8.0\lib\netstandard2.0\KY.Core.Common.dll + + ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI.Minimal/packages.config b/CLI.Minimal/packages.config index 9f911f48..208d971b 100644 --- a/CLI.Minimal/packages.config +++ b/CLI.Minimal/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/CLI.Standalone/KY.Generator.CLI.Standalone.csproj b/CLI.Standalone/KY.Generator.CLI.Standalone.csproj index 8d96df53..572f5886 100644 --- a/CLI.Standalone/KY.Generator.CLI.Standalone.csproj +++ b/CLI.Standalone/KY.Generator.CLI.Standalone.csproj @@ -41,8 +41,8 @@ ..\packages\Costura.Fody.3.3.2\lib\net40\Costura.dll - - ..\packages\KY.Core.Common.4.8.0\lib\netstandard2.0\KY.Core.Common.dll + + ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI.Standalone/packages.config b/CLI.Standalone/packages.config index 229ac691..825b6a1a 100644 --- a/CLI.Standalone/packages.config +++ b/CLI.Standalone/packages.config @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/CLI/KY.Generator.CLI.csproj b/CLI/KY.Generator.CLI.csproj index baff2e5a..28c23ee7 100644 --- a/CLI/KY.Generator.CLI.csproj +++ b/CLI/KY.Generator.CLI.csproj @@ -36,8 +36,8 @@ 4 - - ..\packages\KY.Core.Common.4.8.0\lib\netstandard2.0\KY.Core.Common.dll + + ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI/packages.config b/CLI/packages.config index 9f911f48..208d971b 100644 --- a/CLI/packages.config +++ b/CLI/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Core.Tests/CaseTest.cs b/Core.Tests/CaseTest.cs index f80e946d..806a9509 100644 --- a/Core.Tests/CaseTest.cs +++ b/Core.Tests/CaseTest.cs @@ -15,11 +15,13 @@ public void TestPascalAllLower() { Assert.AreEqual("Alllower", "alllower".ToPascalCase()); } + [TestMethod] public void TestPascalAllLowerNumber() { Assert.AreEqual("Alllower1", "alllower1".ToPascalCase()); } + [TestMethod] public void TestPascalAllLowerNumbers() { @@ -149,11 +151,13 @@ public void TestCamelAllLower() { Assert.AreEqual("alllower", "alllower".ToCamelCase()); } + [TestMethod] public void TestCamelAllLowerNumber() { Assert.AreEqual("alllower1", "alllower1".ToCamelCase()); } + [TestMethod] public void TestCamelAllLowerNumbers() { diff --git a/Core.Tests/CommandReaderTests.cs b/Core.Tests/CommandReaderTests.cs new file mode 100644 index 00000000..1d9bb4f6 --- /dev/null +++ b/Core.Tests/CommandReaderTests.cs @@ -0,0 +1,84 @@ +using System.Collections.Generic; +using KY.Core.Dependency; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Configurations; +using KY.Generator.Core.Tests.Models; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace KY.Generator.Core.Tests +{ + [TestClass] + public class CommandReaderTests + { + private CommandRegister commands; + private CommandReader reader; + + [TestInitialize] + public void Initialize() + { + this.commands = new CommandRegister(new DependencyResolver()); + this.reader = new CommandReader(this.commands); + } + + [TestMethod] + public void TestReadString() + { + this.commands.Register("test"); + List parameters = new List{ "test", "-test=Test"}; + StringConfiguration configuration = this.reader.Read(parameters) as StringConfiguration; + Assert.IsNotNull(configuration, "Read failed"); + Assert.AreEqual("Test", configuration.Test); + } + + [TestMethod] + public void TestReadInt() + { + this.commands.Register("test"); + List parameters = new List{ "test", "-test=123"}; + IntConfiguration configuration = this.reader.Read(parameters) as IntConfiguration; + Assert.IsNotNull(configuration, "Read failed"); + Assert.AreEqual(123, configuration.Test); + } + + [TestMethod] + public void TestReadCustomType() + { + this.commands.Register("test"); + List parameters = new List{ "test", "-test=~1~2~3~"}; + CustomTypeConfiguration configuration = this.reader.Read(parameters) as CustomTypeConfiguration; + Assert.IsNotNull(configuration, "Read failed"); + Assert.IsNotNull(configuration.Test); + Assert.AreEqual(123, configuration.Test.Value); + } + + private class StringConfiguration : TestConfiguration + { + public string Test { get; set; } + } + + private class IntConfiguration : TestConfiguration + { + public int Test { get; set; } + } + + private class CustomTypeConfiguration : TestConfiguration + { + [ConfigurationPropertyConverter(typeof(CustomTypeConverter))] + public CustomType Test { get; set; } + + public class CustomType + { + public int Value { get; set; } + } + + public class CustomTypeConverter : ConfigurationPropertyConverter + { + public override object Convert(string value) + { + return new CustomType { Value = int.Parse(value.Replace("~", string.Empty)) }; + } + } + } + } +} \ No newline at end of file diff --git a/Core.Tests/CommandRegisterTests.cs b/Core.Tests/CommandRegisterTests.cs new file mode 100644 index 00000000..c9b42fba --- /dev/null +++ b/Core.Tests/CommandRegisterTests.cs @@ -0,0 +1,83 @@ +using System; +using KY.Core.Dependency; +using KY.Generator.Command; +using KY.Generator.Core.Tests.Models; +using KY.Generator.Exceptions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace KY.Generator.Core.Tests +{ + [TestClass] + public class CommandRegisterTests + { + private CommandRegister commands; + + [TestInitialize] + public void Initialize() + { + this.commands = new CommandRegister(new DependencyResolver()); + } + + [TestMethod] + [ExpectedException(typeof(InvalidOperationException))] + public void RegisterAmbiguousCommands() + { + this.commands + .Register("test", "group") + .Register("test", "group"); + } + + [TestMethod] + [ExpectedException(typeof(AmbiguousCommandException))] + public void TestAmbiguousCommandName() + { + this.commands + .Register("test", "group1") + .Register("test", "group2"); + this.commands.CreateConfiguration("test"); + } + + [TestMethod] + [ExpectedException(typeof(CommandNotFoundException))] + public void TestCommandNotFound() + { + this.commands.CreateConfiguration("test"); + } + + [TestMethod] + public void TestOneGroupOneCommands() + { + this.commands.Register("test1", "group1"); + Assert.IsNotNull(this.commands.CreateConfiguration("test1")); + } + + [TestMethod] + public void TestOneGroupMultipleCommands() + { + this.commands + .Register("test1", "group1") + .Register("test2", "group1"); + Assert.IsNotNull(this.commands.CreateConfiguration("test1")); + } + + [TestMethod] + public void TestMultipleGroupsOneCommands() + { + this.commands + .Register("test", "group1") + .Register("test", "group2"); + Assert.IsNotNull(this.commands.CreateConfiguration("group2-test")); + } + + [TestMethod] + public void TestMultipleGroupsMultipleCommands() + { + this.commands + .Register("test1", "group1") + .Register("test1", "group2") + .Register("test2", "group1") + .Register("test2", "group2"); + Assert.IsNotNull(this.commands.CreateConfiguration("group2-test1")); + } + } +} \ No newline at end of file diff --git a/Core.Tests/KY.Generator.Core.Tests.csproj b/Core.Tests/KY.Generator.Core.Tests.csproj index 6a70af44..96fccec6 100644 --- a/Core.Tests/KY.Generator.Core.Tests.csproj +++ b/Core.Tests/KY.Generator.Core.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Core.Tests/Models/TestCommand.cs b/Core.Tests/Models/TestCommand.cs new file mode 100644 index 00000000..452a6b7d --- /dev/null +++ b/Core.Tests/Models/TestCommand.cs @@ -0,0 +1,13 @@ +using KY.Generator.Command; +using KY.Generator.Configurations; + +namespace KY.Generator.Core.Tests.Models +{ + internal class TestCommand : IGeneratorCommand + { + public bool Execute(IConfiguration configuration) + { + return true; + } + } +} \ No newline at end of file diff --git a/Core.Tests/Models/TestConfiguration.cs b/Core.Tests/Models/TestConfiguration.cs index 749b7d94..1b601911 100644 --- a/Core.Tests/Models/TestConfiguration.cs +++ b/Core.Tests/Models/TestConfiguration.cs @@ -2,6 +2,7 @@ using KY.Generator.Configuration; using KY.Generator.Configurations; using KY.Generator.Languages; +using KY.Generator.Output; namespace KY.Generator.Core.Tests.Models { @@ -16,6 +17,8 @@ internal class TestConfiguration : IModelConfiguration public bool FormatNames { get; set; } public ILanguage Language { get; set; } public ConfigurationFormatting Formatting { get; } + public IOutput Output { get; set; } + public ConfigurationEnvironment Environment { get; set; } public TestConfiguration() { diff --git a/Core/Client/GeneratorClient.cs b/Core/Client/GeneratorClient.cs deleted file mode 100644 index c484c7ac..00000000 --- a/Core/Client/GeneratorClient.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace KY.Generator.Client -{ - public class GeneratorClient - { - - } -} \ No newline at end of file diff --git a/Core/Command/CommandConfiguration.cs b/Core/Command/CommandConfiguration.cs deleted file mode 100644 index 6df8a861..00000000 --- a/Core/Command/CommandConfiguration.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Collections.Generic; -using KY.Generator.Configurations; -using KY.Generator.Languages; - -namespace KY.Generator.Command -{ - public class CommandConfiguration : ConfigurationBase - { - public override bool RequireLanguage => false; - public string Command { get; } - public List Parameters { get; } - - public CommandConfiguration(string command, List parameters = default) - { - this.Command = command; - this.Parameters = parameters ?? new List(); - this.Language = new ForwardFileLanguage(); - } - } -} \ No newline at end of file diff --git a/Core/Command/CommandParameterConverters.cs b/Core/Command/CommandParameterConverters.cs new file mode 100644 index 00000000..0f4087e0 --- /dev/null +++ b/Core/Command/CommandParameterConverters.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using KY.Generator.Configuration; +using KY.Generator.Exceptions; + +namespace KY.Generator.Command +{ + public static class CommandParameterConverters + { + private static readonly Dictionary> converters; + + static CommandParameterConverters() + { + converters = new Dictionary>(); + converters.Add(typeof(string), value => value); + converters.Add(typeof(int), value => int.Parse(value)); + converters.Add(typeof(long), value => long.Parse(value)); + converters.Add(typeof(float), value => float.Parse(value)); + converters.Add(typeof(double), value => double.Parse(value)); + converters.Add(typeof(decimal), value => decimal.Parse(value)); + converters.Add(typeof(TimeSpan), value => TimeSpan.Parse(value)); + converters.Add(typeof(DateTime), value => DateTime.Parse(value)); + } + + public static object Convert(string value, PropertyInfo property) + { + ConfigurationPropertyConverterAttribute attribute = property.GetCustomAttribute(); + if (attribute != null) + { + ConfigurationPropertyConverter converter = (ConfigurationPropertyConverter)Activator.CreateInstance(attribute.ConverterType); + return converter.Convert(value); + } + if (!converters.ContainsKey(property.PropertyType)) + { + throw new CommandParameterConverterNotFoundException(property.PropertyType); + } + return converters[property.PropertyType](value); + } + } +} \ No newline at end of file diff --git a/Core/Command/CommandReader.cs b/Core/Command/CommandReader.cs index 888fd265..eb24ae69 100644 --- a/Core/Command/CommandReader.cs +++ b/Core/Command/CommandReader.cs @@ -1,25 +1,29 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; +using System.Reflection; using KY.Core; -using KY.Generator.Command.Extensions; -using KY.Generator.Languages; +using KY.Generator.Configuration; +using KY.Generator.Configurations; +using KY.Generator.Exceptions; +using KY.Generator.Extensions; namespace KY.Generator.Command { - internal class CommandReader + public class CommandReader { - private readonly List languages; + private readonly CommandRegister commands; - public CommandReader(List languages) + public CommandReader(CommandRegister commands) { - this.languages = languages; + this.commands = commands; } - public CommandConfiguration Read(params string[] parameters) + public IConfiguration Read(List parameters) { - if (parameters.Length == 0) + if (parameters.Count == 0) { - Logger.Error("No command found. Provide at least one command like 'run -configuration=\"\"'"); + Logger.Error("No command found. Provide at least one command like 'KY.Generator run -configuration=\"\"' or 'KY.Generator version'"); return null; } List commandList = parameters.Where(x => !x.StartsWith("-")).ToList(); @@ -29,8 +33,15 @@ public CommandConfiguration Read(params string[] parameters) return null; } List commandParameters = this.ReadParameters(parameters.Where(x => x.StartsWith("-"))).ToList(); - CommandConfiguration configuration = new CommandConfiguration(commandList.Single(), commandParameters); - configuration.ReadFromParameters(configuration.Parameters, this.languages); + + IConfiguration configuration = this.commands.CreateConfiguration(commandList.Single()); + if (configuration == null) + { + Logger.Error($"Command '{commandList.Single()}' not found"); + return null; + } + configuration.Environment?.Parameters.AddRange(commandParameters); + this.SetParameters(configuration, commandParameters); return configuration; } @@ -41,5 +52,33 @@ private IEnumerable ReadParameters(IEnumerable paramet yield return CommandParameter.Parse(parameter.Trim()); } } + + private void SetParameters(IConfiguration configuration, List parameters) + { + parameters.AssertIsNotNull(nameof(parameters)); + Type type = configuration.GetType(); + Dictionary properties = new Dictionary(); + foreach (PropertyInfo property in type.GetProperties()) + { + properties.Add(property.Name, property); + property.GetCustomAttributes().ForEach(attribute => properties.Add(attribute.Alias, property)); + } + foreach (CommandParameter parameter in parameters) + { + string parameterName = parameter.Name.ToPascalCase(); + if (!properties.ContainsKey(parameterName)) + { + Logger.Warning($"Unknown parameter '{parameterName}'. No matching property in {type.Name} found. Add a matching property or use [{nameof(ConfigurationPropertyAttribute).Replace("Attribute", string.Empty)}(\"{parameterName}\")]."); + continue; + } + PropertyInfo propertyInfo = properties[parameterName]; + if (!propertyInfo.CanWrite) + { + throw new ConfigurationParameterReadOnlyException(parameterName); + } + object value = CommandParameterConverters.Convert(parameter.Value, propertyInfo); + propertyInfo.SetValue(configuration, value); + } + } } } \ No newline at end of file diff --git a/Core/Command/CommandRegister.cs b/Core/Command/CommandRegister.cs new file mode 100644 index 00000000..e41cc8b8 --- /dev/null +++ b/Core/Command/CommandRegister.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using KY.Core; +using KY.Core.Dependency; +using KY.Generator.Configurations; +using KY.Generator.Exceptions; + +namespace KY.Generator.Command +{ + public class CommandRegister + { + public const string DefaultGroup = "execute"; + private readonly IDependencyResolver resolver; + private readonly List entries; + + public CommandRegister(IDependencyResolver resolver) + { + this.resolver = resolver.AssertIsNotNull(nameof(resolver)); + this.entries = new List(); + } + + public CommandRegister Register(string name, string group = DefaultGroup) + where TCommand : IGeneratorCommand + where TConfiguration : IConfiguration + { + group = string.IsNullOrWhiteSpace(group) ? DefaultGroup : group; + if (this.entries.Any(entry => entry.Group.Equals(group, StringComparison.InvariantCultureIgnoreCase) && entry.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))) + { + throw new InvalidOperationException($"{name} ({group}) is already mapped. Please use a prefix like my-{name}"); + } + this.entries.Add(new RegisterEntry + { + Name = name, + Group = group, + Command = typeof(TCommand), + Configuration = typeof(TConfiguration) + }); + return this; + } + + private RegisterEntry Find(string command) + { + List found = this.entries.Where(entry => entry.Name.Equals(command, StringComparison.InvariantCultureIgnoreCase)).ToList(); + if (found.Count > 1) + { + throw new AmbiguousCommandException($"Ambiguous command '{command}'. Use {string.Join(" or ", found.Select(x => $"'{x.Group}-{x.Name}'"))} instead."); + } + if (found.Count == 0) + { + found = this.entries.Where(entry => $"{entry.Group}-{entry.Name}".Equals(command, StringComparison.InvariantCultureIgnoreCase)).ToList(); + } + if (found.Count == 0) + { + throw new CommandNotFoundException(command); + } + return found.Single(); + } + + public IConfiguration CreateConfiguration(string command) + { + RegisterEntry entry = this.Find(command); + return entry == null ? null : this.resolver.Create(entry.Configuration) as IConfiguration; + } + + public IGeneratorCommand CreateCommand(IConfiguration configuration) + { + Type type = configuration.GetType(); + RegisterEntry entry = this.entries.FirstOrDefault(x => x.Configuration == type); + return entry == null ? null : this.resolver.Create(entry.Command) as IGeneratorCommand; + } + + private class RegisterEntry + { + public string Name { get; set; } + public string Group { get; set; } + public Type Command { get; set; } + public Type Configuration { get; set; } + } + } +} \ No newline at end of file diff --git a/Core/Command/CommandRunner.cs b/Core/Command/CommandRunner.cs index 59256159..149c1f36 100644 --- a/Core/Command/CommandRunner.cs +++ b/Core/Command/CommandRunner.cs @@ -1,32 +1,25 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using KY.Core; +using KY.Generator.Configurations; using KY.Generator.Output; namespace KY.Generator.Command { public class CommandRunner { - private readonly List commands; + private readonly CommandRegister commands; - public CommandRunner(List commands) + public CommandRunner(CommandRegister commands) { this.commands = commands; } - public bool Run(CommandConfiguration configuration, IOutput output) + public bool Run(IConfiguration configuration, IOutput output) { if (configuration == null) { return false; } - List commandsToRun = this.commands.Where(x => x.Names.Any(name => name.Equals(configuration.Command, StringComparison.InvariantCultureIgnoreCase))).ToList(); - if (commandsToRun.Count == 0) - { - Logger.Error($"Command '{configuration.Command}' not found"); - } - bool success = commandsToRun.Select(x => x.Generate(configuration, ref output)).ToList().Any(x => x); + IGeneratorCommand command = this.commands.CreateCommand(configuration); + bool success = command.Execute(configuration); if (success) { output.Execute(); diff --git a/Core/Command/Extensions/ConfigurationBaseExtension.cs b/Core/Command/Extensions/ConfigurationBaseExtension.cs deleted file mode 100644 index 456fb9b7..00000000 --- a/Core/Command/Extensions/ConfigurationBaseExtension.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using KY.Generator.Configurations; -using KY.Generator.Languages; - -namespace KY.Generator.Command.Extensions -{ - public static class ConfigurationBaseExtension - { - public static void ReadFromParameters(this ConfigurationBase configuration, List parameters, List languages) - { - configuration.VerifySsl = parameters.GetBool(nameof(ConfigurationBase.VerifySsl), configuration.VerifySsl); - configuration.Language = languages.FirstOrDefault(x => x.Name.Equals(parameters.GetString(nameof(ConfigurationBase.Language)), StringComparison.InvariantCultureIgnoreCase)) ?? configuration.Language; - configuration.AddHeader = parameters.GetBool(nameof(ConfigurationBase.AddHeader), configuration.AddHeader); - configuration.AddHeader = !parameters.Exists("skipHeader") && configuration.AddHeader; - } - } -} \ No newline at end of file diff --git a/Core/Command/IGeneratorCommand.cs b/Core/Command/IGeneratorCommand.cs index 51ffdd26..61097b8a 100644 --- a/Core/Command/IGeneratorCommand.cs +++ b/Core/Command/IGeneratorCommand.cs @@ -1,10 +1,9 @@ -using KY.Generator.Output; +using KY.Generator.Configurations; namespace KY.Generator.Command { public interface IGeneratorCommand { - string[] Names { get; } - bool Generate(CommandConfiguration configuration, ref IOutput output); + bool Execute(IConfiguration configurationBase); } } \ No newline at end of file diff --git a/Core/Command/ParameterListExtension.cs b/Core/Command/ParameterListExtension.cs deleted file mode 100644 index 76674277..00000000 --- a/Core/Command/ParameterListExtension.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace KY.Generator.Command -{ - public static class ParameterListExtension - { - public static bool Exists(this IEnumerable list, string parameter) - { - return list.Any(x => parameter.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase)); - } - - public static string GetString(this IEnumerable list, string parameter) - { - return list.FirstOrDefault(x => parameter.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.Value; - } - - public static bool GetBool(this IEnumerable list, string parameter, bool defaultValue = false) - { - string value = list.GetString(parameter); - if (bool.TrueString.Equals(value, StringComparison.InvariantCultureIgnoreCase) || string.Empty.Equals(value)) - { - return true; - } - if (bool.FalseString.Equals(value, StringComparison.InvariantCultureIgnoreCase)) - { - return false; - } - return defaultValue; - } - - public static int GetInt(this IEnumerable list, string parameter, int defaultValue = default) - { - string value = list.GetString(parameter); - return int.TryParse(value, out int result) ? result : defaultValue; - } - - public static TimeSpan GetTimeSpan(this IEnumerable list, string parameter, TimeSpan defaultValue = default) - { - string value = list.GetString(parameter); - if (string.IsNullOrEmpty(value)) - { - return defaultValue; - } - if ((value.Contains(".") || value.Contains(":")) && TimeSpan.TryParse(value, out TimeSpan timeSpan)) - { - return timeSpan; - } - return int.TryParse(value, out int result) ? TimeSpan.FromMilliseconds(result) : defaultValue; - - } - } -} \ No newline at end of file diff --git a/Core/Command/VariableCommandGenerator.cs b/Core/Command/VariableCommandGenerator.cs deleted file mode 100644 index 234f7ff6..00000000 --- a/Core/Command/VariableCommandGenerator.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using KY.Core; -using KY.Core.Extension; -using KY.Generator.Output; - -namespace KY.Generator.Command -{ - public abstract class VariableCommandGenerator : IGeneratorCommand - { - public abstract string[] Names { get; } - public abstract string SubCommand { get; } - public virtual List RequiredParameters => new List(); - - public bool Generate(CommandConfiguration configuration, ref IOutput output) - { - Logger.Trace("Execute variable command..."); - if (configuration.Parameters.All(x => !x.Name.Equals(this.SubCommand, StringComparison.InvariantCultureIgnoreCase))) - { - return false; - } - foreach (string requiredParameter in this.RequiredParameters) - { - if (configuration.Parameters.All(available => !requiredParameter.Equals(available.Name, StringComparison.InvariantCultureIgnoreCase))) - { - throw new ArgumentNullException(requiredParameter); - } - } - this.OnGenerate(configuration, ref output); - return true; - } - - protected abstract void OnGenerate(CommandConfiguration configuration, ref IOutput output); - - protected TemplateSyntax GetTemplate(string template) - { - return new TemplateSyntax(template, this.GetType().Assembly.GetManifestResourceString(template)); - } - } -} \ No newline at end of file diff --git a/Core/Client/ClientCommand.cs b/Core/Commands/Client/ClientCommand.cs similarity index 100% rename from Core/Client/ClientCommand.cs rename to Core/Commands/Client/ClientCommand.cs diff --git a/Core/Client/GeneratorClientConfiguration.cs b/Core/Commands/Client/GeneratorClientConfiguration.cs similarity index 100% rename from Core/Client/GeneratorClientConfiguration.cs rename to Core/Commands/Client/GeneratorClientConfiguration.cs diff --git a/Core/Client/GeneratorConfiguration.cs b/Core/Commands/Client/GeneratorConfiguration.cs similarity index 100% rename from Core/Client/GeneratorConfiguration.cs rename to Core/Commands/Client/GeneratorConfiguration.cs diff --git a/Core/Client/GeneratorGenerator.cs b/Core/Commands/Client/GeneratorGenerator.cs similarity index 100% rename from Core/Client/GeneratorGenerator.cs rename to Core/Commands/Client/GeneratorGenerator.cs diff --git a/Core/Command/TemplateSyntax.cs b/Core/Commands/Template/TemplateSyntax.cs similarity index 100% rename from Core/Command/TemplateSyntax.cs rename to Core/Commands/Template/TemplateSyntax.cs diff --git a/Core/Commands/VersionCommand.cs b/Core/Commands/VersionCommand.cs index 2b8c13cb..2a06ba7f 100644 --- a/Core/Commands/VersionCommand.cs +++ b/Core/Commands/VersionCommand.cs @@ -1,25 +1,26 @@ using System; using System.Linq; +using System.Reflection; using KY.Core; using KY.Generator.Command; -using KY.Generator.Output; +using KY.Generator.Configurations; namespace KY.Generator.Commands { internal class VersionCommand : IGeneratorCommand { - public string[] Names { get; } = { "version", "-version", "--version", "v", "-v", "--v" }; - - public bool Generate(CommandConfiguration configuration, ref IOutput output) + public bool Execute(IConfiguration configurationBase) { - bool detailed = configuration.Parameters.GetBool("d"); Logger.Trace("Execute version command..."); + AssemblyName callingName = Assembly.GetEntryAssembly()?.GetName(); + Logger.Trace($"{callingName?.Name} {callingName?.Version}"); + VersionConfiguration configuration = (VersionConfiguration)configurationBase; Logger.Trace("Loaded assemblies:"); AppDomain.CurrentDomain.GetAssemblies() .Select(x => x.GetName()) .OrderBy(x => x.Name) - .ForEach(x => Logger.Trace($"{x.Name} {x.Version} {(detailed ? x.CodeBase.TrimStart("file:///") : "")}")); + .ForEach(x => Logger.Trace($"{x.Name} {x.Version} {(configuration.Detailed ? x.CodeBase.TrimStart("file:///") : "")}")); return true; } } diff --git a/Core/Configuration/ConfigurationEnvironment.cs b/Core/Configuration/ConfigurationEnvironment.cs index d5aaae2a..8ce7648b 100644 --- a/Core/Configuration/ConfigurationEnvironment.cs +++ b/Core/Configuration/ConfigurationEnvironment.cs @@ -1,14 +1,19 @@ +using System.Collections.Generic; +using KY.Generator.Command; + namespace KY.Generator.Configuration { public class ConfigurationEnvironment { public string ConfigurationFilePath { get; } public string OutputPath { get; } + public List Parameters { get; } public ConfigurationEnvironment(string configurationFilePath, string outputPath) { this.ConfigurationFilePath = configurationFilePath; this.OutputPath = outputPath; + this.Parameters = new List(); } } } \ No newline at end of file diff --git a/Core/Configuration/ConfigurationIgnoreAttribute.cs b/Core/Configuration/ConfigurationIgnoreAttribute.cs new file mode 100644 index 00000000..c4afde64 --- /dev/null +++ b/Core/Configuration/ConfigurationIgnoreAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace KY.Generator.Configuration +{ + [AttributeUsage(AttributeTargets.Property)] + public class ConfigurationIgnoreAttribute : Attribute + { + } +} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationPropertyAttribute.cs b/Core/Configuration/ConfigurationPropertyAttribute.cs new file mode 100644 index 00000000..0e206ae8 --- /dev/null +++ b/Core/Configuration/ConfigurationPropertyAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace KY.Generator.Configuration +{ + [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] + public class ConfigurationPropertyAttribute : Attribute + { + public string Alias { get; } + + public ConfigurationPropertyAttribute(string alias) + { + this.Alias = alias; + } + } +} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationPropertyConverter.cs b/Core/Configuration/ConfigurationPropertyConverter.cs new file mode 100644 index 00000000..575be50a --- /dev/null +++ b/Core/Configuration/ConfigurationPropertyConverter.cs @@ -0,0 +1,7 @@ +namespace KY.Generator.Configuration +{ + public abstract class ConfigurationPropertyConverter + { + public abstract object Convert(string value); + } +} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationPropertyConverterAttribute.cs b/Core/Configuration/ConfigurationPropertyConverterAttribute.cs new file mode 100644 index 00000000..a286a8c9 --- /dev/null +++ b/Core/Configuration/ConfigurationPropertyConverterAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace KY.Generator.Configuration +{ + [AttributeUsage(AttributeTargets.Property)] + public class ConfigurationPropertyConverterAttribute : Attribute + { + public Type ConverterType { get; } + + public ConfigurationPropertyConverterAttribute(Type converterType) + { + this.ConverterType = converterType; + } + } +} \ No newline at end of file diff --git a/Core/Configurations/ConfigurationBase.cs b/Core/Configurations/ConfigurationBase.cs index 79930489..a545e90e 100644 --- a/Core/Configurations/ConfigurationBase.cs +++ b/Core/Configurations/ConfigurationBase.cs @@ -2,6 +2,7 @@ using KY.Generator.Configuration; using KY.Generator.Languages; using KY.Generator.Mappings; +using KY.Generator.Output; using Newtonsoft.Json; namespace KY.Generator.Configurations @@ -11,20 +12,37 @@ public abstract class ConfigurationBase : IConfiguration public bool VerifySsl { get; set; } = true; [JsonIgnore] + [ConfigurationIgnore] public ILanguage Language { get; set; } [JsonProperty("Language")] + [ConfigurationProperty("Language")] internal string LanguageKey { get; set; } public bool AddHeader { get; set; } = true; public virtual bool RequireLanguage => true; + [JsonIgnore] + public bool SkipHeader + { + get => !this.AddHeader; + set => this.AddHeader = !value; + } + public List ClassMapping { get; } public List FieldMapping { get; } public List PropertyMapping { get; } + public ConfigurationFormatting Formatting { get; set; } + + [JsonIgnore] public bool Standalone { get; set; } + + [JsonIgnore] public ConfigurationEnvironment Environment { get; set; } - public ConfigurationFormatting Formatting { get; set; } + + [JsonIgnore] + public IOutput Output { get; } + public bool CheckOnOverwrite { get; set; } = true; public bool BeforeBuild { get; set; } diff --git a/Core/Configurations/IConfiguration.cs b/Core/Configurations/IConfiguration.cs index e6eda44a..8267efe6 100644 --- a/Core/Configurations/IConfiguration.cs +++ b/Core/Configurations/IConfiguration.cs @@ -1,5 +1,6 @@ using KY.Generator.Configuration; using KY.Generator.Languages; +using KY.Generator.Output; namespace KY.Generator.Configurations { @@ -7,5 +8,7 @@ public interface IConfiguration { ILanguage Language { get; } ConfigurationFormatting Formatting { get; } + IOutput Output { get; } + ConfigurationEnvironment Environment { get; } } } \ No newline at end of file diff --git a/Core/Configurations/TemplateConfiguration.cs b/Core/Configurations/TemplateConfiguration.cs new file mode 100644 index 00000000..f0b43bb4 --- /dev/null +++ b/Core/Configurations/TemplateConfiguration.cs @@ -0,0 +1,5 @@ +namespace KY.Generator.Configurations +{ + public class TemplateConfiguration : ConfigurationBase + { } +} \ No newline at end of file diff --git a/Core/Configurations/VersionConfiguration.cs b/Core/Configurations/VersionConfiguration.cs new file mode 100644 index 00000000..e56ea1ee --- /dev/null +++ b/Core/Configurations/VersionConfiguration.cs @@ -0,0 +1,10 @@ +using KY.Generator.Configuration; + +namespace KY.Generator.Configurations +{ + public class VersionConfiguration : ConfigurationBase + { + [ConfigurationProperty("d")] + public bool Detailed { get; set; } + } +} \ No newline at end of file diff --git a/Core/CoreModule.cs b/Core/CoreModule.cs index 16cab753..b7ff8edd 100644 --- a/Core/CoreModule.cs +++ b/Core/CoreModule.cs @@ -31,9 +31,17 @@ public CoreModule(IDependencyResolver dependencyResolver) public override void Initialize() { - this.DependencyResolver.Bind().To(); + this.DependencyResolver.Get() + .Register("client") + .Register("version") + .Register("v") + .Register("execute") + .Register("exec") + .Register("e") + .Register("run") + .Register("r"); this.DependencyResolver.Bind().To(); - this.DependencyResolver.Bind().To(); + this.DependencyResolver.Bind().To(); this.DependencyResolver.Bind().To(); this.DependencyResolver.Get() .Map("cookie") diff --git a/Core/Exceptions/AmbiguousCommandException.cs b/Core/Exceptions/AmbiguousCommandException.cs new file mode 100644 index 00000000..2ac3cd6a --- /dev/null +++ b/Core/Exceptions/AmbiguousCommandException.cs @@ -0,0 +1,11 @@ +using System; + +namespace KY.Generator.Exceptions +{ + public class AmbiguousCommandException : Exception + { + public AmbiguousCommandException(string message = null, Exception innerException = null) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Core/Exceptions/CommandNotFoundException.cs b/Core/Exceptions/CommandNotFoundException.cs new file mode 100644 index 00000000..76e6d769 --- /dev/null +++ b/Core/Exceptions/CommandNotFoundException.cs @@ -0,0 +1,11 @@ +using System; + +namespace KY.Generator.Exceptions +{ + public class CommandNotFoundException : Exception + { + public CommandNotFoundException(string command) + : base($"Command '{command}' not found") + { } + } +} \ No newline at end of file diff --git a/Core/Exceptions/CommandParameterConverterNotFoundException.cs b/Core/Exceptions/CommandParameterConverterNotFoundException.cs new file mode 100644 index 00000000..8359dd6f --- /dev/null +++ b/Core/Exceptions/CommandParameterConverterNotFoundException.cs @@ -0,0 +1,12 @@ +using System; +using KY.Generator.Configuration; + +namespace KY.Generator.Exceptions +{ + public class CommandParameterConverterNotFoundException : Exception + { + public CommandParameterConverterNotFoundException(Type type) + : base($"Converter for '{type.FullName} not found. Use [{typeof(ConfigurationPropertyConverterAttribute).Name.Replace("Attribute", string.Empty)}(typeof(MyConverter)] and derive your converter from {typeof(ConfigurationPropertyConverter)}.") + { } + } +} \ No newline at end of file diff --git a/Core/Exceptions/ConfigurationParameterReadOnlyException.cs b/Core/Exceptions/ConfigurationParameterReadOnlyException.cs new file mode 100644 index 00000000..fe425edb --- /dev/null +++ b/Core/Exceptions/ConfigurationParameterReadOnlyException.cs @@ -0,0 +1,11 @@ +using System; + +namespace KY.Generator.Exceptions +{ + public class ConfigurationParameterReadOnlyException : Exception + { + public ConfigurationParameterReadOnlyException(string parameter) + : base($"Parameter '{parameter} is readonly. Add a setter (set;).") + { } + } +} \ No newline at end of file diff --git a/Core/Extensions/StringExtensions.cs b/Core/Extensions/StringExtensions.cs index 5bec7067..5dcb556f 100644 --- a/Core/Extensions/StringExtensions.cs +++ b/Core/Extensions/StringExtensions.cs @@ -7,26 +7,41 @@ namespace KY.Generator.Extensions { public static class StringExtensions { + /// + /// Converts a string to PascalCase (UpperCamelCase) + /// public static string ToPascalCase(this string value) { return string.Join("", Split(value, true).Select(x => x.FirstCharToUpper())); } - + + /// + /// Converts a string to camelCase (lowerCamelCase) + /// public static string ToCamelCase(this string value) { return string.Join("", Split(value, true).Select(x => x.FirstCharToUpper())).FirstCharToLower(); } - + + /// + /// Converts a string to kebab-case + /// public static string ToKebabCase(this string value) { return string.Join("-", Split(value, true).Select(x => x.ToLowerInvariant())); } - + + /// + /// Converts a string to snake_case + /// public static string ToSnakeCase(this string value) { return string.Join("_", Split(value, true).Select(x => x.ToLowerInvariant())); } - + + /// + /// Converts a string to Darwin_Case + /// public static string ToDarwinCase(this string value) { return string.Join("_", Split(value, true).Select(x => x.ToLowerInvariant().FirstCharToUpper())); diff --git a/Core/Generator.cs b/Core/Generator.cs index 4d748b84..1a63a692 100644 --- a/Core/Generator.cs +++ b/Core/Generator.cs @@ -11,21 +11,21 @@ using KY.Generator.Mappings; using KY.Generator.Output; using KY.Generator.Syntax; -using KY.Generator.Transfer.Readers; using KY.Generator.Transfer.Writers; namespace KY.Generator { public class Generator : IGeneratorRunSyntax, IGeneratorAfterRunSyntax { - private IOutput output; private readonly DependencyResolver resolver; - private readonly CommandConfiguration command; + private readonly List parameters; + private IOutput output; private bool success; private IList Modules { get; } public Generator(params string[] parameters) { + this.parameters = parameters.ToList(); InitializeLogger(parameters); Logger.Trace($"KY-Generator v{Assembly.GetCallingAssembly().GetName().Version}"); Logger.Trace("Current Directory: " + Environment.CurrentDirectory); @@ -37,7 +37,9 @@ public Generator(params string[] parameters) this.output = new FileOutput(AppDomain.CurrentDomain.BaseDirectory); this.resolver = new DependencyResolver(); this.resolver.Bind().ToSingleton(); + this.resolver.Bind().ToSelf(); this.resolver.Bind().ToSelf(); + this.resolver.Bind().ToSingleton(); this.resolver.Bind().ToSelf(); this.resolver.Bind().To(); this.resolver.Bind().ToSingleton(); @@ -54,9 +56,6 @@ public Generator(params string[] parameters) } this.Modules.ForEach(module => this.resolver.Bind().To(module)); this.Modules.ForEach(module => module.Initialize()); - - CommandReader reader = this.resolver.Create(); - this.command = reader.Read(parameters); } public static Generator Create(params string[] parameters) @@ -80,37 +79,17 @@ public Generator SetOutput(string path) return this.SetOutput(new FileOutput(path)); } - public Generator RegisterCommand() where T : IGeneratorCommand - { - this.resolver.Bind().To(); - return this; - } - - public Generator RegisterCommand(IGeneratorCommand generator) - { - this.resolver.Bind().To(generator); - return this; - } - - public Generator RegisterReader(string name) - where TConfiguration : ConfigurationBase - where TReader : ITransferReader - { - this.resolver.Get().Map(name); - return this; - } - - public Generator RegisterWriter(string name) - where TConfiguration : ConfigurationBase - where TWriter : ITransferWriter + public Generator RegisterCommand(string name, string group = CommandRegister.DefaultGroup) + where TCommand : IGeneratorCommand + where TConfiguration : IConfiguration { - this.resolver.Get().Map(name); + this.resolver.Get().Register(name, group); return this; } public Generator SetStandalone() { - this.command.Standalone = true; + this.parameters.Add("-standalone"); return this; } @@ -118,7 +97,8 @@ public IGeneratorAfterRunSyntax Run() { try { - this.success = this.resolver.Get().Run(this.command, this.output); + IConfiguration configuration = this.resolver.Get().Read(this.parameters); + this.success = this.resolver.Get().Run(configuration, this.output); } catch (Exception exception) { diff --git a/Core/KY.Generator.Core.csproj b/Core/KY.Generator.Core.csproj index 3a520516..bcc3e4cb 100644 --- a/Core/KY.Generator.Core.csproj +++ b/Core/KY.Generator.Core.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Csharp.Tests/KY.Generator.Csharp.Tests.csproj b/Csharp.Tests/KY.Generator.Csharp.Tests.csproj index d8c31d67..c65eceec 100644 --- a/Csharp.Tests/KY.Generator.Csharp.Tests.csproj +++ b/Csharp.Tests/KY.Generator.Csharp.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Csharp/KY.Generator.CSharp.csproj b/Csharp/KY.Generator.CSharp.csproj index 294587a5..f6e790e6 100644 --- a/Csharp/KY.Generator.CSharp.csproj +++ b/Csharp/KY.Generator.CSharp.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/EntityFramework/KY.Generator.EntityFramework.csproj b/EntityFramework/KY.Generator.EntityFramework.csproj index 7e6e71d7..7d66a336 100644 --- a/EntityFramework/KY.Generator.EntityFramework.csproj +++ b/EntityFramework/KY.Generator.EntityFramework.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Json.Tests/KY.Generator.Json.Tests.csproj b/Json.Tests/KY.Generator.Json.Tests.csproj index 4c414a64..199b1baa 100644 --- a/Json.Tests/KY.Generator.Json.Tests.csproj +++ b/Json.Tests/KY.Generator.Json.Tests.csproj @@ -29,7 +29,7 @@ - + diff --git a/Json/KY.Generator.Json.csproj b/Json/KY.Generator.Json.csproj index 549e3088..93e6eb0c 100644 --- a/Json/KY.Generator.Json.csproj +++ b/Json/KY.Generator.Json.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/OData.Tests/KY.Generator.OData.Tests.csproj b/OData.Tests/KY.Generator.OData.Tests.csproj index 90f19233..433556bf 100644 --- a/OData.Tests/KY.Generator.OData.Tests.csproj +++ b/OData.Tests/KY.Generator.OData.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/OData/KY.Generator.OData.csproj b/OData/KY.Generator.OData.csproj index 33cbc412..5a022942 100644 --- a/OData/KY.Generator.OData.csproj +++ b/OData/KY.Generator.OData.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/OpenApi/KY.Generator.OpenApi.csproj b/OpenApi/KY.Generator.OpenApi.csproj index b842f3a5..dd869087 100644 --- a/OpenApi/KY.Generator.OpenApi.csproj +++ b/OpenApi/KY.Generator.OpenApi.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Reflection.Tests/KY.Generator.Reflection.Tests.csproj b/Reflection.Tests/KY.Generator.Reflection.Tests.csproj index c10493c9..c12d7962 100644 --- a/Reflection.Tests/KY.Generator.Reflection.Tests.csproj +++ b/Reflection.Tests/KY.Generator.Reflection.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Reflection/KY.Generator.Reflection.csproj b/Reflection/KY.Generator.Reflection.csproj index 50973102..597ea184 100644 --- a/Reflection/KY.Generator.Reflection.csproj +++ b/Reflection/KY.Generator.Reflection.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Tests/KY.Generator.Tests.csproj b/Tests/KY.Generator.Tests.csproj index cdf66cfd..34c235b1 100644 --- a/Tests/KY.Generator.Tests.csproj +++ b/Tests/KY.Generator.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Tsql.Tests/KY.Generator.Tsql.Tests.csproj b/Tsql.Tests/KY.Generator.Tsql.Tests.csproj index 28bfc81b..4243d656 100644 --- a/Tsql.Tests/KY.Generator.Tsql.Tests.csproj +++ b/Tsql.Tests/KY.Generator.Tsql.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Tsql/KY.Generator.Tsql.csproj b/Tsql/KY.Generator.Tsql.csproj index 5dfc60ca..5f836a17 100644 --- a/Tsql/KY.Generator.Tsql.csproj +++ b/Tsql/KY.Generator.Tsql.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj b/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj index ae2d2320..8844ece8 100644 --- a/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj +++ b/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/TypeScript/KY.Generator.TypeScript.csproj b/TypeScript/KY.Generator.TypeScript.csproj index 92c5dacb..1a2898cd 100644 --- a/TypeScript/KY.Generator.TypeScript.csproj +++ b/TypeScript/KY.Generator.TypeScript.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Watchdog/Configurations/WatchdogConfiguration.cs b/Watchdog/Configurations/WatchdogConfiguration.cs new file mode 100644 index 00000000..c5125aa9 --- /dev/null +++ b/Watchdog/Configurations/WatchdogConfiguration.cs @@ -0,0 +1,17 @@ +using System; +using KY.Generator.Configurations; + +namespace KY.Generator.Watchdog.Configurations +{ + public class WatchdogConfiguration : ConfigurationBase + { + public bool Async { get; set; } + public string LaunchSettings { get; set; } + public TimeSpan Timeout { get; set; } = TimeSpan.FromMinutes(5); + public TimeSpan Delay { get; set; } = TimeSpan.FromSeconds(1); + public TimeSpan Sleep { get; set; } = TimeSpan.FromMilliseconds(100); + public string Command { get; set; } + public string Url { get; set; } + public int Tries { get; set; } + } +} \ No newline at end of file diff --git a/Watchdog/KY.Generator.Watchdog.csproj b/Watchdog/KY.Generator.Watchdog.csproj index 6379d71b..8251e965 100644 --- a/Watchdog/KY.Generator.Watchdog.csproj +++ b/Watchdog/KY.Generator.Watchdog.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + From 4bb0574e53b1be8046636008453f87113eeaf818 Mon Sep 17 00:00:00 2001 From: KY Date: Fri, 17 Jan 2020 06:28:03 +0100 Subject: [PATCH 3/4] Core - command parameter converters added - configuration base classes and interfaces moved --- Core.Tests/CommandReaderTests.cs | 35 +++++++++++++++++++ Core/Command/CommandParameterConverters.cs | 8 +++++ Core/Command/CommandReader.cs | 10 +++--- .../ConfigurationBase.cs | 2 +- .../IConfiguration.cs | 0 .../IFormattableConfiguration.cs | 0 .../IModelConfiguration.cs | 0 .../ReadConfigurationBase.cs | 0 Core/Configurations/ExecuteConfiguration.cs | 7 +++- 9 files changed, 55 insertions(+), 7 deletions(-) rename Core/{Configurations => Configuration}/ConfigurationBase.cs (98%) rename Core/{Configurations => Configuration}/IConfiguration.cs (100%) rename Core/{Configurations => Configuration}/IFormattableConfiguration.cs (100%) rename Core/{Configurations => Configuration}/IModelConfiguration.cs (100%) rename Core/{Configurations => Configuration}/ReadConfigurationBase.cs (100%) diff --git a/Core.Tests/CommandReaderTests.cs b/Core.Tests/CommandReaderTests.cs index 1d9bb4f6..fe1d92e9 100644 --- a/Core.Tests/CommandReaderTests.cs +++ b/Core.Tests/CommandReaderTests.cs @@ -41,6 +41,36 @@ public void TestReadInt() Assert.AreEqual(123, configuration.Test); } + [TestMethod] + public void TestReadBoolTrue() + { + this.commands.Register("test"); + List parameters = new List{ "test", "-test=true"}; + BoolConfiguration configuration = this.reader.Read(parameters) as BoolConfiguration; + Assert.IsNotNull(configuration, "Read failed"); + Assert.AreEqual(true, configuration.Test); + } + + [TestMethod] + public void TestReadBoolFalse() + { + this.commands.Register("test"); + List parameters = new List{ "test", "-test=false"}; + BoolConfiguration configuration = this.reader.Read(parameters) as BoolConfiguration; + Assert.IsNotNull(configuration, "Read failed"); + Assert.AreEqual(false, configuration.Test); + } + + [TestMethod] + public void TestReadBoolEmpty() + { + this.commands.Register("test"); + List parameters = new List{ "test", "-test"}; + BoolConfiguration configuration = this.reader.Read(parameters) as BoolConfiguration; + Assert.IsNotNull(configuration, "Read failed"); + Assert.AreEqual(true, configuration.Test); + } + [TestMethod] public void TestReadCustomType() { @@ -62,6 +92,11 @@ private class IntConfiguration : TestConfiguration public int Test { get; set; } } + private class BoolConfiguration : TestConfiguration + { + public bool Test { get; set; } + } + private class CustomTypeConfiguration : TestConfiguration { [ConfigurationPropertyConverter(typeof(CustomTypeConverter))] diff --git a/Core/Command/CommandParameterConverters.cs b/Core/Command/CommandParameterConverters.cs index 0f4087e0..ba8397f9 100644 --- a/Core/Command/CommandParameterConverters.cs +++ b/Core/Command/CommandParameterConverters.cs @@ -13,14 +13,22 @@ public static class CommandParameterConverters static CommandParameterConverters() { converters = new Dictionary>(); + converters.Add(typeof(char), value => value[0]); converters.Add(typeof(string), value => value); + converters.Add(typeof(bool), value => value == string.Empty || bool.Parse(value)); + converters.Add(typeof(byte), value => byte.Parse(value)); + converters.Add(typeof(short), value => short.Parse(value)); converters.Add(typeof(int), value => int.Parse(value)); converters.Add(typeof(long), value => long.Parse(value)); + converters.Add(typeof(ushort), value => ushort.Parse(value)); + converters.Add(typeof(uint), value => uint.Parse(value)); + converters.Add(typeof(ulong), value => ulong.Parse(value)); converters.Add(typeof(float), value => float.Parse(value)); converters.Add(typeof(double), value => double.Parse(value)); converters.Add(typeof(decimal), value => decimal.Parse(value)); converters.Add(typeof(TimeSpan), value => TimeSpan.Parse(value)); converters.Add(typeof(DateTime), value => DateTime.Parse(value)); + converters.Add(typeof(Guid), value => Guid.Parse(value)); } public static object Convert(string value, PropertyInfo property) diff --git a/Core/Command/CommandReader.cs b/Core/Command/CommandReader.cs index eb24ae69..6410d0cc 100644 --- a/Core/Command/CommandReader.cs +++ b/Core/Command/CommandReader.cs @@ -65,16 +65,16 @@ private void SetParameters(IConfiguration configuration, List } foreach (CommandParameter parameter in parameters) { - string parameterName = parameter.Name.ToPascalCase(); - if (!properties.ContainsKey(parameterName)) + string propertyName = parameter.Name.ToPascalCase(); + if (!properties.ContainsKey(propertyName)) { - Logger.Warning($"Unknown parameter '{parameterName}'. No matching property in {type.Name} found. Add a matching property or use [{nameof(ConfigurationPropertyAttribute).Replace("Attribute", string.Empty)}(\"{parameterName}\")]."); + Logger.Warning($"Unknown parameter '{parameter.Name}'. No matching property '{propertyName}' in {type.Name} found. Add a matching property or use [{nameof(ConfigurationPropertyAttribute).Replace("Attribute", string.Empty)}(\"{propertyName}\")]."); continue; } - PropertyInfo propertyInfo = properties[parameterName]; + PropertyInfo propertyInfo = properties[propertyName]; if (!propertyInfo.CanWrite) { - throw new ConfigurationParameterReadOnlyException(parameterName); + throw new ConfigurationParameterReadOnlyException(propertyName); } object value = CommandParameterConverters.Convert(parameter.Value, propertyInfo); propertyInfo.SetValue(configuration, value); diff --git a/Core/Configurations/ConfigurationBase.cs b/Core/Configuration/ConfigurationBase.cs similarity index 98% rename from Core/Configurations/ConfigurationBase.cs rename to Core/Configuration/ConfigurationBase.cs index a545e90e..02f36fb3 100644 --- a/Core/Configurations/ConfigurationBase.cs +++ b/Core/Configuration/ConfigurationBase.cs @@ -41,7 +41,7 @@ public bool SkipHeader public ConfigurationEnvironment Environment { get; set; } [JsonIgnore] - public IOutput Output { get; } + public IOutput Output { get; set; } public bool CheckOnOverwrite { get; set; } = true; public bool BeforeBuild { get; set; } diff --git a/Core/Configurations/IConfiguration.cs b/Core/Configuration/IConfiguration.cs similarity index 100% rename from Core/Configurations/IConfiguration.cs rename to Core/Configuration/IConfiguration.cs diff --git a/Core/Configurations/IFormattableConfiguration.cs b/Core/Configuration/IFormattableConfiguration.cs similarity index 100% rename from Core/Configurations/IFormattableConfiguration.cs rename to Core/Configuration/IFormattableConfiguration.cs diff --git a/Core/Configurations/IModelConfiguration.cs b/Core/Configuration/IModelConfiguration.cs similarity index 100% rename from Core/Configurations/IModelConfiguration.cs rename to Core/Configuration/IModelConfiguration.cs diff --git a/Core/Configurations/ReadConfigurationBase.cs b/Core/Configuration/ReadConfigurationBase.cs similarity index 100% rename from Core/Configurations/ReadConfigurationBase.cs rename to Core/Configuration/ReadConfigurationBase.cs diff --git a/Core/Configurations/ExecuteConfiguration.cs b/Core/Configurations/ExecuteConfiguration.cs index 9c7320be..37054173 100644 --- a/Core/Configurations/ExecuteConfiguration.cs +++ b/Core/Configurations/ExecuteConfiguration.cs @@ -1,7 +1,12 @@ -namespace KY.Generator.Configurations +using KY.Generator.Configuration; + +namespace KY.Generator.Configurations { public class ExecuteConfiguration : ReadConfigurationBase { public string File { get; set; } + + [ConfigurationProperty("config")] + public string Configuration { get; set; } } } \ No newline at end of file From 48f6ae5033b83ed20dc29abe60fa14a842b23094 Mon Sep 17 00:00:00 2001 From: KY Date: Sun, 19 Jan 2020 10:12:23 +0100 Subject: [PATCH 4/4] All - replace transfer reader/writer with command - fixes all unit test - ensure each command has its own configuration class - code cleanup Core - replaced the usage of ConfigurationBase with IConfiguration or IConfigurationWithLanguage - replaced RequireLanguage with IConfigurationWithLanguage - some validation exceptions added WARNING: this commit does not builds --- Angular.Tests/FullStageTests.cs | 49 ++---- .../KY.Generator.Angular.Tests.csproj | 3 +- .../WriteAngularCommand.cs} | 19 +- .../AngularWriteConfiguration.cs | 10 +- Angular/KY.Generator.Angular.csproj | 2 +- AspDotNet.Tests/FullStageTests.cs | 49 ++---- .../KY.Generator.AspDotNet.Tests.csproj | 3 +- AspDotNet/AspDotNetModule.cs | 13 +- .../ReadAspDotNetCommand.cs} | 15 +- .../WriteAspDotNetCommand.cs} | 19 +- .../AspDotNetReadConfiguration.cs | 4 +- .../AspDotNetWriteConfiguration.cs | 4 +- AspDotNet/KY.Generator.AspDotNet.csproj | 2 +- .../AspDotNetGeneratorControllerWriter.cs | 3 - .../KY.Generator.CLI.Core.Full.csproj | 2 +- .../KY.Generator.CLI.Core.Minimal.csproj | 2 +- .../KY.Generator.CLI.Core.Standalone.csproj | 2 +- CLI.Core/KY.Generator.CLI.Core.csproj | 2 +- CLI.Full/KY.Generator.CLI.Full.csproj | 2 +- CLI.Full/Properties/AssemblyInfo.cs | 1 - CLI.Full/packages.config | 2 +- CLI.Minimal/KY.Generator.CLI.Minimal.csproj | 2 +- CLI.Minimal/Properties/AssemblyInfo.cs | 1 - CLI.Minimal/packages.config | 2 +- .../KY.Generator.CLI.Standalone.csproj | 2 +- CLI.Standalone/Properties/AssemblyInfo.cs | 1 - CLI.Standalone/packages.config | 2 +- CLI/KY.Generator.CLI.csproj | 2 +- CLI/Properties/AssemblyInfo.cs | 1 - CLI/packages.config | 2 +- Core.Tests/CaseTest.cs | 5 +- Core.Tests/CommandReaderTests.cs | 43 ++--- ...gisterTests.cs => CommandRegistryTests.cs} | 36 ++-- Core.Tests/KY.Generator.Core.Tests.csproj | 2 +- Core.Tests/ModelWriterTests.cs | 3 +- Core.Tests/Models/TestCommand.cs | 10 +- Core.Tests/Models/TestConfiguration.cs | 13 +- Core.Tests/TemplateWriterTests.cs | 3 +- Core.Tests/TestConfigurationRunner.cs | 52 ++++++ Core/Command/CommandReader.cs | 19 +- Core/Command/CommandRegister.cs | 81 --------- Core/Command/CommandRegistry.cs | 165 ++++++++++++++++++ Core/Command/CommandRunner.cs | 30 ---- Core/Command/ICommand.cs | 5 + Core/Command/ICommandLineCommand.cs | 12 ++ Core/Command/IConfigurationCommand.cs | 14 ++ Core/Command/IGeneratorCommand.cs | 9 - .../Commands/Client/GeneratorConfiguration.cs | 2 +- Core/Commands/Client/GeneratorGenerator.cs | 19 -- .../DemoWriter.cs => Commands/DemoCommand.cs} | 13 +- Core/Commands/ExecuteCommand.cs | 86 +++++++++ .../ExecuteSeparateCommand.cs} | 14 +- Core/Commands/ModelWriteCommand.cs | 31 ++++ .../ReadCookieCommand.cs} | 10 +- Core/Commands/RunCommand.cs | 101 ----------- Core/Commands/VersionCommand.cs | 3 +- Core/Configuration/ConfigurationBase.cs | 56 +++--- .../Configuration/ConfigurationEnvironment.cs | 8 +- Core/Configuration/ConfigurationMapping.cs | 87 --------- .../ConfigurationMappingEntry.cs | 20 --- .../ConfigurationReaderVersion2.cs | 82 +++++---- Core/Configuration/ConfigurationSet.cs | 15 -- Core/Configuration/ConfigurationVersion.cs | 9 +- Core/Configuration/ConfigurationVersion2.cs | 11 ++ .../ConfigurationWithLanguageBase.cs | 25 +++ Core/Configuration/ConfigurationsReader.cs | 46 ++--- Core/Configuration/IConfiguration.cs | 8 +- .../IConfigurationReaderVersion.cs | 5 +- .../IConfigurationWithLanguage.cs | 10 ++ .../IFormattableConfiguration.cs | 2 +- Core/Configuration/IModelConfiguration.cs | 4 +- Core/Configuration/ReadConfigurationBase.cs | 7 - Core/Configurations/CookieConfiguration.cs | 2 - Core/Configurations/DemoConfiguration.cs | 6 +- Core/Configurations/ExecuteConfiguration.cs | 24 ++- .../ExecuteSeparateConfiguration.cs | 7 + .../Configurations/ModelWriteConfiguration.cs | 3 +- Core/Configurations/TemplateConfiguration.cs | 4 +- Core/CoreModule.cs | 30 ++-- .../AmbiguousConfigurationException.cs | 11 ++ .../CommandAlreadyRegisteredException.cs | 11 ++ .../CommandWithoutEnvironmentException.cs | 12 ++ Core/Exceptions/UnknownCommandException.cs | 11 ++ Core/Extensions/ConfigurationListExtension.cs | 24 +++ Core/Extensions/FileTemplateListExtension.cs | 14 ++ Core/Generator.cs | 44 +++-- Core/Helpers/ConfigurationRunner.cs | 79 ++++----- Core/Helpers/Formatter.cs | 9 +- Core/Helpers/GeneratorTypeLoader.cs | 5 +- Core/Helpers/PathResolver.cs | 3 +- Core/KY.Generator.Core.csproj | 2 +- Core/Languages/BaseLanguage.cs | 1 + Core/Mappings/TypeMapping.cs | 6 +- .../Extensions/ClassTemplateExtension.cs | 5 +- .../Extensions/FieldTemplateExtension.cs | 1 - .../Extensions/MethodTemplateExtension.cs | 1 - .../Extensions/ParameterTemplateExtension.cs | 1 - .../Extensions/PropertyTemplateExtension.cs | 2 - Core/Transfer/Readers/ITransferReader.cs | 10 -- Core/Transfer/Writers/ITransferWriter.cs | 11 -- Core/Transfer/Writers/ModelWriter.cs | 34 +--- Core/Transfer/Writers/TransferWriter.cs | 29 +-- Core/Writers/MultilineCodeFragmentWriter.cs | 20 --- Csharp.Tests/KY.Generator.Csharp.Tests.csproj | 2 +- Csharp.Tests/TemplateWriterTests.cs | 3 +- Csharp/KY.Generator.CSharp.csproj | 2 +- .../WriteEntityFrameworkCommand.cs} | 17 +- .../EntityFrameworkWriteConfiguration.cs | 4 +- EntityFramework/EntityFrameworkModule.cs | 10 +- .../KY.Generator.EntityFramework.csproj | 2 +- .../EntityFrameworkDataContextWriter.cs | 2 +- Json.Tests/ConfigurationTests.cs | 59 +++---- Json.Tests/FullStageTests.cs | 87 ++++----- Json.Tests/KY.Generator.Json.Tests.csproj | 3 +- .../ReadJsonCommand.cs} | 15 +- .../WriteJsonCommand.cs} | 18 +- Json/Configurations/JsonReadConfiguration.cs | 4 +- Json/Configurations/JsonWriteConfiguration.cs | 4 +- Json/JsonModule.cs | 11 +- Json/KY.Generator.Json.csproj | 2 +- .../JsonModelTransferObject.cs | 2 +- Json/Writers/ObjectWriter.cs | 3 +- OData.Tests/FullStageTests.cs | 53 ++---- OData.Tests/KY.Generator.OData.Tests.csproj | 3 +- .../ReadODataCommand.cs} | 20 ++- .../Configurations/ODataReadConfiguration.cs | 4 +- OData/KY.Generator.OData.csproj | 2 +- OData/ODataModule.cs | 7 +- .../ODataResultTransferObject.cs | 2 +- .../ReadOpenApiCommand.cs} | 13 +- .../OpenApiReadConfiguration.cs | 4 +- OpenApi/DataAccess/OpenApiUrlReader.cs | 3 +- OpenApi/KY.Generator.OpenApi.csproj | 6 +- OpenApi/Languages/OpenApiLanguage.cs | 5 +- OpenApi/OpenApiModule.cs | 6 +- Reflection.Tests/Data/CustomGeneric.cs | 6 +- Reflection.Tests/Data/CustomTypeInArray.cs | 5 +- Reflection.Tests/InterfaceTest.cs | 3 +- .../KY.Generator.Reflection.Tests.csproj | 2 +- .../ReflectionModelReaderTests.cs | 3 +- .../ReadReflectionCommand.cs} | 18 +- .../WriteReflectionCommand.cs} | 20 ++- ...tion.cs => ReadReflectionConfiguration.cs} | 4 +- .../Configurations/ReflectionConfiguration.cs | 135 ++++++++++++++ ...ion.cs => WriteReflectionConfiguration.cs} | 8 +- Reflection/KY.Generator.Reflection.csproj | 2 +- Reflection/ReflectionModule.cs | 14 +- Tests/DeserializationTests.cs | 127 +++++--------- Tests/FullStageTests.cs | 53 ++---- Tests/KY.Generator.Tests.csproj | 3 +- Tests/Models/{Reader1.cs => Read1Command.cs} | 8 +- Tests/Models/Read1Configuration.cs | 4 +- Tests/Models/{Reader2.cs => Read2Command.cs} | 8 +- Tests/Models/Read2Configuration.cs | 4 +- Tests/Models/Write1Command.cs | 16 ++ Tests/Models/Write1Configuration.cs | 2 +- Tests/Models/Write2Command.cs | 16 ++ Tests/Models/Write2Configuration.cs | 1 - Tests/Models/Writer1.cs | 17 -- Tests/Models/Writer2.cs | 17 -- Tests/Properties/Resources.Designer.cs | 72 -------- Tests/Properties/Resources.resx | 9 - .../Resources/empty-configuration-array.json | 4 - .../one-read-one-generate-twice.json | 26 --- .../two-generates-in-array-array.json | 17 -- Tsql.Tests/FullStageTests.cs | 41 ++--- Tsql.Tests/KY.Generator.Tsql.Tests.csproj | 3 +- .../ReadTsqlCommand.cs} | 13 +- Tsql/Configurations/TsqlReadConfiguration.cs | 4 +- Tsql/KY.Generator.Tsql.csproj | 2 +- .../StoredProcedureTransferObject.cs | 2 +- Tsql/TsqlModule.cs | 7 +- .../KY.Generator.TypeScript.Tests.csproj | 2 +- TypeScript.Tests/TemplateWriterTests.cs | 4 +- TypeScript/KY.Generator.TypeScript.csproj | 2 +- TypeScript/Languages/LanguageExtension.cs | 8 +- TypeScript/Transfer/TypeScriptModelWriter.cs | 4 +- .../Configurations/WatchdogConfiguration.cs | 2 +- Watchdog/KY.Generator.Watchdog.csproj | 2 +- Watchdog/WatchdogModule.cs | 4 +- 180 files changed, 1451 insertions(+), 1472 deletions(-) rename Angular/{Writers/AngularWriter.cs => Commands/WriteAngularCommand.cs} (64%) rename AspDotNet/{Readers/AspDotNetReader.cs => Commands/ReadAspDotNetCommand.cs} (58%) rename AspDotNet/{Writers/AspDotNetWriter.cs => Commands/WriteAspDotNetCommand.cs} (64%) rename Core.Tests/{CommandRegisterTests.cs => CommandRegistryTests.cs} (64%) create mode 100644 Core.Tests/TestConfigurationRunner.cs delete mode 100644 Core/Command/CommandRegister.cs create mode 100644 Core/Command/CommandRegistry.cs delete mode 100644 Core/Command/CommandRunner.cs create mode 100644 Core/Command/ICommand.cs create mode 100644 Core/Command/ICommandLineCommand.cs create mode 100644 Core/Command/IConfigurationCommand.cs delete mode 100644 Core/Command/IGeneratorCommand.cs delete mode 100644 Core/Commands/Client/GeneratorGenerator.cs rename Core/{Transfer/Writers/DemoWriter.cs => Commands/DemoCommand.cs} (52%) create mode 100644 Core/Commands/ExecuteCommand.cs rename Core/{Transfer/Readers/ExecuteReader.cs => Commands/ExecuteSeparateCommand.cs} (80%) create mode 100644 Core/Commands/ModelWriteCommand.cs rename Core/{Transfer/Readers/CookieReader.cs => Commands/ReadCookieCommand.cs} (82%) delete mode 100644 Core/Commands/RunCommand.cs delete mode 100644 Core/Configuration/ConfigurationMapping.cs delete mode 100644 Core/Configuration/ConfigurationMappingEntry.cs delete mode 100644 Core/Configuration/ConfigurationSet.cs create mode 100644 Core/Configuration/ConfigurationVersion2.cs create mode 100644 Core/Configuration/ConfigurationWithLanguageBase.cs create mode 100644 Core/Configuration/IConfigurationWithLanguage.cs delete mode 100644 Core/Configuration/ReadConfigurationBase.cs create mode 100644 Core/Configurations/ExecuteSeparateConfiguration.cs create mode 100644 Core/Exceptions/AmbiguousConfigurationException.cs create mode 100644 Core/Exceptions/CommandAlreadyRegisteredException.cs create mode 100644 Core/Exceptions/CommandWithoutEnvironmentException.cs create mode 100644 Core/Exceptions/UnknownCommandException.cs create mode 100644 Core/Extensions/ConfigurationListExtension.cs create mode 100644 Core/Extensions/FileTemplateListExtension.cs delete mode 100644 Core/Transfer/Readers/ITransferReader.cs delete mode 100644 Core/Transfer/Writers/ITransferWriter.cs rename EntityFramework/{Writers/EntityFrameworkWriter.cs => Commands/WriteEntityFrameworkCommand.cs} (72%) rename Json/{Readers/JsonReader.cs => Commands/ReadJsonCommand.cs} (89%) rename Json/{Writers/JsonWriter.cs => Commands/WriteJsonCommand.cs} (71%) rename Json/{Transfers => TransferObjects}/JsonModelTransferObject.cs (70%) rename OData/{Readers/ODataReader.cs => Commands/ReadODataCommand.cs} (96%) rename OData/{Transfers => TransferObjects}/ODataResultTransferObject.cs (85%) rename OpenApi/{Readers/OpenApiReader.cs => Commands/ReadOpenApiCommand.cs} (74%) rename Reflection/{Readers/ReflectionReader.cs => Commands/ReadReflectionCommand.cs} (62%) rename Reflection/{Writers/ReflectionWriter.cs => Commands/WriteReflectionCommand.cs} (52%) rename Reflection/Configurations/{ReflectionReadConfiguration.cs => ReadReflectionConfiguration.cs} (69%) create mode 100644 Reflection/Configurations/ReflectionConfiguration.cs rename Reflection/Configurations/{ReflectionWriteConfiguration.cs => WriteReflectionConfiguration.cs} (77%) rename Tests/Models/{Reader1.cs => Read1Command.cs} (60%) rename Tests/Models/{Reader2.cs => Read2Command.cs} (60%) create mode 100644 Tests/Models/Write1Command.cs create mode 100644 Tests/Models/Write2Command.cs delete mode 100644 Tests/Models/Writer1.cs delete mode 100644 Tests/Models/Writer2.cs delete mode 100644 Tests/Resources/empty-configuration-array.json delete mode 100644 Tests/Resources/one-read-one-generate-twice.json delete mode 100644 Tests/Resources/two-generates-in-array-array.json rename Tsql/{Readers/TsqlReader.cs => Commands/ReadTsqlCommand.cs} (95%) rename Tsql/{Transfers => TransferObjects}/StoredProcedureTransferObject.cs (91%) diff --git a/Angular.Tests/FullStageTests.cs b/Angular.Tests/FullStageTests.cs index 18c496e4..ae224502 100644 --- a/Angular.Tests/FullStageTests.cs +++ b/Angular.Tests/FullStageTests.cs @@ -1,11 +1,8 @@ -using System.Collections.Generic; -using KY.Core.Dependency; +using KY.Core; using KY.Generator.Angular.Tests.Properties; using KY.Generator.AspDotNet; -using KY.Generator.Configuration; +using KY.Generator.Core.Tests; using KY.Generator.Csharp; -using KY.Generator.Mappings; -using KY.Generator.Output; using KY.Generator.Reflection; using KY.Generator.TypeScript; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -13,44 +10,28 @@ namespace KY.Generator.Angular.Tests { [TestClass] - public class FullStageTests + public class FullStageTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; - private ConfigurationRunner runner; - private MemoryOutput output; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().ToSingleton(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); - this.runner = this.resolver.Create(); - this.output = this.resolver.Create(); + this.runner = new TestConfigurationRunner(); + this.runner.Resolver.Create().Initialize(); + this.runner.Resolver.Create().Initialize(); + this.runner.Resolver.Create().Initialize(); + this.runner.Resolver.Create().Initialize(); + this.runner.Resolver.Create().Initialize(); + this.runner.Resolver.Create().Initialize(); } [TestMethod] public void CustomHttpClientType() { - Assert.AreEqual(true, this.Run(Resources.custom_client_type), "Generation not successful"); - Assert.AreEqual(2, this.output.Files.Count); - Assert.AreEqual(Resources.custom_values_service_ts, this.output.Files["src\\app\\services\\custom-values.service.ts"]); - } - - private bool Run(string configuration) - { - List configurations = this.reader.Parse(configuration); - configurations.ForEach(x => x.Configurations.ForEach(y => y.AddHeader = false)); - return this.runner.Run(configurations, this.output); + Assert.AreEqual(true, this.runner.Run(Resources.custom_client_type), "Generation not successful"); + Assert.AreEqual(2, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.custom_values_service_ts, this.runner.Output.Files["src\\app\\services\\custom-values.service.ts"]); } } -} +} \ No newline at end of file diff --git a/Angular.Tests/KY.Generator.Angular.Tests.csproj b/Angular.Tests/KY.Generator.Angular.Tests.csproj index d68a7c72..74b41e80 100644 --- a/Angular.Tests/KY.Generator.Angular.Tests.csproj +++ b/Angular.Tests/KY.Generator.Angular.Tests.csproj @@ -7,7 +7,7 @@ - + @@ -16,6 +16,7 @@ + diff --git a/Angular/Writers/AngularWriter.cs b/Angular/Commands/WriteAngularCommand.cs similarity index 64% rename from Angular/Writers/AngularWriter.cs rename to Angular/Commands/WriteAngularCommand.cs index 04a5fe4d..621adbff 100644 --- a/Angular/Writers/AngularWriter.cs +++ b/Angular/Commands/WriteAngularCommand.cs @@ -1,26 +1,28 @@ using System.Collections.Generic; +using KY.Core; using KY.Core.Dependency; using KY.Generator.Angular.Configurations; +using KY.Generator.Angular.Writers; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Output; +using KY.Generator.Extensions; using KY.Generator.Templates; using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; -namespace KY.Generator.Angular.Writers +namespace KY.Generator.Angular.Commands { - internal class AngularWriter : ITransferWriter + internal class WriteAngularCommand : IConfigurationCommand { private readonly IDependencyResolver resolver; - public AngularWriter(IDependencyResolver resolver) + public WriteAngularCommand(IDependencyResolver resolver) { this.resolver = resolver; } - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Write angular..."); AngularWriteConfiguration configuration = (AngularWriteConfiguration)configurationBase; List files = new List(); if (configuration.Service != null) @@ -31,7 +33,8 @@ public void Write(ConfigurationBase configurationBase, List tra { this.resolver.Create().Write(configuration, transferObjects, files); } - files.ForEach(file => configuration.Language.Write(file, output)); + files.Write(configuration); + return true; } } } \ No newline at end of file diff --git a/Angular/Configurations/AngularWriteConfiguration.cs b/Angular/Configurations/AngularWriteConfiguration.cs index 932adc30..2c2b6155 100644 --- a/Angular/Configurations/AngularWriteConfiguration.cs +++ b/Angular/Configurations/AngularWriteConfiguration.cs @@ -1,15 +1,21 @@ using KY.Generator.Angular.Languages; -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Angular.Configurations { - public class AngularWriteConfiguration : ConfigurationBase, IFormattableConfiguration + public class AngularWriteConfiguration : ConfigurationWithLanguageBase, IFormattableConfiguration { public AngularWriteServiceConfiguration Service { get; set; } public AngularWriteModelConfiguration Model { get; set; } public bool FormatNames { get; set; } public bool WriteModels { get; set; } + public override bool AddHeader + { + get => this.Model.AddHeader; + set => this.Model.AddHeader = value; + } + public AngularWriteConfiguration() { this.Language = new AngularTypeScriptLanguage(); diff --git a/Angular/KY.Generator.Angular.csproj b/Angular/KY.Generator.Angular.csproj index 3a4e336e..a36516e9 100644 --- a/Angular/KY.Generator.Angular.csproj +++ b/Angular/KY.Generator.Angular.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/AspDotNet.Tests/FullStageTests.cs b/AspDotNet.Tests/FullStageTests.cs index ed3b3ea3..bcdd4f5b 100644 --- a/AspDotNet.Tests/FullStageTests.cs +++ b/AspDotNet.Tests/FullStageTests.cs @@ -1,58 +1,39 @@ -using System.Collections.Generic; -using KY.Core.Dependency; +using KY.Core; using KY.Generator.AspDotNet.Tests.Properties; -using KY.Generator.Configuration; +using KY.Generator.Core.Tests; using KY.Generator.Csharp; -using KY.Generator.Mappings; -using KY.Generator.Output; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.AspDotNet.Tests { [TestClass] - public class FullStageTests + public class FullStageTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; - private ConfigurationRunner runner; - private MemoryOutput output; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().ToSingleton(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); - this.runner = this.resolver.Create(); - this.output = this.resolver.Create(); + this.runner = new TestConfigurationRunner() + .Initialize() + .Initialize() + .Initialize(); } [TestMethod] public void FrameworkController() { - Assert.AreEqual(true, this.Run(Resources.generator_controller_generator), "Generation not successful"); - Assert.AreEqual(1, this.output.Files.Count); - Assert.AreEqual(Resources.GeneratorController_cs, this.output.Files["GeneratorController.cs"]); + Assert.AreEqual(true, this.runner.Run(Resources.generator_controller_generator), "Generation not successful"); + Assert.AreEqual(1, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.GeneratorController_cs, this.runner.Output.Files["GeneratorController.cs"]); } [TestMethod] public void CoreController() { - Assert.AreEqual(true, this.Run(Resources.generator_controller_core_generator), "Generation not successful"); - Assert.AreEqual(1, this.output.Files.Count); - Assert.AreEqual(Resources.GeneratorCoreController_cs, this.output.Files["GeneratorController.cs"]); - } - - private bool Run(string configuration) - { - List configurations = this.reader.Parse(configuration); - configurations.ForEach(x => x.Configurations.ForEach(y => y.AddHeader = false)); - return this.runner.Run(configurations, this.output); + Assert.AreEqual(true, this.runner.Run(Resources.generator_controller_core_generator), "Generation not successful"); + Assert.AreEqual(1, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.GeneratorCoreController_cs, this.runner.Output.Files["GeneratorController.cs"]); } } -} +} \ No newline at end of file diff --git a/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj b/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj index c779a640..b73d4191 100644 --- a/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj +++ b/AspDotNet.Tests/KY.Generator.AspDotNet.Tests.csproj @@ -7,7 +7,7 @@ - + @@ -15,6 +15,7 @@ + diff --git a/AspDotNet/AspDotNetModule.cs b/AspDotNet/AspDotNetModule.cs index 75fe1423..f46517e8 100644 --- a/AspDotNet/AspDotNetModule.cs +++ b/AspDotNet/AspDotNetModule.cs @@ -1,9 +1,8 @@ using KY.Core.Dependency; using KY.Core.Module; +using KY.Generator.AspDotNet.Commands; using KY.Generator.AspDotNet.Configurations; -using KY.Generator.AspDotNet.Readers; -using KY.Generator.AspDotNet.Writers; -using KY.Generator.Configuration; +using KY.Generator.Command; namespace KY.Generator.AspDotNet { @@ -15,10 +14,10 @@ public AspDotNetModule(IDependencyResolver dependencyResolver) public override void Initialize() { - this.DependencyResolver.Get() - .Map("asp") - .Map("asp") - .Map("asp-core"); + this.DependencyResolver.Get() + .Register("asp", "read") + .Register("asp", "write") + .Register("asp-core", "write"); } } } \ No newline at end of file diff --git a/AspDotNet/Readers/AspDotNetReader.cs b/AspDotNet/Commands/ReadAspDotNetCommand.cs similarity index 58% rename from AspDotNet/Readers/AspDotNetReader.cs rename to AspDotNet/Commands/ReadAspDotNetCommand.cs index 615a8a38..d38b19ce 100644 --- a/AspDotNet/Readers/AspDotNetReader.cs +++ b/AspDotNet/Commands/ReadAspDotNetCommand.cs @@ -1,29 +1,32 @@ using System.Collections.Generic; +using KY.Core; using KY.Core.Dependency; using KY.Generator.AspDotNet.Configurations; +using KY.Generator.AspDotNet.Readers; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; -namespace KY.Generator.AspDotNet.Readers +namespace KY.Generator.AspDotNet.Commands { - public class AspDotNetReader : ITransferReader + public class ReadAspDotNetCommand : IConfigurationCommand { private readonly IDependencyResolver resolver; - public AspDotNetReader(IDependencyResolver resolver) + public ReadAspDotNetCommand(IDependencyResolver resolver) { this.resolver = resolver; } - public virtual void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Read ASP.net..."); AspDotNetReadConfiguration configuration = (AspDotNetReadConfiguration)configurationBase; if (configuration.Controller != null) { this.resolver.Create().Read(configuration, transferObjects); } + return true; } } } \ No newline at end of file diff --git a/AspDotNet/Writers/AspDotNetWriter.cs b/AspDotNet/Commands/WriteAspDotNetCommand.cs similarity index 64% rename from AspDotNet/Writers/AspDotNetWriter.cs rename to AspDotNet/Commands/WriteAspDotNetCommand.cs index 1b01d8e2..3d86d62a 100644 --- a/AspDotNet/Writers/AspDotNetWriter.cs +++ b/AspDotNet/Commands/WriteAspDotNetCommand.cs @@ -1,26 +1,28 @@ using System.Collections.Generic; +using KY.Core; using KY.Core.Dependency; using KY.Generator.AspDotNet.Configurations; +using KY.Generator.AspDotNet.Writers; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Output; +using KY.Generator.Extensions; using KY.Generator.Templates; using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; -namespace KY.Generator.AspDotNet.Writers +namespace KY.Generator.AspDotNet.Commands { - public class AspDotNetWriter : ITransferWriter + public class WriteAspDotNetCommand : IConfigurationCommand { private readonly IDependencyResolver resolver; - public AspDotNetWriter(IDependencyResolver resolver) + public WriteAspDotNetCommand(IDependencyResolver resolver) { this.resolver = resolver; } - public virtual void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Write ASP.net..."); AspDotNetWriteConfiguration configuration = (AspDotNetWriteConfiguration)configurationBase; List files = new List(); if (configuration.GeneratorController != null) @@ -31,7 +33,8 @@ public virtual void Write(ConfigurationBase configurationBase, List().Write(configuration, transferObjects, files); } - files.ForEach(file => configuration.Language.Write(file, output)); + files.Write(configuration); + return true; } } } \ No newline at end of file diff --git a/AspDotNet/Configurations/AspDotNetReadConfiguration.cs b/AspDotNet/Configurations/AspDotNetReadConfiguration.cs index eb02352e..85346ffe 100644 --- a/AspDotNet/Configurations/AspDotNetReadConfiguration.cs +++ b/AspDotNet/Configurations/AspDotNetReadConfiguration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.AspDotNet.Configurations { - public class AspDotNetReadConfiguration : ReadConfigurationBase + public class AspDotNetReadConfiguration : ConfigurationBase { public AspDotNetReadControllerConfiguration Controller { get; set; } } diff --git a/AspDotNet/Configurations/AspDotNetWriteConfiguration.cs b/AspDotNet/Configurations/AspDotNetWriteConfiguration.cs index f827cf8b..a3ef3874 100644 --- a/AspDotNet/Configurations/AspDotNetWriteConfiguration.cs +++ b/AspDotNet/Configurations/AspDotNetWriteConfiguration.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; using KY.Generator.AspDotNet.Templates; -using KY.Generator.Configurations; +using KY.Generator.Configuration; using KY.Generator.Csharp.Languages; namespace KY.Generator.AspDotNet.Configurations { - public class AspDotNetWriteConfiguration : ConfigurationBase, IFormattableConfiguration + public class AspDotNetWriteConfiguration : ConfigurationWithLanguageBase, IFormattableConfiguration { public string Namespace { get; set; } public string RelativePath { get; set; } diff --git a/AspDotNet/KY.Generator.AspDotNet.csproj b/AspDotNet/KY.Generator.AspDotNet.csproj index 9d576b70..6b355f78 100644 --- a/AspDotNet/KY.Generator.AspDotNet.csproj +++ b/AspDotNet/KY.Generator.AspDotNet.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/AspDotNet/Writers/AspDotNetGeneratorControllerWriter.cs b/AspDotNet/Writers/AspDotNetGeneratorControllerWriter.cs index cca690da..58f44a7e 100644 --- a/AspDotNet/Writers/AspDotNetGeneratorControllerWriter.cs +++ b/AspDotNet/Writers/AspDotNetGeneratorControllerWriter.cs @@ -1,13 +1,10 @@ using System; using System.Collections.Generic; -using System.Linq; using KY.Core; using KY.Generator.AspDotNet.Configurations; -using KY.Generator.AspDotNet.Templates; using KY.Generator.Csharp; using KY.Generator.Csharp.Extensions; using KY.Generator.Csharp.Languages; -using KY.Generator.Output; using KY.Generator.Templates; using KY.Generator.Templates.Extensions; diff --git a/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj b/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj index fd75ece2..574d49c0 100644 --- a/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj +++ b/CLI.Core.Full/KY.Generator.CLI.Core.Full.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj b/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj index 5ec53a39..4c78103c 100644 --- a/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj +++ b/CLI.Core.Minimal/KY.Generator.CLI.Core.Minimal.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj b/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj index fd75ece2..574d49c0 100644 --- a/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj +++ b/CLI.Core.Standalone/KY.Generator.CLI.Core.Standalone.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Core/KY.Generator.CLI.Core.csproj b/CLI.Core/KY.Generator.CLI.Core.csproj index fd75ece2..574d49c0 100644 --- a/CLI.Core/KY.Generator.CLI.Core.csproj +++ b/CLI.Core/KY.Generator.CLI.Core.csproj @@ -12,7 +12,7 @@ - + diff --git a/CLI.Full/KY.Generator.CLI.Full.csproj b/CLI.Full/KY.Generator.CLI.Full.csproj index 81d7db68..752a72b5 100644 --- a/CLI.Full/KY.Generator.CLI.Full.csproj +++ b/CLI.Full/KY.Generator.CLI.Full.csproj @@ -36,7 +36,7 @@ - ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll + ..\packages\KY.Core.Common.4.9.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI.Full/Properties/AssemblyInfo.cs b/CLI.Full/Properties/AssemblyInfo.cs index 4d4a30b0..63796cda 100644 --- a/CLI.Full/Properties/AssemblyInfo.cs +++ b/CLI.Full/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/CLI.Full/packages.config b/CLI.Full/packages.config index 208d971b..4bcb0101 100644 --- a/CLI.Full/packages.config +++ b/CLI.Full/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/CLI.Minimal/KY.Generator.CLI.Minimal.csproj b/CLI.Minimal/KY.Generator.CLI.Minimal.csproj index 68a3e308..4da14c93 100644 --- a/CLI.Minimal/KY.Generator.CLI.Minimal.csproj +++ b/CLI.Minimal/KY.Generator.CLI.Minimal.csproj @@ -37,7 +37,7 @@ - ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll + ..\packages\KY.Core.Common.4.9.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI.Minimal/Properties/AssemblyInfo.cs b/CLI.Minimal/Properties/AssemblyInfo.cs index 1acd7e1a..31d91544 100644 --- a/CLI.Minimal/Properties/AssemblyInfo.cs +++ b/CLI.Minimal/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/CLI.Minimal/packages.config b/CLI.Minimal/packages.config index 208d971b..4bcb0101 100644 --- a/CLI.Minimal/packages.config +++ b/CLI.Minimal/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/CLI.Standalone/KY.Generator.CLI.Standalone.csproj b/CLI.Standalone/KY.Generator.CLI.Standalone.csproj index 572f5886..5a79f95d 100644 --- a/CLI.Standalone/KY.Generator.CLI.Standalone.csproj +++ b/CLI.Standalone/KY.Generator.CLI.Standalone.csproj @@ -42,7 +42,7 @@ ..\packages\Costura.Fody.3.3.2\lib\net40\Costura.dll - ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll + ..\packages\KY.Core.Common.4.9.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI.Standalone/Properties/AssemblyInfo.cs b/CLI.Standalone/Properties/AssemblyInfo.cs index 376f9c01..2d7bed45 100644 --- a/CLI.Standalone/Properties/AssemblyInfo.cs +++ b/CLI.Standalone/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/CLI.Standalone/packages.config b/CLI.Standalone/packages.config index 825b6a1a..0fc89af2 100644 --- a/CLI.Standalone/packages.config +++ b/CLI.Standalone/packages.config @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/CLI/KY.Generator.CLI.csproj b/CLI/KY.Generator.CLI.csproj index 28c23ee7..7f0b4813 100644 --- a/CLI/KY.Generator.CLI.csproj +++ b/CLI/KY.Generator.CLI.csproj @@ -37,7 +37,7 @@ - ..\packages\KY.Core.Common.4.9.0-rc.0\lib\netstandard2.0\KY.Core.Common.dll + ..\packages\KY.Core.Common.4.9.0\lib\netstandard2.0\KY.Core.Common.dll ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/CLI/Properties/AssemblyInfo.cs b/CLI/Properties/AssemblyInfo.cs index 1acd7e1a..31d91544 100644 --- a/CLI/Properties/AssemblyInfo.cs +++ b/CLI/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following diff --git a/CLI/packages.config b/CLI/packages.config index 208d971b..4bcb0101 100644 --- a/CLI/packages.config +++ b/CLI/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Core.Tests/CaseTest.cs b/Core.Tests/CaseTest.cs index 806a9509..4cf74175 100644 --- a/Core.Tests/CaseTest.cs +++ b/Core.Tests/CaseTest.cs @@ -1,10 +1,11 @@ -using KY.Generator.Extensions; +using KY.Core; +using KY.Generator.Extensions; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.Core.Tests { [TestClass] - public class CaseTest + public class CaseTest : MsTestBase { /**************** * PascalCase * diff --git a/Core.Tests/CommandReaderTests.cs b/Core.Tests/CommandReaderTests.cs index fe1d92e9..5bda07a1 100644 --- a/Core.Tests/CommandReaderTests.cs +++ b/Core.Tests/CommandReaderTests.cs @@ -1,31 +1,32 @@ using System.Collections.Generic; +using KY.Core; using KY.Core.Dependency; using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Core.Tests.Models; +using KY.Generator.Languages; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.Core.Tests { [TestClass] - public class CommandReaderTests + public class CommandReaderTests : MsTestBase { - private CommandRegister commands; + private CommandRegistry commands; private CommandReader reader; [TestInitialize] public void Initialize() { - this.commands = new CommandRegister(new DependencyResolver()); - this.reader = new CommandReader(this.commands); + this.commands = new CommandRegistry(new DependencyResolver()); + this.reader = new CommandReader(this.commands, new List()); } [TestMethod] public void TestReadString() { this.commands.Register("test"); - List parameters = new List{ "test", "-test=Test"}; + List parameters = new List { "test", "-test=Test" }; StringConfiguration configuration = this.reader.Read(parameters) as StringConfiguration; Assert.IsNotNull(configuration, "Read failed"); Assert.AreEqual("Test", configuration.Test); @@ -35,7 +36,7 @@ public void TestReadString() public void TestReadInt() { this.commands.Register("test"); - List parameters = new List{ "test", "-test=123"}; + List parameters = new List { "test", "-test=123" }; IntConfiguration configuration = this.reader.Read(parameters) as IntConfiguration; Assert.IsNotNull(configuration, "Read failed"); Assert.AreEqual(123, configuration.Test); @@ -45,7 +46,7 @@ public void TestReadInt() public void TestReadBoolTrue() { this.commands.Register("test"); - List parameters = new List{ "test", "-test=true"}; + List parameters = new List { "test", "-test=true" }; BoolConfiguration configuration = this.reader.Read(parameters) as BoolConfiguration; Assert.IsNotNull(configuration, "Read failed"); Assert.AreEqual(true, configuration.Test); @@ -55,7 +56,7 @@ public void TestReadBoolTrue() public void TestReadBoolFalse() { this.commands.Register("test"); - List parameters = new List{ "test", "-test=false"}; + List parameters = new List { "test", "-test=false" }; BoolConfiguration configuration = this.reader.Read(parameters) as BoolConfiguration; Assert.IsNotNull(configuration, "Read failed"); Assert.AreEqual(false, configuration.Test); @@ -65,7 +66,7 @@ public void TestReadBoolFalse() public void TestReadBoolEmpty() { this.commands.Register("test"); - List parameters = new List{ "test", "-test"}; + List parameters = new List { "test", "-test" }; BoolConfiguration configuration = this.reader.Read(parameters) as BoolConfiguration; Assert.IsNotNull(configuration, "Read failed"); Assert.AreEqual(true, configuration.Test); @@ -75,23 +76,13 @@ public void TestReadBoolEmpty() public void TestReadCustomType() { this.commands.Register("test"); - List parameters = new List{ "test", "-test=~1~2~3~"}; + List parameters = new List { "test", "-test=~1~2~3~" }; CustomTypeConfiguration configuration = this.reader.Read(parameters) as CustomTypeConfiguration; Assert.IsNotNull(configuration, "Read failed"); Assert.IsNotNull(configuration.Test); Assert.AreEqual(123, configuration.Test.Value); } - private class StringConfiguration : TestConfiguration - { - public string Test { get; set; } - } - - private class IntConfiguration : TestConfiguration - { - public int Test { get; set; } - } - private class BoolConfiguration : TestConfiguration { public bool Test { get; set; } @@ -115,5 +106,15 @@ public override object Convert(string value) } } } + + private class IntConfiguration : TestConfiguration + { + public int Test { get; set; } + } + + private class StringConfiguration : TestConfiguration + { + public string Test { get; set; } + } } } \ No newline at end of file diff --git a/Core.Tests/CommandRegisterTests.cs b/Core.Tests/CommandRegistryTests.cs similarity index 64% rename from Core.Tests/CommandRegisterTests.cs rename to Core.Tests/CommandRegistryTests.cs index c9b42fba..3d76d892 100644 --- a/Core.Tests/CommandRegisterTests.cs +++ b/Core.Tests/CommandRegistryTests.cs @@ -1,6 +1,7 @@ -using System; +using KY.Core; using KY.Core.Dependency; using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Core.Tests.Models; using KY.Generator.Exceptions; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -8,23 +9,23 @@ namespace KY.Generator.Core.Tests { [TestClass] - public class CommandRegisterTests + public class CommandRegistryTests : MsTestBase { - private CommandRegister commands; + private CommandRegistry commands; [TestInitialize] public void Initialize() { - this.commands = new CommandRegister(new DependencyResolver()); + this.commands = new CommandRegistry(new DependencyResolver()); } [TestMethod] - [ExpectedException(typeof(InvalidOperationException))] + [ExpectedException(typeof(CommandAlreadyRegisteredException))] public void RegisterAmbiguousCommands() { this.commands .Register("test", "group") - .Register("test", "group"); + .Register("test", "group"); } [TestMethod] @@ -33,7 +34,7 @@ public void TestAmbiguousCommandName() { this.commands .Register("test", "group1") - .Register("test", "group2"); + .Register("test", "group2"); this.commands.CreateConfiguration("test"); } @@ -56,7 +57,7 @@ public void TestOneGroupMultipleCommands() { this.commands .Register("test1", "group1") - .Register("test2", "group1"); + .Register("test2", "group1"); Assert.IsNotNull(this.commands.CreateConfiguration("test1")); } @@ -65,7 +66,7 @@ public void TestMultipleGroupsOneCommands() { this.commands .Register("test", "group1") - .Register("test", "group2"); + .Register("test", "group2"); Assert.IsNotNull(this.commands.CreateConfiguration("group2-test")); } @@ -74,10 +75,21 @@ public void TestMultipleGroupsMultipleCommands() { this.commands .Register("test1", "group1") - .Register("test1", "group2") - .Register("test2", "group1") - .Register("test2", "group2"); + .Register("test1", "group2") + .Register("test2", "group1") + .Register("test2", "group2"); Assert.IsNotNull(this.commands.CreateConfiguration("group2-test1")); } + + [TestMethod] + public void TestOneCommandMultipleGroupsWithDefaultGroup() + { + this.commands + .Register("test") + .Register("test", "group"); + IConfiguration found = this.commands.CreateConfiguration("test"); + Assert.IsNotNull(found); + Assert.IsInstanceOfType(found, typeof(TestConfiguration)); + } } } \ No newline at end of file diff --git a/Core.Tests/KY.Generator.Core.Tests.csproj b/Core.Tests/KY.Generator.Core.Tests.csproj index 96fccec6..e7a93baf 100644 --- a/Core.Tests/KY.Generator.Core.Tests.csproj +++ b/Core.Tests/KY.Generator.Core.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Core.Tests/ModelWriterTests.cs b/Core.Tests/ModelWriterTests.cs index 5d79a36b..5a1c2048 100644 --- a/Core.Tests/ModelWriterTests.cs +++ b/Core.Tests/ModelWriterTests.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using KY.Core; using KY.Core.Dependency; using KY.Generator.Core.Tests.Models; using KY.Generator.Mappings; @@ -10,7 +11,7 @@ namespace KY.Generator.Core.Tests { [TestClass] - public class ModelWriterTests + public class ModelWriterTests : MsTestBase { private IDependencyResolver resolver; private ModelWriter writer; diff --git a/Core.Tests/Models/TestCommand.cs b/Core.Tests/Models/TestCommand.cs index 452a6b7d..b1f330ae 100644 --- a/Core.Tests/Models/TestCommand.cs +++ b/Core.Tests/Models/TestCommand.cs @@ -1,11 +1,13 @@ -using KY.Generator.Command; -using KY.Generator.Configurations; +using System.Collections.Generic; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Transfer; namespace KY.Generator.Core.Tests.Models { - internal class TestCommand : IGeneratorCommand + internal class TestCommand : IConfigurationCommand { - public bool Execute(IConfiguration configuration) + public bool Execute(IConfiguration configuration, List transferObjects) { return true; } diff --git a/Core.Tests/Models/TestConfiguration.cs b/Core.Tests/Models/TestConfiguration.cs index 1b601911..53e75795 100644 --- a/Core.Tests/Models/TestConfiguration.cs +++ b/Core.Tests/Models/TestConfiguration.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Languages; using KY.Generator.Output; @@ -16,15 +15,27 @@ internal class TestConfiguration : IModelConfiguration public List Usings { get; } public bool FormatNames { get; set; } public ILanguage Language { get; set; } + public string LanguageKey { get; set; } public ConfigurationFormatting Formatting { get; } public IOutput Output { get; set; } public ConfigurationEnvironment Environment { get; set; } + public bool BeforeBuild { get; set; } public TestConfiguration() { this.Language = new TestLanguage(); this.Usings = new List(); this.Formatting = new ConfigurationFormatting(); + this.Environment = new ConfigurationEnvironment(); } } + + internal class TestConfiguration2 : TestConfiguration + { } + + internal class TestConfiguration3 : TestConfiguration + { } + + internal class TestConfiguration4 : TestConfiguration + { } } \ No newline at end of file diff --git a/Core.Tests/TemplateWriterTests.cs b/Core.Tests/TemplateWriterTests.cs index 0f1a3bb0..73e2d9b7 100644 --- a/Core.Tests/TemplateWriterTests.cs +++ b/Core.Tests/TemplateWriterTests.cs @@ -11,10 +11,11 @@ namespace KY.Generator.Core.Tests { [TestClass] - public class TemplateWriterTests : Codeable + public class TemplateWriterTests : MsTestBase { private IDependencyResolver resolver; private IOutputCache output; + private static readonly Code Code = default; [TestInitialize] public void Initialize() diff --git a/Core.Tests/TestConfigurationRunner.cs b/Core.Tests/TestConfigurationRunner.cs new file mode 100644 index 00000000..79a05e54 --- /dev/null +++ b/Core.Tests/TestConfigurationRunner.cs @@ -0,0 +1,52 @@ +using System.Linq; +using KY.Core; +using KY.Core.Dependency; +using KY.Core.Module; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Configurations; +using KY.Generator.Extensions; +using KY.Generator.Mappings; +using KY.Generator.Output; + +namespace KY.Generator.Core.Tests +{ + public class TestConfigurationRunner + { + public IDependencyResolver Resolver { get; } + public MemoryOutput Output { get; } + + public TestConfigurationRunner() + { + this.Resolver = new DependencyResolver(); + this.Resolver.Bind().ToSingleton(); + this.Resolver.Bind().ToSelf(); + this.Resolver.Bind().ToSingleton(); + this.Resolver.Bind().To(); + this.Resolver.Bind().ToSelf(); + + this.Output = this.Resolver.Create(); + } + + public TestConfigurationRunner Initialize() + where TModule : ModuleBase + { + this.Resolver.Create().Initialize(); + return this; + } + + public ExecuteConfiguration Parse(string json) + { + return this.Resolver.Create().Parse(json); + } + + public bool Run(string json) + { + ExecuteConfiguration configuration = this.Parse(json); + configuration.Execute.Flatten().ForEach(x => x.Output = this.Output); + ConfigurationRunner runner = this.Resolver.Create(); + configuration.Execute.OfType().ForEach(x => x.AddHeader = false); + return runner.Run(configuration.Execute); + } + } +} \ No newline at end of file diff --git a/Core/Command/CommandReader.cs b/Core/Command/CommandReader.cs index 6410d0cc..f3ff3c09 100644 --- a/Core/Command/CommandReader.cs +++ b/Core/Command/CommandReader.cs @@ -4,19 +4,21 @@ using System.Reflection; using KY.Core; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Exceptions; using KY.Generator.Extensions; +using KY.Generator.Languages; namespace KY.Generator.Command { public class CommandReader { - private readonly CommandRegister commands; + private readonly CommandRegistry commands; + private readonly List languages; - public CommandReader(CommandRegister commands) + public CommandReader(CommandRegistry commands, List languages) { this.commands = commands; + this.languages = languages; } public IConfiguration Read(List parameters) @@ -33,7 +35,7 @@ public IConfiguration Read(List parameters) return null; } List commandParameters = this.ReadParameters(parameters.Where(x => x.StartsWith("-"))).ToList(); - + IConfiguration configuration = this.commands.CreateConfiguration(commandList.Single()); if (configuration == null) { @@ -42,6 +44,11 @@ public IConfiguration Read(List parameters) } configuration.Environment?.Parameters.AddRange(commandParameters); this.SetParameters(configuration, commandParameters); + if (configuration is IConfigurationWithLanguage configurationWithLanguage) + { + configurationWithLanguage.Language = this.languages.FirstOrDefault(language => language.Name.Equals(configurationWithLanguage.LanguageKey, StringComparison.InvariantCultureIgnoreCase)) + ?? configurationWithLanguage.Language; + } return configuration; } @@ -60,6 +67,10 @@ private void SetParameters(IConfiguration configuration, List Dictionary properties = new Dictionary(); foreach (PropertyInfo property in type.GetProperties()) { + if (property.GetCustomAttributes().Any()) + { + continue; + } properties.Add(property.Name, property); property.GetCustomAttributes().ForEach(attribute => properties.Add(attribute.Alias, property)); } diff --git a/Core/Command/CommandRegister.cs b/Core/Command/CommandRegister.cs deleted file mode 100644 index e41cc8b8..00000000 --- a/Core/Command/CommandRegister.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using KY.Core; -using KY.Core.Dependency; -using KY.Generator.Configurations; -using KY.Generator.Exceptions; - -namespace KY.Generator.Command -{ - public class CommandRegister - { - public const string DefaultGroup = "execute"; - private readonly IDependencyResolver resolver; - private readonly List entries; - - public CommandRegister(IDependencyResolver resolver) - { - this.resolver = resolver.AssertIsNotNull(nameof(resolver)); - this.entries = new List(); - } - - public CommandRegister Register(string name, string group = DefaultGroup) - where TCommand : IGeneratorCommand - where TConfiguration : IConfiguration - { - group = string.IsNullOrWhiteSpace(group) ? DefaultGroup : group; - if (this.entries.Any(entry => entry.Group.Equals(group, StringComparison.InvariantCultureIgnoreCase) && entry.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))) - { - throw new InvalidOperationException($"{name} ({group}) is already mapped. Please use a prefix like my-{name}"); - } - this.entries.Add(new RegisterEntry - { - Name = name, - Group = group, - Command = typeof(TCommand), - Configuration = typeof(TConfiguration) - }); - return this; - } - - private RegisterEntry Find(string command) - { - List found = this.entries.Where(entry => entry.Name.Equals(command, StringComparison.InvariantCultureIgnoreCase)).ToList(); - if (found.Count > 1) - { - throw new AmbiguousCommandException($"Ambiguous command '{command}'. Use {string.Join(" or ", found.Select(x => $"'{x.Group}-{x.Name}'"))} instead."); - } - if (found.Count == 0) - { - found = this.entries.Where(entry => $"{entry.Group}-{entry.Name}".Equals(command, StringComparison.InvariantCultureIgnoreCase)).ToList(); - } - if (found.Count == 0) - { - throw new CommandNotFoundException(command); - } - return found.Single(); - } - - public IConfiguration CreateConfiguration(string command) - { - RegisterEntry entry = this.Find(command); - return entry == null ? null : this.resolver.Create(entry.Configuration) as IConfiguration; - } - - public IGeneratorCommand CreateCommand(IConfiguration configuration) - { - Type type = configuration.GetType(); - RegisterEntry entry = this.entries.FirstOrDefault(x => x.Configuration == type); - return entry == null ? null : this.resolver.Create(entry.Command) as IGeneratorCommand; - } - - private class RegisterEntry - { - public string Name { get; set; } - public string Group { get; set; } - public Type Command { get; set; } - public Type Configuration { get; set; } - } - } -} \ No newline at end of file diff --git a/Core/Command/CommandRegistry.cs b/Core/Command/CommandRegistry.cs new file mode 100644 index 00000000..88382cbf --- /dev/null +++ b/Core/Command/CommandRegistry.cs @@ -0,0 +1,165 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using KY.Core; +using KY.Core.Dependency; +using KY.Generator.Configuration; +using KY.Generator.Exceptions; + +namespace KY.Generator.Command +{ + public class CommandRegistry + { + public const string DefaultGroup = "execute"; + private readonly IDependencyResolver resolver; + private readonly List entries; + + public CommandRegistry(IDependencyResolver resolver) + { + this.resolver = resolver.AssertIsNotNull(nameof(resolver)); + this.entries = new List(); + } + + public IRegisterSyntax Register(string name, string group = DefaultGroup) + where TCommand : ICommand + where TConfiguration : IConfiguration + { + group = string.IsNullOrWhiteSpace(group) ? DefaultGroup : group; + if (this.entries.Any(entry => entry.Group.Equals(group, StringComparison.InvariantCultureIgnoreCase) && entry.HasName(name))) + { + throw new CommandAlreadyRegisteredException(name, group); + } + RegistryEntry commandUsesConfiguration = this.entries.FirstOrDefault(entry => entry.Configuration == typeof(TConfiguration)); + if (commandUsesConfiguration != null) + { + throw new AmbiguousConfigurationException(typeof(TConfiguration), commandUsesConfiguration.Name, commandUsesConfiguration.Group); + } + RegistryEntry registryEntry = new RegistryEntry + { + Name = name, + Group = group, + Command = typeof(TCommand), + Configuration = typeof(TConfiguration) + }; + this.entries.Add(registryEntry); + return new RegisterSyntax(this, registryEntry); + } + + private RegistryEntry Find(string command, string group = null) + { + List found; + if (!string.IsNullOrEmpty(group)) + { + found = this.entries.Where(entry => entry.HasName(command) + && entry.Group.Equals(group, StringComparison.CurrentCultureIgnoreCase)) + .ToList(); + } + else + { + found = this.entries.Where(entry => entry.HasName(command) && entry.Group == DefaultGroup).ToList(); + if (found.Count == 0) + { + found = this.entries.Where(entry => entry.HasName(command)).ToList(); + } + if (found.Count > 1) + { + throw new AmbiguousCommandException($"Ambiguous command '{command}'. Use {string.Join(" or ", found.Select(x => $"'{x.Group}-{x.Name}'"))} instead."); + } + if (found.Count == 0) + { + found = this.entries.Where(entry => $"{entry.Group}-{entry.Name}".Equals(command, StringComparison.InvariantCultureIgnoreCase) + || entry.Aliases.Any(alias => $"{entry.Group}-{alias}".Equals(command, StringComparison.InvariantCultureIgnoreCase)) + ).ToList(); + } + } + if (found.Count == 0) + { + throw new CommandNotFoundException(command); + } + return found.Single(); + } + + public Type GetConfigurationType(string command, string group = null) + { + return this.Find(command, group)?.Configuration; + } + + public IConfiguration CreateConfiguration(string command, string group = null) + { + Type type = this.GetConfigurationType(command, group); + if (type == null) + { + return null; + } + IConfiguration configuration = (IConfiguration)this.resolver.Create(type); + if (configuration.Environment == null) + { + throw new CommandWithoutEnvironmentException(configuration.GetType()); + } + configuration.Environment.Command = command; + configuration.Environment.CommandGroup = group; + return configuration; + } + + public ICommand CreateCommand(IConfiguration configuration) + { + Type type = configuration.GetType(); + RegistryEntry entry = this.entries.FirstOrDefault(x => x.Configuration == type); + return entry == null ? null : (ICommand)this.resolver.Create(entry.Command); + } + + public List GetGroups() + { + return this.entries.Select(x => x.Group).Unique().ToList(); + } + + public interface IRegisterSyntax + { + IRegisterSyntax Register(string name, string group = DefaultGroup) + where TCommand : ICommand + where TConfiguration : IConfiguration; + + IRegisterSyntax Alias(params string[] aliases); + } + + private class RegisterSyntax : IRegisterSyntax + { + private readonly CommandRegistry commandRegistry; + private readonly RegistryEntry entry; + + public RegisterSyntax(CommandRegistry commandRegistry, RegistryEntry entry) + { + this.commandRegistry = commandRegistry; + this.entry = entry; + } + + public IRegisterSyntax Register(string name, string group = DefaultGroup) + where TCommand : ICommand + where TConfiguration : IConfiguration + { + return this.commandRegistry.Register(name, group); + } + + public IRegisterSyntax Alias(params string[] aliases) + { + this.entry.Aliases.AddRange(aliases); + return this; + } + } + + private class RegistryEntry + { + public string Name { get; set; } + public string Group { get; set; } + public Type Command { get; set; } + public Type Configuration { get; set; } + public List Aliases { get; } = new List(); + + public bool HasName(string name) + { + return this.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase) + || this.Aliases.Any(alias => alias.Equals(name, StringComparison.InvariantCultureIgnoreCase)); + } + } + } +} \ No newline at end of file diff --git a/Core/Command/CommandRunner.cs b/Core/Command/CommandRunner.cs deleted file mode 100644 index 149c1f36..00000000 --- a/Core/Command/CommandRunner.cs +++ /dev/null @@ -1,30 +0,0 @@ -using KY.Generator.Configurations; -using KY.Generator.Output; - -namespace KY.Generator.Command -{ - public class CommandRunner - { - private readonly CommandRegister commands; - - public CommandRunner(CommandRegister commands) - { - this.commands = commands; - } - - public bool Run(IConfiguration configuration, IOutput output) - { - if (configuration == null) - { - return false; - } - IGeneratorCommand command = this.commands.CreateCommand(configuration); - bool success = command.Execute(configuration); - if (success) - { - output.Execute(); - } - return success; - } - } -} \ No newline at end of file diff --git a/Core/Command/ICommand.cs b/Core/Command/ICommand.cs new file mode 100644 index 00000000..c663504a --- /dev/null +++ b/Core/Command/ICommand.cs @@ -0,0 +1,5 @@ +namespace KY.Generator.Command +{ + public interface ICommand + { } +} \ No newline at end of file diff --git a/Core/Command/ICommandLineCommand.cs b/Core/Command/ICommandLineCommand.cs new file mode 100644 index 00000000..d9efa95e --- /dev/null +++ b/Core/Command/ICommandLineCommand.cs @@ -0,0 +1,12 @@ +using KY.Generator.Configuration; + +namespace KY.Generator.Command +{ + /// + /// Command executed from the cli e.g. "KY-Programming.exe demo" + /// + public interface ICommandLineCommand : ICommand + { + bool Execute(IConfiguration configurationBase); + } +} \ No newline at end of file diff --git a/Core/Command/IConfigurationCommand.cs b/Core/Command/IConfigurationCommand.cs new file mode 100644 index 00000000..85a105b7 --- /dev/null +++ b/Core/Command/IConfigurationCommand.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using KY.Generator.Configuration; +using KY.Generator.Transfer; + +namespace KY.Generator.Command +{ + /// + /// Command executed from a configuration file e.g. a generator.json + /// + public interface IConfigurationCommand : ICommand + { + bool Execute(IConfiguration configurationBase, List transferObjects); + } +} \ No newline at end of file diff --git a/Core/Command/IGeneratorCommand.cs b/Core/Command/IGeneratorCommand.cs deleted file mode 100644 index 61097b8a..00000000 --- a/Core/Command/IGeneratorCommand.cs +++ /dev/null @@ -1,9 +0,0 @@ -using KY.Generator.Configurations; - -namespace KY.Generator.Command -{ - public interface IGeneratorCommand - { - bool Execute(IConfiguration configurationBase); - } -} \ No newline at end of file diff --git a/Core/Commands/Client/GeneratorConfiguration.cs b/Core/Commands/Client/GeneratorConfiguration.cs index 40dd4546..a31bd0ad 100644 --- a/Core/Commands/Client/GeneratorConfiguration.cs +++ b/Core/Commands/Client/GeneratorConfiguration.cs @@ -1,4 +1,4 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Client { diff --git a/Core/Commands/Client/GeneratorGenerator.cs b/Core/Commands/Client/GeneratorGenerator.cs deleted file mode 100644 index fe438e58..00000000 --- a/Core/Commands/Client/GeneratorGenerator.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using KY.Core; -using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Output; -using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; - -namespace KY.Generator.Client -{ - internal class GeneratorGenerator : Codeable, ITransferWriter - { - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) - { - Logger.Trace("Generate generator..."); - GeneratorConfiguration configuration = (GeneratorConfiguration)configurationBase; - } - } -} \ No newline at end of file diff --git a/Core/Transfer/Writers/DemoWriter.cs b/Core/Commands/DemoCommand.cs similarity index 52% rename from Core/Transfer/Writers/DemoWriter.cs rename to Core/Commands/DemoCommand.cs index e5743b85..21f661a7 100644 --- a/Core/Transfer/Writers/DemoWriter.cs +++ b/Core/Commands/DemoCommand.cs @@ -1,18 +1,19 @@ -using System.Collections.Generic; -using KY.Core; +using KY.Core; +using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Configurations; -using KY.Generator.Output; -namespace KY.Generator.Transfer.Writers +namespace KY.Generator.Commands { - public class DemoWriter : ITransferWriter + public class DemoCommand : ICommandLineCommand { - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) + public bool Execute(IConfiguration configurationBase) { DemoConfiguration configuration = (DemoConfiguration)configurationBase; Logger.Trace(configuration.Message); Logger.Trace("See full documentation on https://github.com/KY-Programming/generator/wiki"); + return true; } } } \ No newline at end of file diff --git a/Core/Commands/ExecuteCommand.cs b/Core/Commands/ExecuteCommand.cs new file mode 100644 index 00000000..8fd40580 --- /dev/null +++ b/Core/Commands/ExecuteCommand.cs @@ -0,0 +1,86 @@ +using KY.Core; +using KY.Core.DataAccess; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Configurations; +using KY.Generator.Extensions; +using KY.Generator.Output; + +namespace KY.Generator.Commands +{ + internal class ExecuteCommand : ICommandLineCommand + { + private readonly ConfigurationsReader reader; + private readonly ConfigurationRunner runner; + + public ExecuteCommand(ConfigurationsReader reader, ConfigurationRunner runner) + { + this.reader = reader; + this.runner = runner; + } + + public bool Execute(IConfiguration configurationBase) + { + ExecuteConfiguration configuration = (ExecuteConfiguration)configurationBase; + string serializedConfiguration; + if (!string.IsNullOrEmpty(configuration.Configuration)) + { + serializedConfiguration = configuration.Configuration; + } + else + { + if (string.IsNullOrEmpty(configuration.File)) + { + Logger.Error("Execute command without -file parameter found"); + return false; + } + if (!FileSystem.FileExists(configuration.File)) + { + Logger.Error($"Execute command can not find file \"{configuration.File}\". Searched in \"{FileSystem.Parent(FileSystem.ToAbsolutePath(configuration.File))}\""); + return false; + } + if (configuration.Output == null) + { + configuration.Output = new FileOutput(FileSystem.Parent(configuration.File)); + Logger.Trace($"Output: {configuration.Output}"); + } + serializedConfiguration = FileSystem.ReadAllText(configuration.File); + } + Logger.Trace("Read configurations..."); + ExecuteConfiguration executeConfiguration = this.reader.Parse(serializedConfiguration); + executeConfiguration.Execute.Flatten().ForEach(x => x.Output = configuration.Output); + return this.runner.Run(executeConfiguration.Yield()); + } + + //private bool Run(string serializedConfiguration, string path, CommandConfiguration configuration, IOutput output) + //{ + // List configurations = this.Deserialize(serializedConfiguration, output); + // ConfigurationEnvironment environment = new ConfigurationEnvironment(path, output.ToString()); + // configurations.SelectMany(x => x.Configurations) + // .ForEach(x => x.Environment = environment); + // return this.Run(configurations, configuration, output); + //} + + //private bool Run(List configurations, CommandConfiguration configuration, IOutput output) + //{ + // configuration.AssertIsNotNull(nameof(configurations), "No configuration loaded. Generation failed!"); + // bool isBeforeBuild = configuration.Parameters.Exists("beforeBuild"); + // if (isBeforeBuild) + // { + // Logger.Trace("Run only configurations flagged with \"beforeBuild\": true"); + // } + // if (configurations == null || configurations.Count == 0) + // { + // Logger.Trace("No configuration loaded. Provide at least one entry like: ...\"generate\": [{\"write\": \"demo\"}]..."); + // return false; + // } + // if (configurations.Any(x => x.Configurations.Any(y => !y.VerifySsl))) + // { + // ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; + // } + // bool success = this.runner.Run(configurations, output, isBeforeBuild); + // Logger.Trace("All configurations generated"); + // return success; + //} + } +} \ No newline at end of file diff --git a/Core/Transfer/Readers/ExecuteReader.cs b/Core/Commands/ExecuteSeparateCommand.cs similarity index 80% rename from Core/Transfer/Readers/ExecuteReader.cs rename to Core/Commands/ExecuteSeparateCommand.cs index b66d8e15..12a42b1f 100644 --- a/Core/Transfer/Readers/ExecuteReader.cs +++ b/Core/Commands/ExecuteSeparateCommand.cs @@ -4,13 +4,16 @@ using System.Reflection; using KY.Core; using KY.Core.DataAccess; +using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Configurations; +using KY.Generator.Transfer; -namespace KY.Generator.Transfer.Readers +namespace KY.Generator.Commands { - internal class ExecuteReader : ITransferReader + internal class ExecuteSeparateCommand : IConfigurationCommand { - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { ExecuteConfiguration configuration = (ExecuteConfiguration)configurationBase; if (configuration.File == configuration.Environment.ConfigurationFilePath) @@ -25,12 +28,12 @@ public void Read(ConfigurationBase configurationBase, List tran if (executable.EndsWith(".exe")) { process.StartInfo.FileName = executable; - process.StartInfo.Arguments = $"\"{configurationPath}\" \"{FileSystem.Parent(configurationPath)}\" -forwardLogging"; + process.StartInfo.Arguments = $"execute -file=\"{configurationPath}\" -forwardLogging"; } else { process.StartInfo.FileName = "dotnet"; - process.StartInfo.Arguments = $"\"{executable}\" \"{configurationPath}\" \"{FileSystem.Parent(configurationPath)}\" -forwardLogging"; + process.StartInfo.Arguments = $"\"{executable}\" execute -file=\"{configurationPath}\" -forwardLogging"; } process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; @@ -44,6 +47,7 @@ public void Read(ConfigurationBase configurationBase, List tran Logger.Trace(line); } Logger.Trace($"Process exited with code {process.ExitCode}"); + return process.ExitCode == 0; } } } \ No newline at end of file diff --git a/Core/Commands/ModelWriteCommand.cs b/Core/Commands/ModelWriteCommand.cs new file mode 100644 index 00000000..e9972b06 --- /dev/null +++ b/Core/Commands/ModelWriteCommand.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using KY.Core; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Extensions; +using KY.Generator.Templates; +using KY.Generator.Transfer; +using KY.Generator.Transfer.Writers; + +namespace KY.Generator.Commands +{ + public class ModelWriteCommand : IConfigurationCommand + { + private readonly ModelWriter writer; + + public ModelWriteCommand(ModelWriter writer) + { + this.writer = writer; + } + + public bool Execute(IConfiguration configurationBase, List transferObjects) + { + Logger.Trace("Write model..."); + configurationBase.Output.AssertIsNotNull(message: $"The output of '{configurationBase.Environment.Command}' command is not set"); + IModelConfiguration configuration = (IModelConfiguration)configurationBase; + List files = this.writer.Write(configuration, transferObjects); + files.Write(configuration); + return true; + } + } +} \ No newline at end of file diff --git a/Core/Transfer/Readers/CookieReader.cs b/Core/Commands/ReadCookieCommand.cs similarity index 82% rename from Core/Transfer/Readers/CookieReader.cs rename to Core/Commands/ReadCookieCommand.cs index ce22d837..14b34d5e 100644 --- a/Core/Transfer/Readers/CookieReader.cs +++ b/Core/Commands/ReadCookieCommand.cs @@ -1,13 +1,16 @@ using System.Collections.Generic; using System.Net; using KY.Core; +using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Configurations; +using KY.Generator.Transfer; -namespace KY.Generator.Transfer.Readers +namespace KY.Generator.Commands { - public class CookieReader : ITransferReader + public class ReadCookieCommand : IConfigurationCommand { - public virtual void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { CookieConfiguration configuration = (CookieConfiguration)configurationBase; if (!string.IsNullOrEmpty(configuration.Url)) @@ -18,6 +21,7 @@ public virtual void Read(ConfigurationBase configurationBase, List(new Cookie(configuration.Name, configuration.Value, configuration.Path, configuration.Domain))); } + return true; } private void ReadFromUrl(CookieConfiguration configuration, List list) diff --git a/Core/Commands/RunCommand.cs b/Core/Commands/RunCommand.cs deleted file mode 100644 index eef6efc0..00000000 --- a/Core/Commands/RunCommand.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Net; -using KY.Core; -using KY.Core.DataAccess; -using KY.Core.Dependency; -using KY.Core.Module; -using KY.Generator.Command; -using KY.Generator.Configuration; -using KY.Generator.Output; - -namespace KY.Generator.Commands -{ - internal class RunCommand : IGeneratorCommand - { - private readonly List modules; - private readonly IDependencyResolver resolver; - private readonly ConfigurationRunner runner; - public string[] Names { get; } = { "run" }; - - public RunCommand(List modules, IDependencyResolver resolver, ConfigurationRunner runner) - { - this.modules = modules; - this.resolver = resolver; - this.runner = runner; - } - - public bool Generate(CommandConfiguration configuration, ref IOutput output) - { - Logger.Trace("Execute run command..."); - string outputPath = configuration.Parameters.GetString("output"); - if (!string.IsNullOrEmpty(outputPath)) - { - output = new FileOutput(outputPath); - } - if (output == null) - { - Logger.Error("No valid output specified"); - return false; - } - Logger.Trace("Output: " + output); - string path = configuration.Parameters.GetString("path"); - if (!string.IsNullOrEmpty(path)) - { - Logger.Trace("Read settings from: " + path); - return this.Run(FileSystem.ReadAllText(path), path, configuration, output); - } - string serialized = configuration.Parameters.GetString("configuration"); - if (!string.IsNullOrEmpty(serialized)) - { - Logger.Trace("Read settings from: Memory"); - return this.Run(serialized, configuration, output); - } - Logger.Error("Invalid parameters: Provide at least path to config file)"); - return false; - } - - public bool Run(string serializedConfiguration, CommandConfiguration configuration, IOutput output) - { - List configurations = this.Deserialize(serializedConfiguration, output); - return this.Run(configurations, configuration, output); - } - - private bool Run(string serializedConfiguration, string path, CommandConfiguration configuration, IOutput output) - { - List configurations = this.Deserialize(serializedConfiguration, output); - ConfigurationEnvironment environment = new ConfigurationEnvironment(path, output.ToString()); - configurations.SelectMany(x => x.Configurations) - .ForEach(x => x.Environment = environment); - return this.Run(configurations, configuration, output); - } - - private List Deserialize(string configuration, IOutput output) - { - ConfigurationsReader configurationsReader = this.resolver.Create(); - return configurationsReader.Parse(configuration, output); - } - - private bool Run(List configurations, CommandConfiguration configuration, IOutput output) - { - configuration.AssertIsNotNull(nameof(configurations), "No configuration loaded. Generation failed!"); - bool isBeforeBuild = configuration.Parameters.Exists("beforeBuild"); - if (isBeforeBuild) - { - Logger.Trace("Run only configurations flagged with \"beforeBuild\": true"); - } - if (configurations == null || configurations.Count == 0) - { - Logger.Trace("No configuration loaded. Provide at least one entry like: ...\"generate\": [{\"write\": \"demo\"}]..."); - return false; - } - if (configurations.Any(x => x.Configurations.Any(y => !y.VerifySsl))) - { - ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; - } - bool success = this.runner.Run(configurations, output, isBeforeBuild); - Logger.Trace("All configurations generated"); - return success; - } - } -} \ No newline at end of file diff --git a/Core/Commands/VersionCommand.cs b/Core/Commands/VersionCommand.cs index 2a06ba7f..1d249035 100644 --- a/Core/Commands/VersionCommand.cs +++ b/Core/Commands/VersionCommand.cs @@ -3,11 +3,12 @@ using System.Reflection; using KY.Core; using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Configurations; namespace KY.Generator.Commands { - internal class VersionCommand : IGeneratorCommand + internal class VersionCommand : ICommandLineCommand { public bool Execute(IConfiguration configurationBase) { diff --git a/Core/Configuration/ConfigurationBase.cs b/Core/Configuration/ConfigurationBase.cs index 02f36fb3..510881b2 100644 --- a/Core/Configuration/ConfigurationBase.cs +++ b/Core/Configuration/ConfigurationBase.cs @@ -1,26 +1,14 @@ using System.Collections.Generic; -using KY.Generator.Configuration; -using KY.Generator.Languages; using KY.Generator.Mappings; using KY.Generator.Output; using Newtonsoft.Json; -namespace KY.Generator.Configurations +namespace KY.Generator.Configuration { public abstract class ConfigurationBase : IConfiguration { - public bool VerifySsl { get; set; } = true; - - [JsonIgnore] - [ConfigurationIgnore] - public ILanguage Language { get; set; } - - [JsonProperty("Language")] - [ConfigurationProperty("Language")] - internal string LanguageKey { get; set; } - - public bool AddHeader { get; set; } = true; - public virtual bool RequireLanguage => true; + public virtual bool VerifySsl { get; set; } = true; + public virtual bool AddHeader { get; set; } = true; [JsonIgnore] public bool SkipHeader @@ -29,43 +17,45 @@ public bool SkipHeader set => this.AddHeader = !value; } - public List ClassMapping { get; } - public List FieldMapping { get; } - public List PropertyMapping { get; } - public ConfigurationFormatting Formatting { get; set; } + public virtual List ClassMapping { get; } + public virtual List FieldMapping { get; } + public virtual List PropertyMapping { get; } + public virtual ConfigurationFormatting Formatting { get; set; } [JsonIgnore] - public bool Standalone { get; set; } + public virtual bool Standalone { get; set; } [JsonIgnore] - public ConfigurationEnvironment Environment { get; set; } + public virtual ConfigurationEnvironment Environment { get; set; } [JsonIgnore] - public IOutput Output { get; set; } + public virtual IOutput Output { get; set; } - public bool CheckOnOverwrite { get; set; } = true; - public bool BeforeBuild { get; set; } + public virtual bool CheckOnOverwrite { get; set; } = true; + public virtual bool BeforeBuild { get; set; } protected ConfigurationBase() { this.ClassMapping = new List(); this.FieldMapping = new List(); this.PropertyMapping = new List(); - this.Environment = new ConfigurationEnvironment(null, null); + this.Environment = new ConfigurationEnvironment(); this.Formatting = new ConfigurationFormatting(); } - public virtual void CopyBaseFrom(ConfigurationBase source) + public virtual void CopyBaseFrom(IConfiguration source) { - this.VerifySsl = source.VerifySsl; - this.Language = source.Language; - this.AddHeader = source.AddHeader; - this.ClassMapping.AddRange(source.ClassMapping); - this.FieldMapping.AddRange(source.FieldMapping); - this.PropertyMapping.AddRange(source.PropertyMapping); - this.Standalone = source.Standalone; this.Environment = source.Environment; this.Formatting = source.Formatting; + if (source is ConfigurationBase configurationBase) + { + this.VerifySsl = configurationBase.VerifySsl; + this.AddHeader = configurationBase.AddHeader; + this.ClassMapping.AddRange(configurationBase.ClassMapping); + this.FieldMapping.AddRange(configurationBase.FieldMapping); + this.PropertyMapping.AddRange(configurationBase.PropertyMapping); + this.Standalone = configurationBase.Standalone; + } } } } \ No newline at end of file diff --git a/Core/Configuration/ConfigurationEnvironment.cs b/Core/Configuration/ConfigurationEnvironment.cs index 8ce7648b..be001c1a 100644 --- a/Core/Configuration/ConfigurationEnvironment.cs +++ b/Core/Configuration/ConfigurationEnvironment.cs @@ -5,11 +5,13 @@ namespace KY.Generator.Configuration { public class ConfigurationEnvironment { - public string ConfigurationFilePath { get; } - public string OutputPath { get; } + public string ConfigurationFilePath { get; set; } + public string OutputPath { get; set; } public List Parameters { get; } + public string Command { get; set; } + public string CommandGroup { get; set; } - public ConfigurationEnvironment(string configurationFilePath, string outputPath) + public ConfigurationEnvironment(string configurationFilePath = null, string outputPath = null) { this.ConfigurationFilePath = configurationFilePath; this.OutputPath = outputPath; diff --git a/Core/Configuration/ConfigurationMapping.cs b/Core/Configuration/ConfigurationMapping.cs deleted file mode 100644 index 0fc4eb2f..00000000 --- a/Core/Configuration/ConfigurationMapping.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using KY.Core; -using KY.Core.Dependency; -using KY.Generator.Configurations; -using KY.Generator.Transfer.Readers; -using KY.Generator.Transfer.Writers; - -namespace KY.Generator.Configuration -{ - public class ConfigurationMapping - { - private readonly IDependencyResolver resolver; - private readonly List mapping; - - public ConfigurationMapping(IDependencyResolver resolver) - { - this.resolver = resolver; - this.mapping = new List(); - } - - public void Map(string name, string action) - where TConfiguration : IConfiguration - { - name.AssertIsNotNull(nameof(name)); - if (this.mapping.Any(entry => entry.Action.Equals(action, StringComparison.InvariantCultureIgnoreCase) && entry.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))) - { - throw new InvalidOperationException($"{name} is already mapped. Please use a prefix like my-{name}"); - } - if (this.mapping.Any(entry => entry.Action.Equals(action, StringComparison.InvariantCultureIgnoreCase) && entry.Configuration == typeof(TConfiguration))) - { - throw new InvalidOperationException($"{typeof(TConfiguration)} is already mapped. Please create a derived class"); - } - this.mapping.Add(new ConfigurationMappingEntry(action, name.ToLowerInvariant(), typeof(TConfiguration), typeof(TActor))); - } - - public ConfigurationMapping Map(string name) - where TConfiguration : IConfiguration - { - bool isReader = typeof(ITransferReader).IsAssignableFrom(typeof(TActor)); - bool isWriter = typeof(ITransferWriter).IsAssignableFrom(typeof(TActor)); - if (!isReader && !isWriter) - { - throw new InvalidOperationException($"{name} has to be at least a {nameof(ITransferReader)} or {nameof(ITransferWriter)}"); - } - if (isReader) - { - this.Map(name, "read"); - } - if (isWriter) - { - this.Map(name, "write"); - } - return this; - } - - public Type ResolveConfiguration(string name, string action) - { - action.AssertIsNotNull(nameof(action)); - name.AssertIsNotNull(nameof(name)); - ConfigurationMappingEntry entry = this.mapping.FirstOrDefault(e => e.Action.Equals(action, StringComparison.InvariantCultureIgnoreCase) - && e.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)); - if (entry == null) - { - throw new InvalidOperationException($"{action.FirstCharToUpper()} {name} not found. Please check if the module was loaded"); - } - return entry.Configuration; - } - - public object Resolve(IConfiguration configuration) - { - configuration.AssertIsNotNull(nameof(configuration)); - ConfigurationMappingEntry entry = this.mapping.FirstOrDefault(e => e.Configuration == configuration.GetType()); - if (entry == null) - { - throw new InvalidOperationException($"Actor for {configuration.GetType().Name} not found. Please check if the module was loaded"); - } - return this.resolver.Create(entry.Actor); - } - - public List GetActions() - { - return this.mapping.Select(x => x.Action).Unique().ToList(); - } - } -} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationMappingEntry.cs b/Core/Configuration/ConfigurationMappingEntry.cs deleted file mode 100644 index da2934c6..00000000 --- a/Core/Configuration/ConfigurationMappingEntry.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -namespace KY.Generator.Configuration -{ - public class ConfigurationMappingEntry - { - public string Action { get; } - public string Name { get; } - public Type Configuration { get; } - public Type Actor { get; } - - public ConfigurationMappingEntry(string action, string name, Type configuration, Type actor) - { - this.Action = action; - this.Name = name; - this.Configuration = configuration; - this.Actor = actor; - } - } -} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationReaderVersion2.cs b/Core/Configuration/ConfigurationReaderVersion2.cs index a55bcf67..de4e8673 100644 --- a/Core/Configuration/ConfigurationReaderVersion2.cs +++ b/Core/Configuration/ConfigurationReaderVersion2.cs @@ -1,9 +1,14 @@ using System; using System.Collections.Generic; using System.Linq; +using KY.Core; using KY.Core.Dependency; +using KY.Generator.Command; using KY.Generator.Configurations; +using KY.Generator.Exceptions; +using KY.Generator.Extensions; using KY.Generator.Languages; +using KY.Generator.Load; using Newtonsoft.Json.Linq; namespace KY.Generator.Configuration @@ -19,60 +24,61 @@ public ConfigurationReaderVersion2(IDependencyResolver resolver) this.resolver = resolver; } - public List Read(ConfigurationVersion version) + public ExecuteConfiguration Read(JObject rawConfiguration) { - List list = new List(); - if (version.Generate is JObject obj) + ExecuteConfiguration configuration = rawConfiguration.ToObject(); + if (configuration.Load != null && configuration.Load.Count > 0) { - ConfigurationSet set = new ConfigurationSet(); - this.ReadToSet(obj, set); - list.Add(set); + this.resolver.Create().Load(configuration.Load); } - else if (version.Generate is JArray array) + ConfigurationVersion2 configuration2 = rawConfiguration.ToObject(); + if (configuration2.Execute == null) { - if (array.First is JObject) + throw new InvalidConfigurationException("Invalid configuration found. 'execute' tag is missing."); + } + if (configuration2.Execute is JObject obj) + { + configuration.Execute.Add(this.ReadConfiguration(obj)); + } + else if (configuration2.Execute is JArray array) + { + foreach (JToken token in array) { - ConfigurationSet set = new ConfigurationSet(); - foreach (JObject entry in array.OfType()) + if (token is JObject jObject) { - this.ReadToSet(entry, set); + configuration.Execute.Add(this.ReadConfiguration(jObject)); } - list.Add(set); - } - else if (array.First is JArray) - { - foreach (JArray innerArray in array.OfType()) + else { - ConfigurationSet set = new ConfigurationSet(); - foreach (JObject entry in innerArray.OfType()) - { - this.ReadToSet(entry, set); - } - list.Add(set); + throw new InvalidConfigurationException($"Invalid configuration found. Unknown entry in 'execute' tag found. Expected 'Object' but got '{token.Type}'"); } } } - list.ForEach(pair => pair.Configurations.ForEach(configuration => configuration.Formatting = configuration.Formatting ?? version.Formatting)); - return list; + return configuration; } - private void ReadToSet(JObject token, ConfigurationSet set) + private IConfiguration ReadConfiguration(JObject rawConfiguration) { - ConfigurationMapping mapping = this.resolver.Get(); - List actions = mapping.GetActions(); - JProperty property = token.Properties().FirstOrDefault(p => actions.Any(action => action.Equals(p.Name, StringComparison.InvariantCultureIgnoreCase))); - string configurationName = property?.Value?.ToString(); - if (configurationName != null) + CommandRegistry commands = this.resolver.Get(); + List groups = commands.GetGroups(); + JProperty property = rawConfiguration.Properties().FirstOrDefault(p => groups.Any(action => action.Equals(p.Name, StringComparison.InvariantCultureIgnoreCase))); + if (property == null) { - ConfigurationBase configurationBase = (ConfigurationBase)token.ToObject(mapping.ResolveConfiguration(configurationName, property.Name)); - this.Prepare(configurationBase); - set.Configurations.Add(configurationBase); + JProperty firstProperty = rawConfiguration.Properties().FirstOrDefault(); + string command = firstProperty == null ? "{ }" : $"{{ \"{firstProperty.Name}\": \"{firstProperty.Value}\", ... }}"; + throw new UnknownCommandException(command); } - } - - private void Prepare(ConfigurationBase configurationBase) - { - configurationBase.Language = configurationBase.Language ?? this.resolver.Get>().FirstOrDefault(x => x.Name.Equals(configurationBase.LanguageKey, StringComparison.InvariantCultureIgnoreCase)); + Type type = commands.GetConfigurationType(property.Value.ToString(), property.Name); + IConfiguration configuration = (IConfiguration)rawConfiguration.ToObject(type); + configuration.Environment.Command = property.Name; + configuration.Environment.CommandGroup = property.Value.ToString(); + if (configuration is IConfigurationWithLanguage configurationWithLanguage) + { + List languages = this.resolver.Get>(); + configurationWithLanguage.Language = languages.FirstOrDefault(language => language.Name.Equals(configurationWithLanguage.LanguageKey, StringComparison.InvariantCultureIgnoreCase)) + ?? configurationWithLanguage.Language; + } + return configuration; } } } \ No newline at end of file diff --git a/Core/Configuration/ConfigurationSet.cs b/Core/Configuration/ConfigurationSet.cs deleted file mode 100644 index 5745b584..00000000 --- a/Core/Configuration/ConfigurationSet.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Collections.Generic; -using KY.Generator.Configurations; - -namespace KY.Generator.Configuration -{ - public class ConfigurationSet - { - public List Configurations { get; } - - public ConfigurationSet() - { - this.Configurations = new List(); - } - } -} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationVersion.cs b/Core/Configuration/ConfigurationVersion.cs index b14185ec..0d8d3315 100644 --- a/Core/Configuration/ConfigurationVersion.cs +++ b/Core/Configuration/ConfigurationVersion.cs @@ -1,14 +1,7 @@ -using System.Collections.Generic; -using Newtonsoft.Json.Linq; - -namespace KY.Generator.Configuration +namespace KY.Generator.Configuration { internal class ConfigurationVersion { public int Version { get; set; } - public List Load { get; set; } - public ConfigurationFormatting Formatting { get; set; } - public string Output { get; set; } - public JContainer Generate { get; set; } } } \ No newline at end of file diff --git a/Core/Configuration/ConfigurationVersion2.cs b/Core/Configuration/ConfigurationVersion2.cs new file mode 100644 index 00000000..553c8fe0 --- /dev/null +++ b/Core/Configuration/ConfigurationVersion2.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace KY.Generator.Configuration +{ + internal class ConfigurationVersion2 : ConfigurationVersion + { + [JsonProperty("generate")] + public JToken Execute { get; set; } + } +} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationWithLanguageBase.cs b/Core/Configuration/ConfigurationWithLanguageBase.cs new file mode 100644 index 00000000..87cc2951 --- /dev/null +++ b/Core/Configuration/ConfigurationWithLanguageBase.cs @@ -0,0 +1,25 @@ +using KY.Generator.Languages; +using Newtonsoft.Json; + +namespace KY.Generator.Configuration +{ + public abstract class ConfigurationWithLanguageBase : ConfigurationBase, IConfigurationWithLanguage + { + [JsonIgnore] + [ConfigurationIgnore] + public virtual ILanguage Language { get; set; } + + [JsonProperty("Language")] + [ConfigurationProperty("Language")] + public virtual string LanguageKey { get; set; } + + public override void CopyBaseFrom(IConfiguration source) + { + base.CopyBaseFrom(source); + if (source is IConfigurationWithLanguage configurationWithLanguage) + { + this.Language = configurationWithLanguage.Language; + } + } + } +} \ No newline at end of file diff --git a/Core/Configuration/ConfigurationsReader.cs b/Core/Configuration/ConfigurationsReader.cs index 2693e764..1f6db377 100644 --- a/Core/Configuration/ConfigurationsReader.cs +++ b/Core/Configuration/ConfigurationsReader.cs @@ -3,9 +3,7 @@ using System.IO; using System.Linq; using KY.Core; -using KY.Core.Dependency; -using KY.Generator.Load; -using KY.Generator.Output; +using KY.Generator.Configurations; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -13,51 +11,37 @@ namespace KY.Generator.Configuration { internal class ConfigurationsReader { - private readonly IDependencyResolver resolver; - private readonly Dictionary versions; + private readonly Dictionary readers; - public ConfigurationsReader(IDependencyResolver resolver, IEnumerable versions) + public ConfigurationsReader(IEnumerable readers) { - this.resolver = resolver; - this.versions = versions.ToDictionary(x => x.Version, x => x); + this.readers = readers.ToDictionary(x => x.Version, x => x); } - public List Parse(string json, IOutput output = null) + public ExecuteConfiguration Parse(string json) { using (JsonTextReader reader = new JsonTextReader(new StringReader(json))) { - JObject jObject; + JObject rawConfiguration; try { - jObject = JObject.Load(reader); + rawConfiguration = JObject.Load(reader); } catch (Exception exception) { - throw new InvalidConfigurationException("Can not load json. See inner exception for details", exception); + throw new InvalidConfigurationException("Invalid json. See inner exception for details", exception); } - ConfigurationVersion version = jObject.ToObject(); - if (version?.Generate == null) + ConfigurationVersion configuration = rawConfiguration.ToObject(); + if (configuration.Version == 0) { - throw new InvalidConfigurationException("Unsupported configuration found. Generate tag is missing."); + configuration.Version = this.readers.Max(x => x.Key); + Logger.Warning($"No version found. Fallback to {configuration.Version}"); } - if (version.Version == 0) + if (this.readers.ContainsKey(configuration.Version)) { - version.Version = this.versions.Max(x => x.Key); - Logger.Warning($"No version found. Fallback to {version.Version}"); + return this.readers[configuration.Version].Read(rawConfiguration); } - if (version.Load != null && version.Load.Count > 0) - { - this.resolver.Create().Load(version.Load); - } - if (!string.IsNullOrEmpty(version.Output)) - { - output?.Move(version.Output); - } - if (this.versions.ContainsKey(version.Version)) - { - return this.versions[version.Version].Read(version); - } - throw new InvalidConfigurationException($"No reader for version {version.Version} found"); + throw new InvalidConfigurationException($"No reader for version {configuration.Version} found"); } } } diff --git a/Core/Configuration/IConfiguration.cs b/Core/Configuration/IConfiguration.cs index 8267efe6..4d4adcd4 100644 --- a/Core/Configuration/IConfiguration.cs +++ b/Core/Configuration/IConfiguration.cs @@ -1,14 +1,12 @@ -using KY.Generator.Configuration; -using KY.Generator.Languages; using KY.Generator.Output; -namespace KY.Generator.Configurations +namespace KY.Generator.Configuration { public interface IConfiguration { - ILanguage Language { get; } ConfigurationFormatting Formatting { get; } - IOutput Output { get; } + IOutput Output { get; set; } ConfigurationEnvironment Environment { get; } + bool BeforeBuild { get; set; } } } \ No newline at end of file diff --git a/Core/Configuration/IConfigurationReaderVersion.cs b/Core/Configuration/IConfigurationReaderVersion.cs index b6c7b120..6215cbe7 100644 --- a/Core/Configuration/IConfigurationReaderVersion.cs +++ b/Core/Configuration/IConfigurationReaderVersion.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; +using KY.Generator.Configurations; +using Newtonsoft.Json.Linq; namespace KY.Generator.Configuration { internal interface IConfigurationReaderVersion { int Version { get; } - List Read(ConfigurationVersion version); + ExecuteConfiguration Read(JObject rawConfiguration); } } \ No newline at end of file diff --git a/Core/Configuration/IConfigurationWithLanguage.cs b/Core/Configuration/IConfigurationWithLanguage.cs new file mode 100644 index 00000000..ab5ff562 --- /dev/null +++ b/Core/Configuration/IConfigurationWithLanguage.cs @@ -0,0 +1,10 @@ +using KY.Generator.Languages; + +namespace KY.Generator.Configuration +{ + public interface IConfigurationWithLanguage : IConfiguration + { + ILanguage Language { get; set; } + string LanguageKey { get; set; } + } +} \ No newline at end of file diff --git a/Core/Configuration/IFormattableConfiguration.cs b/Core/Configuration/IFormattableConfiguration.cs index f362ba86..7c986ac2 100644 --- a/Core/Configuration/IFormattableConfiguration.cs +++ b/Core/Configuration/IFormattableConfiguration.cs @@ -1,4 +1,4 @@ -namespace KY.Generator.Configurations +namespace KY.Generator.Configuration { public interface IFormattableConfiguration : IConfiguration { diff --git a/Core/Configuration/IModelConfiguration.cs b/Core/Configuration/IModelConfiguration.cs index 1244787e..39dd90b9 100644 --- a/Core/Configuration/IModelConfiguration.cs +++ b/Core/Configuration/IModelConfiguration.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -namespace KY.Generator.Configurations +namespace KY.Generator.Configuration { - public interface IModelConfiguration : IFormattableConfiguration + public interface IModelConfiguration : IConfigurationWithLanguage, IFormattableConfiguration { string Name { get; set; } string Namespace { get; } diff --git a/Core/Configuration/ReadConfigurationBase.cs b/Core/Configuration/ReadConfigurationBase.cs deleted file mode 100644 index ea41a74d..00000000 --- a/Core/Configuration/ReadConfigurationBase.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace KY.Generator.Configurations -{ - public abstract class ReadConfigurationBase : ConfigurationBase - { - public override bool RequireLanguage => false; - } -} \ No newline at end of file diff --git a/Core/Configurations/CookieConfiguration.cs b/Core/Configurations/CookieConfiguration.cs index 394c24b9..4b576dec 100644 --- a/Core/Configurations/CookieConfiguration.cs +++ b/Core/Configurations/CookieConfiguration.cs @@ -4,8 +4,6 @@ namespace KY.Generator.Configurations { public class CookieConfiguration : ConfigurationBase { - public override bool RequireLanguage => false; - public string Url { get; set; } public string Name { get; set; } public string Value { get; set; } diff --git a/Core/Configurations/DemoConfiguration.cs b/Core/Configurations/DemoConfiguration.cs index 6fd6cc18..715e924c 100644 --- a/Core/Configurations/DemoConfiguration.cs +++ b/Core/Configurations/DemoConfiguration.cs @@ -1,6 +1,8 @@ -namespace KY.Generator.Configurations +using KY.Generator.Configuration; + +namespace KY.Generator.Configurations { - public class DemoConfiguration : ReadConfigurationBase + public class DemoConfiguration : ConfigurationBase { public string Message { get; set; } } diff --git a/Core/Configurations/ExecuteConfiguration.cs b/Core/Configurations/ExecuteConfiguration.cs index 37054173..462147e8 100644 --- a/Core/Configurations/ExecuteConfiguration.cs +++ b/Core/Configurations/ExecuteConfiguration.cs @@ -1,12 +1,32 @@ -using KY.Generator.Configuration; +using System.Collections.Generic; +using KY.Generator.Configuration; +using Newtonsoft.Json; namespace KY.Generator.Configurations { - public class ExecuteConfiguration : ReadConfigurationBase + public class ExecuteConfiguration : ConfigurationBase { + public int Version { get; set; } + public List Load { get; set; } + + [JsonProperty("Output")] + public string OutputPath { get; set; } + + + [ConfigurationProperty("f")] public string File { get; set; } + [ConfigurationProperty("c")] [ConfigurationProperty("config")] public string Configuration { get; set; } + + [ConfigurationIgnore] + [JsonIgnore] + public List Execute { get; set; } + + public ExecuteConfiguration() + { + this.Execute = new List(); + } } } \ No newline at end of file diff --git a/Core/Configurations/ExecuteSeparateConfiguration.cs b/Core/Configurations/ExecuteSeparateConfiguration.cs new file mode 100644 index 00000000..47d6db18 --- /dev/null +++ b/Core/Configurations/ExecuteSeparateConfiguration.cs @@ -0,0 +1,7 @@ +namespace KY.Generator.Configurations +{ + public class ExecuteSeparateConfiguration : ExecuteConfiguration + { + + } +} \ No newline at end of file diff --git a/Core/Configurations/ModelWriteConfiguration.cs b/Core/Configurations/ModelWriteConfiguration.cs index e33d4a8d..846124c2 100644 --- a/Core/Configurations/ModelWriteConfiguration.cs +++ b/Core/Configurations/ModelWriteConfiguration.cs @@ -1,8 +1,9 @@ using System.Collections.Generic; +using KY.Generator.Configuration; namespace KY.Generator.Configurations { - public class ModelWriteConfiguration : ConfigurationBase, IModelConfiguration + public class ModelWriteConfiguration : ConfigurationWithLanguageBase, IModelConfiguration { public string Name { get; set; } public string Namespace { get; set; } diff --git a/Core/Configurations/TemplateConfiguration.cs b/Core/Configurations/TemplateConfiguration.cs index f0b43bb4..86c761c1 100644 --- a/Core/Configurations/TemplateConfiguration.cs +++ b/Core/Configurations/TemplateConfiguration.cs @@ -1,4 +1,6 @@ -namespace KY.Generator.Configurations +using KY.Generator.Configuration; + +namespace KY.Generator.Configurations { public class TemplateConfiguration : ConfigurationBase { } diff --git a/Core/CoreModule.cs b/Core/CoreModule.cs index b7ff8edd..c27ab557 100644 --- a/Core/CoreModule.cs +++ b/Core/CoreModule.cs @@ -1,13 +1,10 @@ using System.Runtime.CompilerServices; using KY.Core.Dependency; using KY.Core.Module; -using KY.Generator.Client; using KY.Generator.Command; using KY.Generator.Commands; -using KY.Generator.Configuration; using KY.Generator.Configurations; using KY.Generator.Languages; -using KY.Generator.Transfer.Readers; using KY.Generator.Transfer.Writers; [assembly: InternalsVisibleTo("KY.Generator.Tests")] @@ -31,24 +28,17 @@ public CoreModule(IDependencyResolver dependencyResolver) public override void Initialize() { - this.DependencyResolver.Get() - .Register("client") - .Register("version") - .Register("v") - .Register("execute") - .Register("exec") - .Register("e") - .Register("run") - .Register("r"); - this.DependencyResolver.Bind().To(); - this.DependencyResolver.Bind().To(); this.DependencyResolver.Bind().To(); - this.DependencyResolver.Get() - .Map("cookie") - .Map("generator") - .Map("model") - .Map("demo") - .Map("generator", "execute"); + this.DependencyResolver.Bind().ToSelf(); + this.DependencyResolver.Get() + //.Register("client") + .Register("version").Alias("v") + .Register("execute").Alias("exec", "e").Alias("run", "r") + .Register("separate") + .Register("cookie", "read") + //.Register("generator", "write") + .Register("model", "write") + .Register("demo"); } } } \ No newline at end of file diff --git a/Core/Exceptions/AmbiguousConfigurationException.cs b/Core/Exceptions/AmbiguousConfigurationException.cs new file mode 100644 index 00000000..f56397d0 --- /dev/null +++ b/Core/Exceptions/AmbiguousConfigurationException.cs @@ -0,0 +1,11 @@ +using System; + +namespace KY.Generator.Exceptions +{ + public class AmbiguousConfigurationException : Exception + { + public AmbiguousConfigurationException(Type configuration, string name, string group) + : base($"Configuration '{configuration.Name}' is already used by {name} ({group}). Each configuration can only be used by one command. Create a new configuration class and derive from {configuration.Name}") + { } + } +} \ No newline at end of file diff --git a/Core/Exceptions/CommandAlreadyRegisteredException.cs b/Core/Exceptions/CommandAlreadyRegisteredException.cs new file mode 100644 index 00000000..b5c7836b --- /dev/null +++ b/Core/Exceptions/CommandAlreadyRegisteredException.cs @@ -0,0 +1,11 @@ +using System; + +namespace KY.Generator.Exceptions +{ + public class CommandAlreadyRegisteredException : Exception + { + public CommandAlreadyRegisteredException(string name, string group) + : base($"{name} ({group}) is already registered. Please use a prefix like my-{name}") + { } + } +} \ No newline at end of file diff --git a/Core/Exceptions/CommandWithoutEnvironmentException.cs b/Core/Exceptions/CommandWithoutEnvironmentException.cs new file mode 100644 index 00000000..ea567ab0 --- /dev/null +++ b/Core/Exceptions/CommandWithoutEnvironmentException.cs @@ -0,0 +1,12 @@ +using System; +using KY.Generator.Configuration; + +namespace KY.Generator.Exceptions +{ + public class CommandWithoutEnvironmentException : Exception + { + public CommandWithoutEnvironmentException(Type type) + : base($"Command '{type.Name}' has no environment set. Ensure you set the 'Environment' property in constructor or derive from {nameof(ConfigurationBase)}") + { } + } +} \ No newline at end of file diff --git a/Core/Exceptions/UnknownCommandException.cs b/Core/Exceptions/UnknownCommandException.cs new file mode 100644 index 00000000..ab70d0bc --- /dev/null +++ b/Core/Exceptions/UnknownCommandException.cs @@ -0,0 +1,11 @@ +using System; + +namespace KY.Generator.Exceptions +{ + public class UnknownCommandException : Exception + { + public UnknownCommandException(string command) + : base($"Unknown command '{command}'. Ensure the module is loaded") + { } + } +} \ No newline at end of file diff --git a/Core/Extensions/ConfigurationListExtension.cs b/Core/Extensions/ConfigurationListExtension.cs new file mode 100644 index 00000000..3d2e60e1 --- /dev/null +++ b/Core/Extensions/ConfigurationListExtension.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using KY.Generator.Configuration; +using KY.Generator.Configurations; + +namespace KY.Generator.Extensions +{ + public static class ConfigurationListExtension + { + public static IEnumerable Flatten(this IEnumerable configurations) + { + foreach (IConfiguration configuration in configurations) + { + yield return configuration; + if (configuration is ExecuteConfiguration executeConfiguration) + { + foreach (IConfiguration child in executeConfiguration.Execute.Flatten()) + { + yield return child; + } + } + } + } + } +} \ No newline at end of file diff --git a/Core/Extensions/FileTemplateListExtension.cs b/Core/Extensions/FileTemplateListExtension.cs new file mode 100644 index 00000000..eb2e1097 --- /dev/null +++ b/Core/Extensions/FileTemplateListExtension.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using KY.Generator.Configuration; +using KY.Generator.Templates; + +namespace KY.Generator.Extensions +{ + public static class FileTemplateListExtension + { + public static void Write(this List files, IConfigurationWithLanguage configuration) + { + files.ForEach(file => configuration.Language.Write(file, configuration.Output)); + } + } +} \ No newline at end of file diff --git a/Core/Generator.cs b/Core/Generator.cs index 1a63a692..0e8455b6 100644 --- a/Core/Generator.cs +++ b/Core/Generator.cs @@ -7,11 +7,9 @@ using KY.Core.Module; using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Mappings; using KY.Generator.Output; using KY.Generator.Syntax; -using KY.Generator.Transfer.Writers; namespace KY.Generator { @@ -38,13 +36,10 @@ public Generator(params string[] parameters) this.resolver = new DependencyResolver(); this.resolver.Bind().ToSingleton(); this.resolver.Bind().ToSelf(); - this.resolver.Bind().ToSelf(); - this.resolver.Bind().ToSingleton(); + this.resolver.Bind().ToSingleton(); this.resolver.Bind().ToSelf(); this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); this.resolver.Bind().ToSelf(); - this.resolver.Bind().ToSelf(); StaticResolver.Resolver = this.resolver; ModuleFinder moduleFinder = this.resolver.Get(); @@ -79,11 +74,11 @@ public Generator SetOutput(string path) return this.SetOutput(new FileOutput(path)); } - public Generator RegisterCommand(string name, string group = CommandRegister.DefaultGroup) - where TCommand : IGeneratorCommand + public Generator RegisterCommand(string name, string group = CommandRegistry.DefaultGroup) + where TCommand : ICommand where TConfiguration : IConfiguration { - this.resolver.Get().Register(name, group); + this.resolver.Get().Register(name, group); return this; } @@ -98,7 +93,28 @@ public IGeneratorAfterRunSyntax Run() try { IConfiguration configuration = this.resolver.Get().Read(this.parameters); - this.success = this.resolver.Get().Run(configuration, this.output); + if (configuration == null) + { + this.success = false; + } + else + { + configuration.Output = this.output; + ICommand command = this.resolver.Get().CreateCommand(configuration); + if (command is ICommandLineCommand commandLineCommand) + { + this.success = commandLineCommand.Execute(configuration); + if (this.success) + { + configuration.Output?.Execute(); + } + } + else + { + Logger.Error($"Can not execute command '{command.GetType().Name.TrimEnd("Command")}'. Command can only be used in configuration file."); + this.success = false; + } + } } catch (Exception exception) { @@ -107,12 +123,12 @@ public IGeneratorAfterRunSyntax Run() } finally { + if (!this.success && Logger.ErrorTargets.Contains(Logger.MsBuildOutput)) + { + Logger.Error($"See the full log in: {Logger.File.Path}"); + } Logger.Trace("==============================="); } - if (!this.success && Logger.ErrorTargets.Contains(Logger.MsBuildOutput)) - { - Logger.Error($"See the full log in: {Logger.File.Path}"); - } return this; } diff --git a/Core/Helpers/ConfigurationRunner.cs b/Core/Helpers/ConfigurationRunner.cs index c76e603b..33863815 100644 --- a/Core/Helpers/ConfigurationRunner.cs +++ b/Core/Helpers/ConfigurationRunner.cs @@ -2,63 +2,64 @@ using System.Collections.Generic; using System.Linq; using KY.Core; -using KY.Core.Dependency; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Output; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; -using KY.Generator.Transfer.Writers; namespace KY.Generator { public class ConfigurationRunner { - private readonly IDependencyResolver resolver; + private readonly CommandRegistry commands; - public ConfigurationRunner(IDependencyResolver resolver) + public ConfigurationRunner(CommandRegistry commands) { - this.resolver = resolver; + this.commands = commands; } - public bool Run(List configurations, IOutput output, bool isBeforeBuild = false) + public bool Run(IEnumerable allConfigurations, bool isBeforeBuild = false) { - ConfigurationMapping mapping = this.resolver.Get(); - Logger.Trace($"Start generating {configurations.SelectMany(x => x.Configurations).Count(x => x.BeforeBuild == isBeforeBuild)} configurations"); - bool success = true; - foreach (ConfigurationSet set in configurations) + List configurations = allConfigurations.Where(x => x.BeforeBuild == isBeforeBuild).ToList(); + Logger.Trace($"Start generating {configurations.Count} configurations"); + IConfiguration missingLanguage = configurations.OfType().FirstOrDefault(x => x.Language == null); + if (missingLanguage != null) { - List configurationsToRun = set.Configurations.Where(x => x.BeforeBuild == isBeforeBuild).ToList(); - ConfigurationBase missingLanguage = configurationsToRun.FirstOrDefault(x => x.Language == null && x.RequireLanguage); - if (missingLanguage != null) - { - Logger.Error($"Configuration '{missingLanguage.GetType().Name}' without language found. Generation failed!"); - success = false; - continue; - } - try + Logger.Error($"Configuration '{missingLanguage.GetType().Name}' without language found. Generation failed!"); + return false; + } + try + { + List transferObjects = new List(); + foreach (IConfiguration configuration in configurations) { - List transferObjects = new List(); - foreach (ConfigurationBase configuration in configurationsToRun) + bool success; + ICommand command = this.commands.CreateCommand(configuration); + if (command is IConfigurationCommand configurationCommand) { - switch (mapping.Resolve(configuration)) - { - case ITransferReader reader: - reader.Read(configuration, transferObjects); - break; - case ITransferWriter writer: - writer.Write(configuration, transferObjects, output); - break; - } + success = configurationCommand.Execute(configuration, transferObjects); + } + else if (command is ICommandLineCommand commandLineCommand) + { + success = commandLineCommand.Execute(configuration); + } + else + { + Logger.Trace($"{command.GetType().Name} can not be executed. Implement at least {nameof(IConfigurationCommand)} or {nameof(ICommandLineCommand)}"); + success = false; + } + if (!success) + { + return false; } } - catch (Exception exception) - { - Logger.Error(exception); - success = false; - } + configurations.Where(x => x.Output != null).Select(x => x.Output).Unique().ForEach(x => x.Execute()); + return true; + } + catch (Exception exception) + { + Logger.Error(exception); + return false; } - return success; } } } \ No newline at end of file diff --git a/Core/Helpers/Formatter.cs b/Core/Helpers/Formatter.cs index ab58a916..6c980e70 100644 --- a/Core/Helpers/Formatter.cs +++ b/Core/Helpers/Formatter.cs @@ -1,7 +1,6 @@ using System; using KY.Core; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Extensions; using KY.Generator.Languages; @@ -15,7 +14,11 @@ public static string FormatFile(string name, IConfiguration configuration) { return name; } - return configuration.Language is BaseLanguage baseLanguage ? baseLanguage.FormatFileName(name, false) : Format(name, GetFormatting(configuration).FileCase); + if (configuration is IConfigurationWithLanguage configurationWithLanguage && configurationWithLanguage.Language is BaseLanguage baseLanguage) + { + return baseLanguage.FormatFileName(name, false); + } + return Format(name, GetFormatting(configuration).FileCase); } public static string FormatClass(string name, IConfiguration configuration) @@ -109,7 +112,7 @@ public static string Format(string name, string casing) private static ConfigurationFormatting GetFormatting(IConfiguration configuration) { ConfigurationFormatting formatting = configuration.Formatting; - if (configuration.Language is IFormattableLanguage formattableLanguage) + if (configuration is IConfigurationWithLanguage configurationWithLanguage && configurationWithLanguage.Language is IFormattableLanguage formattableLanguage) { if (formatting == null) { diff --git a/Core/Helpers/GeneratorTypeLoader.cs b/Core/Helpers/GeneratorTypeLoader.cs index 62b81e5e..bdb9c6d1 100644 --- a/Core/Helpers/GeneratorTypeLoader.cs +++ b/Core/Helpers/GeneratorTypeLoader.cs @@ -4,13 +4,12 @@ using KY.Core; using KY.Core.Nuget; using KY.Generator.Configuration; -using KY.Generator.Configurations; namespace KY.Generator { public static class GeneratorTypeLoader { - public static Type Get(ConfigurationBase configuration, string assemblyName, string nameSpace, string typeName, params SearchLocation[] locations) + public static Type Get(IConfiguration configuration, string assemblyName, string nameSpace, string typeName, params SearchLocation[] locations) { List list = locations.ToList(); list.Add(new SearchLocation(configuration.Environment.ConfigurationFilePath)); @@ -19,4 +18,4 @@ public static Type Get(ConfigurationBase configuration, string assemblyName, str return NugetPackageTypeLoader.Get(assemblyName, nameSpace, typeName, defaultVersion, list.ToArray()); } } -} +} \ No newline at end of file diff --git a/Core/Helpers/PathResolver.cs b/Core/Helpers/PathResolver.cs index ce199264..b30b2035 100644 --- a/Core/Helpers/PathResolver.cs +++ b/Core/Helpers/PathResolver.cs @@ -1,13 +1,12 @@ using System; using KY.Core.DataAccess; using KY.Generator.Configuration; -using KY.Generator.Configurations; namespace KY.Generator { public static class PathResolver { - public static string Resolve(string relativePath, ConfigurationBase configuration) + public static string Resolve(string relativePath, IConfiguration configuration) { string path = relativePath; if (FileSystem.FileExists(path)) diff --git a/Core/KY.Generator.Core.csproj b/Core/KY.Generator.Core.csproj index bcc3e4cb..e8601388 100644 --- a/Core/KY.Generator.Core.csproj +++ b/Core/KY.Generator.Core.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Core/Languages/BaseLanguage.cs b/Core/Languages/BaseLanguage.cs index 62694d94..c81b72d3 100644 --- a/Core/Languages/BaseLanguage.cs +++ b/Core/Languages/BaseLanguage.cs @@ -154,6 +154,7 @@ private void WriteChained(ChainedCodeFragment fragment, IOutputCache output) public virtual void Write(FileTemplate fileTemplate, IOutput output) { + output.AssertIsNotNull(nameof(output)); if (string.IsNullOrEmpty(fileTemplate.Name)) { Logger.Trace("Empty file skipped"); diff --git a/Core/Mappings/TypeMapping.cs b/Core/Mappings/TypeMapping.cs index 9af17481..f87a739b 100644 --- a/Core/Mappings/TypeMapping.cs +++ b/Core/Mappings/TypeMapping.cs @@ -30,7 +30,7 @@ public TypeMappingEntry Get(IMappableLanguage fromLanguage, string fromType, IMa } return mapping; } - + public TypeMappingEntry TryGet(IMappableLanguage fromLanguage, string fromType, IMappableLanguage toLanguage) { fromLanguage.AssertIsNotNull(nameof(fromLanguage)); @@ -38,7 +38,7 @@ public TypeMappingEntry TryGet(IMappableLanguage fromLanguage, string fromType, toLanguage.AssertIsNotNull(nameof(toLanguage)); return this.typeMapping.FirstOrDefault(x => x.FromLanguage.Key == fromLanguage.Key && x.FromType == fromType && x.ToLanguage.Key == toLanguage.Key); } - + public TypeMappingEntry TryGet(IMappableLanguage fromLanguage, Type fromType, IMappableLanguage toLanguage) { if (fromType.IsGenericType) @@ -54,7 +54,7 @@ public void Get(IMappableLanguage fromLanguage, IMappableLanguage toLanguage, Ty { if (type == null) { - throw new ArgumentNullException(nameof(type)); + return; } string typeName = string.IsNullOrEmpty(type.Namespace) ? type.Name : string.Join(".", type.Namespace, type.Name); TypeMappingEntry mapping = this.TryGet(fromLanguage, typeName, toLanguage); diff --git a/Core/Templates/Extensions/ClassTemplateExtension.cs b/Core/Templates/Extensions/ClassTemplateExtension.cs index e0d49861..5e498f6f 100644 --- a/Core/Templates/Extensions/ClassTemplateExtension.cs +++ b/Core/Templates/Extensions/ClassTemplateExtension.cs @@ -1,8 +1,5 @@ -using System.Collections.Generic; -using System.Linq; +using System.Linq; using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Languages; namespace KY.Generator.Templates.Extensions { diff --git a/Core/Templates/Extensions/FieldTemplateExtension.cs b/Core/Templates/Extensions/FieldTemplateExtension.cs index dc030647..ec855e4d 100644 --- a/Core/Templates/Extensions/FieldTemplateExtension.cs +++ b/Core/Templates/Extensions/FieldTemplateExtension.cs @@ -1,5 +1,4 @@ using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Languages; using KY.Generator.Models; diff --git a/Core/Templates/Extensions/MethodTemplateExtension.cs b/Core/Templates/Extensions/MethodTemplateExtension.cs index 33f7c777..0ed01db7 100644 --- a/Core/Templates/Extensions/MethodTemplateExtension.cs +++ b/Core/Templates/Extensions/MethodTemplateExtension.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Languages; using KY.Generator.Models; diff --git a/Core/Templates/Extensions/ParameterTemplateExtension.cs b/Core/Templates/Extensions/ParameterTemplateExtension.cs index 5fc7392f..9d8b4ee0 100644 --- a/Core/Templates/Extensions/ParameterTemplateExtension.cs +++ b/Core/Templates/Extensions/ParameterTemplateExtension.cs @@ -1,5 +1,4 @@ using KY.Generator.Configuration; -using KY.Generator.Configurations; namespace KY.Generator.Templates.Extensions { diff --git a/Core/Templates/Extensions/PropertyTemplateExtension.cs b/Core/Templates/Extensions/PropertyTemplateExtension.cs index 43973c60..ad0ef2ce 100644 --- a/Core/Templates/Extensions/PropertyTemplateExtension.cs +++ b/Core/Templates/Extensions/PropertyTemplateExtension.cs @@ -1,6 +1,4 @@ using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Languages; using KY.Generator.Models; namespace KY.Generator.Templates.Extensions diff --git a/Core/Transfer/Readers/ITransferReader.cs b/Core/Transfer/Readers/ITransferReader.cs deleted file mode 100644 index a170939d..00000000 --- a/Core/Transfer/Readers/ITransferReader.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using KY.Generator.Configurations; - -namespace KY.Generator.Transfer.Readers -{ - public interface ITransferReader - { - void Read(ConfigurationBase configurationBase, List transferObjects); - } -} \ No newline at end of file diff --git a/Core/Transfer/Writers/ITransferWriter.cs b/Core/Transfer/Writers/ITransferWriter.cs deleted file mode 100644 index 91c7a114..00000000 --- a/Core/Transfer/Writers/ITransferWriter.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using KY.Generator.Configurations; -using KY.Generator.Output; - -namespace KY.Generator.Transfer.Writers -{ - public interface ITransferWriter - { - void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output); - } -} \ No newline at end of file diff --git a/Core/Transfer/Writers/ModelWriter.cs b/Core/Transfer/Writers/ModelWriter.cs index ef07c02f..0410275b 100644 --- a/Core/Transfer/Writers/ModelWriter.cs +++ b/Core/Transfer/Writers/ModelWriter.cs @@ -2,34 +2,22 @@ using System.Collections.Generic; using System.Linq; using KY.Core; -using KY.Generator.Configurations; -using KY.Generator.Languages; +using KY.Generator.Configuration; using KY.Generator.Mappings; -using KY.Generator.Output; using KY.Generator.Templates; using KY.Generator.Templates.Extensions; using KY.Generator.Transfer.Extensions; namespace KY.Generator.Transfer.Writers { - public class ModelWriter : TransferWriter, ITransferWriter + public class ModelWriter : TransferWriter { public ModelWriter(ITypeMapping typeMapping) : base(typeMapping) { } - public virtual void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) - { - IModelConfiguration configuration = (IModelConfiguration)configurationBase; - this.Write(configuration, transferObjects).ForEach(file => configuration.Language.Write(file, output)); - } - public virtual List Write(IModelConfiguration configuration, IEnumerable transferObjects) { - if (configuration.Language == null) - { - throw new InvalidOperationException("Can not write model without language"); - } List files = new List(); List models = transferObjects.OfType().ToList(); if (!string.IsNullOrEmpty(configuration.Name)) @@ -51,10 +39,7 @@ protected virtual void WriteModel(IModelConfiguration configuration, ModelTransf { return; } - if (model.Language is IMappableLanguage modelLanguage && configuration.Language is IMappableLanguage configurationLanguage) - { - this.MapType(modelLanguage, configurationLanguage, model); - } + this.MapType(model.Language, configuration, model); if (model.FromSystem) { return; @@ -90,13 +75,7 @@ protected virtual EnumTemplate WriteEnum(IModelConfiguration configuration, Mode protected virtual ClassTemplate WriteClass(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List files) { - IMappableLanguage modelLanguage = model.Language as IMappableLanguage; - IMappableLanguage configurationLanguage = configuration.Language as IMappableLanguage; - - if (model.BasedOn != null && modelLanguage != null && configurationLanguage != null) - { - this.MapType(modelLanguage, configurationLanguage, model.BasedOn); - } + this.MapType(model.Language, configuration, model.BasedOn); ClassTemplate classTemplate = files.AddFile(configuration.RelativePath, configuration.AddHeader) .AddNamespace(nameSpace) @@ -117,10 +96,7 @@ protected virtual ClassTemplate WriteClass(IModelConfiguration configuration, Mo } foreach (TypeTransferObject interFace in model.Interfaces) { - if (modelLanguage != null && configurationLanguage != null) - { - this.MapType(modelLanguage, configurationLanguage, interFace); - } + this.MapType(model.Language, configuration, interFace); classTemplate.BasedOn.Add(new BaseTypeTemplate(classTemplate, Code.Interface(interFace.Name, interFace.Namespace))); this.AddUsing(interFace, classTemplate, configuration); } diff --git a/Core/Transfer/Writers/TransferWriter.cs b/Core/Transfer/Writers/TransferWriter.cs index f20f6c95..aeeb8e58 100644 --- a/Core/Transfer/Writers/TransferWriter.cs +++ b/Core/Transfer/Writers/TransferWriter.cs @@ -1,7 +1,6 @@ using System.Linq; using KY.Core; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Languages; using KY.Generator.Mappings; using KY.Generator.Templates; @@ -49,28 +48,30 @@ protected virtual void AddProperties(ModelTransferObject model, ClassTemplate cl } } + protected virtual void MapType(ILanguage language, IConfiguration configuration, TypeTransferObject type) + { + if (language is IMappableLanguage fromLanguage && configuration is IConfigurationWithLanguage configurationWithLanguage && configurationWithLanguage.Language is IMappableLanguage toLanguage) + { + this.MapType(fromLanguage, toLanguage, type); + } + } + protected virtual void MapType(IMappableLanguage fromLanguage, IMappableLanguage toLanguage, TypeTransferObject type) { this.TypeMapping.Get(fromLanguage, toLanguage, type); - type.Generics.ForEach(x => this.MapType(fromLanguage, toLanguage, x.Type)); + type?.Generics.ForEach(x => this.MapType(fromLanguage, toLanguage, x.Type)); } protected virtual FieldTemplate AddField(ModelTransferObject model, string name, TypeTransferObject type, ClassTemplate classTemplate, IConfiguration configuration) { - if (model.Language is IMappableLanguage modelLanguage && configuration.Language is IMappableLanguage configurationLanguage) - { - this.MapType(modelLanguage, configurationLanguage, type); - } + this.MapType(model.Language, configuration, type); this.AddUsing(type, classTemplate, configuration); return classTemplate.AddField(name, type.ToTemplate()).Public().FormatName(configuration); } protected virtual PropertyTemplate AddProperty(ModelTransferObject model, string name, TypeTransferObject type, ClassTemplate classTemplate, IConfiguration configuration, bool canRead = true, bool canWrite = true) { - if (model.Language is IMappableLanguage modelLanguage && configuration.Language is IMappableLanguage configurationLanguage) - { - this.MapType(modelLanguage, configurationLanguage, type); - } + this.MapType(model.Language, configuration, type); PropertyTemplate propertyTemplate = classTemplate.AddProperty(name, type.ToTemplate()).FormatName(configuration); propertyTemplate.HasGetter = canRead; propertyTemplate.HasSetter = canWrite; @@ -84,12 +85,18 @@ protected virtual void AddUsing(TypeTransferObject type, ClassTemplate classTemp { return; } - if ((!type.FromSystem || type.FromSystem && configuration.Language.ImportFromSystem) && !string.IsNullOrEmpty(type.Namespace) && classTemplate.Namespace.Name != type.Namespace) + if ((!type.FromSystem || type.FromSystem && this.ImportFromSystem(configuration)) && !string.IsNullOrEmpty(type.Namespace) && classTemplate.Namespace.Name != type.Namespace) { string fileName = Formatter.FormatFile(type.Name, configuration); classTemplate.AddUsing(type.Namespace, type.Name, $"{relativeModelPath.Replace("\\", "/").TrimEnd('/')}/{fileName}"); } type.Generics.Where(x => x.Alias == null).ForEach(generic => this.AddUsing(generic.Type, classTemplate, configuration, relativeModelPath)); } + + private bool ImportFromSystem(IConfiguration configuration) + { + IConfigurationWithLanguage configurationWithLanguage = configuration as IConfigurationWithLanguage; + return configurationWithLanguage == null || configurationWithLanguage.Language.ImportFromSystem; + } } } \ No newline at end of file diff --git a/Core/Writers/MultilineCodeFragmentWriter.cs b/Core/Writers/MultilineCodeFragmentWriter.cs index fc75aa04..c9dd774f 100644 --- a/Core/Writers/MultilineCodeFragmentWriter.cs +++ b/Core/Writers/MultilineCodeFragmentWriter.cs @@ -1,7 +1,6 @@ using KY.Generator.Languages; using KY.Generator.Output; using KY.Generator.Templates; -using KY.Generator.Templates.Extensions; namespace KY.Generator.Writers { @@ -22,24 +21,5 @@ public virtual void Write(ICodeFragment fragment, IOutputCache output) output.Add(codeFragment); } } - - //public virtual void Write(IMetaElementList elements, ICodeFragment codeFragment) - //{ - // MultilineCodeFragment fragment = (MultilineCodeFragment)codeFragment; - // foreach (ICodeFragment innerFragment in fragment.Fragments) - // { - // elements.Add(innerFragment, this.Language); - // } - //} - - //public virtual void Write(IMetaFragmentList fragments, ICodeFragment codeFragment) - //{ - // MultilineCodeFragment fragment = (MultilineCodeFragment)codeFragment; - // foreach (ICodeFragment innerFragment in fragment.Fragments) - // { - // fragments.Add(innerFragment, this.Language); - // fragments.AddNewLine(); - // } - //} } } \ No newline at end of file diff --git a/Csharp.Tests/KY.Generator.Csharp.Tests.csproj b/Csharp.Tests/KY.Generator.Csharp.Tests.csproj index c65eceec..10e95177 100644 --- a/Csharp.Tests/KY.Generator.Csharp.Tests.csproj +++ b/Csharp.Tests/KY.Generator.Csharp.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Csharp.Tests/TemplateWriterTests.cs b/Csharp.Tests/TemplateWriterTests.cs index 3c1cf078..914b74fb 100644 --- a/Csharp.Tests/TemplateWriterTests.cs +++ b/Csharp.Tests/TemplateWriterTests.cs @@ -16,10 +16,11 @@ namespace KY.Generator.Csharp.Tests { [TestClass] - public class TemplateWriterTests : Codeable + public class TemplateWriterTests : MsTestBase { private IDependencyResolver resolver; private IOutputCache output; + private static readonly Code Code = default; [TestInitialize] public void Initialize() diff --git a/Csharp/KY.Generator.CSharp.csproj b/Csharp/KY.Generator.CSharp.csproj index f6e790e6..39d6b4be 100644 --- a/Csharp/KY.Generator.CSharp.csproj +++ b/Csharp/KY.Generator.CSharp.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/EntityFramework/Writers/EntityFrameworkWriter.cs b/EntityFramework/Commands/WriteEntityFrameworkCommand.cs similarity index 72% rename from EntityFramework/Writers/EntityFrameworkWriter.cs rename to EntityFramework/Commands/WriteEntityFrameworkCommand.cs index 69c6e407..6b3354db 100644 --- a/EntityFramework/Writers/EntityFrameworkWriter.cs +++ b/EntityFramework/Commands/WriteEntityFrameworkCommand.cs @@ -2,27 +2,27 @@ using System.Collections.Generic; using KY.Core; using KY.Core.Dependency; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Csharp.Languages; using KY.Generator.EntityFramework.Configurations; -using KY.Generator.Output; +using KY.Generator.EntityFramework.Writers; +using KY.Generator.Extensions; using KY.Generator.Templates; using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; -namespace KY.Generator.EntityFramework.Writers +namespace KY.Generator.EntityFramework.Commands { - public class EntityFrameworkWriter : ITransferWriter + public class WriteEntityFrameworkCommand : IConfigurationCommand { private readonly IDependencyResolver resolver; - public EntityFrameworkWriter(IDependencyResolver resolver) + public WriteEntityFrameworkCommand(IDependencyResolver resolver) { this.resolver = resolver; } - public virtual void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) + public bool Execute(IConfiguration configurationBase, List transferObjects) { EntityFrameworkWriteConfiguration configuration = (EntityFrameworkWriteConfiguration)configurationBase; if (!configuration.Language.IsCsharp()) @@ -36,7 +36,8 @@ public virtual void Write(ConfigurationBase configurationBase, List().Write(configuration, transferObjects, files); } this.resolver.Create().Write(configuration, transferObjects, files); - files.ForEach(file => configuration.Language.Write(file, output)); + files.Write(configuration); + return true; } } } \ No newline at end of file diff --git a/EntityFramework/Configurations/EntityFrameworkWriteConfiguration.cs b/EntityFramework/Configurations/EntityFrameworkWriteConfiguration.cs index 82c2d9f8..14b824fb 100644 --- a/EntityFramework/Configurations/EntityFrameworkWriteConfiguration.cs +++ b/EntityFramework/Configurations/EntityFrameworkWriteConfiguration.cs @@ -1,10 +1,10 @@ using System.Collections.Generic; -using KY.Generator.Configurations; +using KY.Generator.Configuration; using KY.Generator.Csharp.Languages; namespace KY.Generator.EntityFramework.Configurations { - public class EntityFrameworkWriteConfiguration : ConfigurationBase, IFormattableConfiguration + public class EntityFrameworkWriteConfiguration : ConfigurationWithLanguageBase, IFormattableConfiguration { public string Namespace { get; set; } public string RelativePath { get; set; } diff --git a/EntityFramework/EntityFrameworkModule.cs b/EntityFramework/EntityFrameworkModule.cs index 038ef2e7..f5eeec23 100644 --- a/EntityFramework/EntityFrameworkModule.cs +++ b/EntityFramework/EntityFrameworkModule.cs @@ -1,8 +1,8 @@ using KY.Core.Dependency; using KY.Core.Module; -using KY.Generator.Configuration; +using KY.Generator.Command; +using KY.Generator.EntityFramework.Commands; using KY.Generator.EntityFramework.Configurations; -using KY.Generator.EntityFramework.Writers; namespace KY.Generator.EntityFramework { @@ -11,9 +11,9 @@ public class EntityFrameworkModule : ModuleBase public EntityFrameworkModule(IDependencyResolver dependencyResolver) : base(dependencyResolver) { - this.DependencyResolver.Get() - .Map("ef") - .Map("ef-core"); + this.DependencyResolver.Get() + .Register("ef", "write") + .Register("ef-core", "write"); } } } \ No newline at end of file diff --git a/EntityFramework/KY.Generator.EntityFramework.csproj b/EntityFramework/KY.Generator.EntityFramework.csproj index 7d66a336..094e160f 100644 --- a/EntityFramework/KY.Generator.EntityFramework.csproj +++ b/EntityFramework/KY.Generator.EntityFramework.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/EntityFramework/Writers/EntityFrameworkDataContextWriter.cs b/EntityFramework/Writers/EntityFrameworkDataContextWriter.cs index f9e011f4..5ce5433f 100644 --- a/EntityFramework/Writers/EntityFrameworkDataContextWriter.cs +++ b/EntityFramework/Writers/EntityFrameworkDataContextWriter.cs @@ -8,7 +8,7 @@ using KY.Generator.Templates.Extensions; using KY.Generator.Transfer; using KY.Generator.Transfer.Extensions; -using KY.Generator.Tsql.Transfers; +using KY.Generator.Tsql.TransferObjects; namespace KY.Generator.EntityFramework.Writers { diff --git a/Json.Tests/ConfigurationTests.cs b/Json.Tests/ConfigurationTests.cs index 8ffa74b8..2042a502 100644 --- a/Json.Tests/ConfigurationTests.cs +++ b/Json.Tests/ConfigurationTests.cs @@ -1,45 +1,35 @@ -using System.Collections.Generic; using KY.Core; -using KY.Core.Dependency; -using KY.Generator.Configuration; using KY.Generator.Configurations; +using KY.Generator.Core.Tests; using KY.Generator.Csharp; using KY.Generator.Csharp.Languages; using KY.Generator.Json.Configurations; using KY.Generator.Json.Tests.Properties; -using KY.Generator.Mappings; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.Json.Tests { [TestClass] - public class ConfigurationTests + public class ConfigurationTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().To(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Get(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); + this.runner = new TestConfigurationRunner() + .Initialize() + .Initialize() + .Initialize(); } [TestMethod] public void ReadSimpleConfiguration() { - List sets = this.reader.Parse(Resources.simple_generator); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(2, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Resources/simple.json", sets[0].Configurations[0].CastTo().Source); - JsonWriteConfiguration writeConfiguration = sets[0].Configurations[1].CastTo(); + ExecuteConfiguration configuration = this.runner.Parse(Resources.simple_generator); + Assert.AreEqual(2, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Resources/simple.json", configuration.Execute[0].CastTo().Source); + JsonWriteConfiguration writeConfiguration = configuration.Execute[1].CastTo(); Assert.AreEqual(CsharpLanguage.Instance, writeConfiguration.Language); Assert.AreEqual("SimpleWithoutReader", writeConfiguration.Object.Name); Assert.AreEqual("KY.Generator.Examples.Json", writeConfiguration.Object.Namespace); @@ -49,11 +39,10 @@ public void ReadSimpleConfiguration() [TestMethod] public void ReadSimpleWithReaderConfiguration() { - List sets = this.reader.Parse(Resources.simple_with_reader_generator); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(2, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Resources/simple.json", sets[0].Configurations[0].CastTo().Source); - JsonWriteConfiguration writeConfiguration = sets[0].Configurations[1].CastTo(); + ExecuteConfiguration configuration = this.runner.Parse(Resources.simple_with_reader_generator); + Assert.AreEqual(2, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Resources/simple.json", configuration.Execute[0].CastTo().Source); + JsonWriteConfiguration writeConfiguration = configuration.Execute[1].CastTo(); Assert.AreEqual(CsharpLanguage.Instance, writeConfiguration.Language); Assert.AreEqual("SimpleWithReader", writeConfiguration.Object.Name); Assert.AreEqual("KY.Generator.Examples.Json", writeConfiguration.Object.Namespace); @@ -65,11 +54,10 @@ public void ReadSimpleWithReaderConfiguration() [TestMethod] public void ReadSimpleWithSeparateReaderConfiguration() { - List sets = this.reader.Parse(Resources.simple_with_separate_reader_generator); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(2, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Resources/simple.json", sets[0].Configurations[0].CastTo().Source); - JsonWriteConfiguration writeConfiguration = sets[0].Configurations[1].CastTo(); + ExecuteConfiguration configuration = this.runner.Parse(Resources.simple_with_separate_reader_generator); + Assert.AreEqual(2, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Resources/simple.json", configuration.Execute[0].CastTo().Source); + JsonWriteConfiguration writeConfiguration = configuration.Execute[1].CastTo(); Assert.AreEqual(CsharpLanguage.Instance, writeConfiguration.Language); Assert.AreEqual("Simple", writeConfiguration.Object.Name); Assert.AreEqual("KY.Generator.Examples.Json", writeConfiguration.Object.Namespace); @@ -81,11 +69,10 @@ public void ReadSimpleWithSeparateReaderConfiguration() [TestMethod] public void ReadComplexConfiguration() { - List sets = this.reader.Parse(Resources.complex_generator); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(2, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Resources/complex.json", sets[0].Configurations[0].CastTo().Source); - ModelWriteConfiguration writeConfiguration = sets[0].Configurations[1].CastTo(); + ExecuteConfiguration configuration = this.runner.Parse(Resources.complex_generator); + Assert.AreEqual(2, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Resources/complex.json", configuration.Execute[0].CastTo().Source); + ModelWriteConfiguration writeConfiguration = configuration.Execute[1].CastTo(); Assert.AreEqual(CsharpLanguage.Instance, writeConfiguration.Language); Assert.AreEqual("Complex", writeConfiguration.Name); Assert.AreEqual("KY.Generator.Examples.Json", writeConfiguration.Namespace); diff --git a/Json.Tests/FullStageTests.cs b/Json.Tests/FullStageTests.cs index 9f123b92..9dcf006e 100644 --- a/Json.Tests/FullStageTests.cs +++ b/Json.Tests/FullStageTests.cs @@ -1,97 +1,78 @@ -using System.Collections.Generic; -using KY.Core.Dependency; -using KY.Generator.Configuration; +using KY.Core; +using KY.Generator.Core.Tests; using KY.Generator.Csharp; using KY.Generator.Json.Tests.Properties; -using KY.Generator.Mappings; -using KY.Generator.Output; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.Json.Tests { [TestClass] - public class FullStageTests + public class FullStageTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; - private ConfigurationRunner runner; - private MemoryOutput output; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().ToSingleton(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); - this.runner = this.resolver.Create(); - this.output = this.resolver.Create(); + this.runner = new TestConfigurationRunner() + .Initialize() + .Initialize() + .Initialize(); } [TestMethod] public void Simple() { - Assert.AreEqual(true, this.Run(Resources.simple_generator), "Generation not successful"); - Assert.AreEqual(1, this.output.Files.Count); - Assert.AreEqual(Resources.SimpleWithoutReader_cs, this.output.Files["SimpleWithoutReader.cs"]); + Assert.AreEqual(true, this.runner.Run(Resources.simple_generator), "Generation not successful"); + Assert.AreEqual(1, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.SimpleWithoutReader_cs, this.runner.Output.Files["SimpleWithoutReader.cs"]); } [TestMethod] public void SimpleWithReader() { - Assert.AreEqual(true, this.Run(Resources.simple_with_reader_generator), "Generation not successful"); - Assert.AreEqual(1, this.output.Files.Count); - Assert.AreEqual(Resources.SimpleWithReader_cs, this.output.Files["SimpleWithReader.cs"]); + Assert.AreEqual(true, this.runner.Run(Resources.simple_with_reader_generator), "Generation not successful"); + Assert.AreEqual(1, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.SimpleWithReader_cs, this.runner.Output.Files["SimpleWithReader.cs"]); } [TestMethod] public void SimpleWithSeparateReader() { - Assert.AreEqual(true, this.Run(Resources.simple_with_separate_reader_generator), "Generation not successful"); - Assert.AreEqual(2, this.output.Files.Count); - Assert.AreEqual(Resources.Simple_cs, this.output.Files["Simple.cs"]); - Assert.AreEqual(Resources.SimpleReader_cs, this.output.Files["SimpleReader.cs"]); + Assert.AreEqual(true, this.runner.Run(Resources.simple_with_separate_reader_generator), "Generation not successful"); + Assert.AreEqual(2, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.Simple_cs, this.runner.Output.Files["Simple.cs"]); + Assert.AreEqual(Resources.SimpleReader_cs, this.runner.Output.Files["SimpleReader.cs"]); } [TestMethod] public void Complex() { - Assert.AreEqual(true, this.Run(Resources.complex_generator), "Generation not successful"); - Assert.AreEqual(3, this.output.Files.Count); - Assert.AreEqual(Resources.Complex_cs, this.output.Files["Complex.cs"]); - Assert.AreEqual(Resources.ObjectProperty_cs, this.output.Files["ObjectProperty.cs"]); - Assert.AreEqual(Resources.ObjectArrayProperty_cs, this.output.Files["ObjectArrayProperty.cs"]); + Assert.AreEqual(true, this.runner.Run(Resources.complex_generator), "Generation not successful"); + Assert.AreEqual(3, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.Complex_cs, this.runner.Output.Files["Complex.cs"]); + Assert.AreEqual(Resources.ObjectProperty_cs, this.runner.Output.Files["ObjectProperty.cs"]); + Assert.AreEqual(Resources.ObjectArrayProperty_cs, this.runner.Output.Files["ObjectArrayProperty.cs"]); } [TestMethod] public void ComplexWithReader() { - Assert.AreEqual(true, this.Run(Resources.complex_with_reader_generator), "Generation not successful"); - Assert.AreEqual(3, this.output.Files.Count); - Assert.AreEqual(Resources.ComplexWithReader_cs, this.output.Files["ComplexWithReader.cs"]); - Assert.AreEqual(Resources.ObjectProperty_cs, this.output.Files["ObjectProperty.cs"]); - Assert.AreEqual(Resources.ObjectArrayProperty_cs, this.output.Files["ObjectArrayProperty.cs"]); + Assert.AreEqual(true, this.runner.Run(Resources.complex_with_reader_generator), "Generation not successful"); + Assert.AreEqual(3, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.ComplexWithReader_cs, this.runner.Output.Files["ComplexWithReader.cs"]); + Assert.AreEqual(Resources.ObjectProperty_cs, this.runner.Output.Files["ObjectProperty.cs"]); + Assert.AreEqual(Resources.ObjectArrayProperty_cs, this.runner.Output.Files["ObjectArrayProperty.cs"]); } [TestMethod] public void FormatNames() { - Assert.AreEqual(true, this.Run(Resources.formatNames_generator), "Generation not successful"); - Assert.AreEqual(3, this.output.Files.Count); - Assert.AreEqual(Resources.FormatNames_cs, this.output.Files["FormatNames.cs"]); - Assert.AreEqual(Resources.Alllowerobject_cs, this.output.Files["Alllowerobject.cs"]); - Assert.AreEqual(Resources.Allupperobject_cs, this.output.Files["Allupperobject.cs"]); - } - - private bool Run(string configuration) - { - List configurations = this.reader.Parse(configuration); - configurations.ForEach(x => x.Configurations.ForEach(y => y.AddHeader = false)); - return this.runner.Run(configurations, this.output); + Assert.AreEqual(true, this.runner.Run(Resources.formatNames_generator), "Generation not successful"); + Assert.AreEqual(3, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.FormatNames_cs, this.runner.Output.Files["FormatNames.cs"]); + Assert.AreEqual(Resources.Alllowerobject_cs, this.runner.Output.Files["Alllowerobject.cs"]); + Assert.AreEqual(Resources.Allupperobject_cs, this.runner.Output.Files["Allupperobject.cs"]); } } -} +} \ No newline at end of file diff --git a/Json.Tests/KY.Generator.Json.Tests.csproj b/Json.Tests/KY.Generator.Json.Tests.csproj index 199b1baa..35abcbd0 100644 --- a/Json.Tests/KY.Generator.Json.Tests.csproj +++ b/Json.Tests/KY.Generator.Json.Tests.csproj @@ -29,13 +29,14 @@ - + + diff --git a/Json/Readers/JsonReader.cs b/Json/Commands/ReadJsonCommand.cs similarity index 89% rename from Json/Readers/JsonReader.cs rename to Json/Commands/ReadJsonCommand.cs index b592c4bb..ad31a19f 100644 --- a/Json/Readers/JsonReader.cs +++ b/Json/Commands/ReadJsonCommand.cs @@ -1,25 +1,28 @@ using System.Collections.Generic; using System.Linq; +using KY.Core; using KY.Core.DataAccess; -using KY.Generator.Configurations; +using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Json.Configurations; using KY.Generator.Json.Language; -using KY.Generator.Json.Transfers; +using KY.Generator.Json.TransferObjects; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -namespace KY.Generator.Json.Readers +namespace KY.Generator.Json.Commands { - internal class JsonReader : ITransferReader + internal class ReadJsonCommand : IConfigurationCommand { - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Read json..."); JsonReadConfiguration configuration = (JsonReadConfiguration)configurationBase; JObject source = JsonConvert.DeserializeObject(FileSystem.ReadAllText(PathResolver.Resolve(configuration.Source, configuration))); this.ReadModel(null, source, transferObjects); + return true; } private ModelTransferObject ReadModel(string name, JObject source, List list) diff --git a/Json/Writers/JsonWriter.cs b/Json/Commands/WriteJsonCommand.cs similarity index 71% rename from Json/Writers/JsonWriter.cs rename to Json/Commands/WriteJsonCommand.cs index 6a6737e6..6909bf2d 100644 --- a/Json/Writers/JsonWriter.cs +++ b/Json/Commands/WriteJsonCommand.cs @@ -1,27 +1,28 @@ using System.Collections.Generic; using KY.Core; using KY.Core.Dependency; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; +using KY.Generator.Extensions; using KY.Generator.Json.Configurations; -using KY.Generator.Output; +using KY.Generator.Json.Writers; using KY.Generator.Templates; using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; -namespace KY.Generator.Json.Writers +namespace KY.Generator.Json.Commands { - internal class JsonWriter : ITransferWriter + internal class WriteJsonCommand : IConfigurationCommand { private readonly IDependencyResolver resolver; - public JsonWriter(IDependencyResolver resolver) + public WriteJsonCommand(IDependencyResolver resolver) { this.resolver = resolver; } - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Write json..."); JsonWriteConfiguration configuration = (JsonWriteConfiguration)configurationBase; List files = new List(); if (configuration.Object != null) @@ -36,7 +37,8 @@ public void Write(ConfigurationBase configurationBase, List tra { Logger.Warning("Json configuration has no model and no reader property. Set at least one of them to start generation"); } - files.ForEach(file => configuration.Language.Write(file, output)); + files.Write(configuration); + return true; } } } \ No newline at end of file diff --git a/Json/Configurations/JsonReadConfiguration.cs b/Json/Configurations/JsonReadConfiguration.cs index b95e9ceb..91c3743a 100644 --- a/Json/Configurations/JsonReadConfiguration.cs +++ b/Json/Configurations/JsonReadConfiguration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Json.Configurations { - internal class JsonReadConfiguration : ReadConfigurationBase + internal class JsonReadConfiguration : ConfigurationBase { public string Source { get; set; } } diff --git a/Json/Configurations/JsonWriteConfiguration.cs b/Json/Configurations/JsonWriteConfiguration.cs index 43ee7eb9..e42dc510 100644 --- a/Json/Configurations/JsonWriteConfiguration.cs +++ b/Json/Configurations/JsonWriteConfiguration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Json.Configurations { - public class JsonWriteConfiguration : ConfigurationBase, IFormattableConfiguration + public class JsonWriteConfiguration : ConfigurationWithLanguageBase, IFormattableConfiguration { public JsonWriteReaderConfiguration Reader { get; set; } public JsonWriteObjectConfiguration Object { get; set; } diff --git a/Json/JsonModule.cs b/Json/JsonModule.cs index 71dcf5f4..a01ec760 100644 --- a/Json/JsonModule.cs +++ b/Json/JsonModule.cs @@ -1,11 +1,10 @@ using System.Runtime.CompilerServices; using KY.Core.Dependency; using KY.Core.Module; -using KY.Generator.Configuration; +using KY.Generator.Command; +using KY.Generator.Json.Commands; using KY.Generator.Json.Configurations; using KY.Generator.Json.Extensions; -using KY.Generator.Json.Readers; -using KY.Generator.Json.Writers; using KY.Generator.Mappings; [assembly: InternalsVisibleTo("KY.Generator.Json.Tests")] @@ -21,9 +20,9 @@ public JsonModule(IDependencyResolver dependencyResolver) public override void Initialize() { this.DependencyResolver.Get().Initialize(); - this.DependencyResolver.Get() - .Map("json") - .Map("json"); + this.DependencyResolver.Get() + .Register("json", "read") + .Register("json", "write"); } } } \ No newline at end of file diff --git a/Json/KY.Generator.Json.csproj b/Json/KY.Generator.Json.csproj index 93e6eb0c..6a7583c3 100644 --- a/Json/KY.Generator.Json.csproj +++ b/Json/KY.Generator.Json.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Json/Transfers/JsonModelTransferObject.cs b/Json/TransferObjects/JsonModelTransferObject.cs similarity index 70% rename from Json/Transfers/JsonModelTransferObject.cs rename to Json/TransferObjects/JsonModelTransferObject.cs index 61744826..ab8dda88 100644 --- a/Json/Transfers/JsonModelTransferObject.cs +++ b/Json/TransferObjects/JsonModelTransferObject.cs @@ -1,6 +1,6 @@ using KY.Generator.Transfer; -namespace KY.Generator.Json.Transfers +namespace KY.Generator.Json.TransferObjects { public class JsonModelTransferObject : ModelTransferObject { } diff --git a/Json/Writers/ObjectWriter.cs b/Json/Writers/ObjectWriter.cs index f40b1b52..67a550c2 100644 --- a/Json/Writers/ObjectWriter.cs +++ b/Json/Writers/ObjectWriter.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; +using KY.Generator.Configuration; using KY.Generator.Configurations; using KY.Generator.Csharp.Extensions; using KY.Generator.Json.Configurations; -using KY.Generator.Json.Transfers; +using KY.Generator.Json.TransferObjects; using KY.Generator.Mappings; using KY.Generator.Templates; using KY.Generator.Templates.Extensions; diff --git a/OData.Tests/FullStageTests.cs b/OData.Tests/FullStageTests.cs index 802de4a1..bfcb75a6 100644 --- a/OData.Tests/FullStageTests.cs +++ b/OData.Tests/FullStageTests.cs @@ -1,59 +1,36 @@ -using System.Collections.Generic; -using System.Linq; using KY.Core; -using KY.Core.Dependency; using KY.Generator.Angular; -using KY.Generator.Angular.Configurations; -using KY.Generator.Configuration; -using KY.Generator.Mappings; +using KY.Generator.Core.Tests; using KY.Generator.OData.Tests.Properties; -using KY.Generator.Output; using KY.Generator.TypeScript; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.OData.Tests { [TestClass] - public class FullStageTests + public class FullStageTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; - private ConfigurationRunner runner; - private MemoryOutput output; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().ToSingleton(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); - this.runner = this.resolver.Create(); - this.output = this.resolver.Create(); + this.runner = new TestConfigurationRunner() + .Initialize() + .Initialize() + .Initialize() + .Initialize(); } [TestMethod] public void TestMethod1() { - Assert.AreEqual(true, this.Run(Resources.odata_generator), "Generation not successful"); - Assert.AreEqual(4, this.output.Files.Count); - Assert.AreEqual(Resources.address_service_ts, this.output.Files["address.service.ts"]); - Assert.AreEqual(Resources.address_ts, this.output.Files["address.ts"]); - Assert.AreEqual(Resources.user_ts, this.output.Files["user.ts"]); - Assert.AreEqual(Resources.u_se_r_service_ts, this.output.Files["u-se-r.service.ts"]); - } - - private bool Run(string configuration) - { - List sets = this.reader.Parse(configuration); - sets.ForEach(x => x.Configurations.ForEach(y => y.AddHeader = false)); - sets.SelectMany(x => x.Configurations).OfType().ForEach(x => x.Model.AddHeader = false); - return this.runner.Run(sets, this.output); + Assert.AreEqual(true, this.runner.Run(Resources.odata_generator), "Generation not successful"); + Assert.AreEqual(4, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.address_service_ts, this.runner.Output.Files["address.service.ts"]); + Assert.AreEqual(Resources.address_ts, this.runner.Output.Files["address.ts"]); + Assert.AreEqual(Resources.user_ts, this.runner.Output.Files["user.ts"]); + Assert.AreEqual(Resources.u_se_r_service_ts, this.runner.Output.Files["u-se-r.service.ts"]); } } -} +} \ No newline at end of file diff --git a/OData.Tests/KY.Generator.OData.Tests.csproj b/OData.Tests/KY.Generator.OData.Tests.csproj index 433556bf..ebe02f86 100644 --- a/OData.Tests/KY.Generator.OData.Tests.csproj +++ b/OData.Tests/KY.Generator.OData.Tests.csproj @@ -7,7 +7,7 @@ - + @@ -15,6 +15,7 @@ + diff --git a/OData/Readers/ODataReader.cs b/OData/Commands/ReadODataCommand.cs similarity index 96% rename from OData/Readers/ODataReader.cs rename to OData/Commands/ReadODataCommand.cs index e0618bce..e881d2e3 100644 --- a/OData/Readers/ODataReader.cs +++ b/OData/Commands/ReadODataCommand.cs @@ -5,23 +5,24 @@ using System.Xml; using KY.Core; using KY.Core.DataAccess; -using KY.Generator.Configurations; +using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.OData.Configurations; using KY.Generator.OData.Language; -using KY.Generator.OData.Transfers; +using KY.Generator.OData.TransferObjects; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Csdl; -namespace KY.Generator.OData.Readers +namespace KY.Generator.OData.Commands { - internal class ODataReader : ITransferReader + internal class ReadODataCommand : IConfigurationCommand { - private const string BindingParameterName = "bindingParameter"; + private const string bindingParameterName = "bindingParameter"; - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Read oData..."); ODataReadConfiguration configuration = (ODataReadConfiguration)configurationBase; if (!string.IsNullOrEmpty(configuration.File)) @@ -43,6 +44,7 @@ public void Read(ConfigurationBase configurationBase, List tran this.Parse(responseString, transferObjects); } } + return true; } private void Parse(string xml, List list) @@ -119,7 +121,7 @@ private Dictionary ReadModels(IEdmModel edmModel, } foreach (IEdmAction action in edmModel.SchemaElements.OfType()) { - IEdmType boundTo = action.FindParameter(BindingParameterName)?.Type.Definition; + IEdmType boundTo = action.FindParameter(bindingParameterName)?.Type.Definition; if (boundTo != null && modelMapping.ContainsKey(boundTo)) { EntityTransferObject entity = entityMapping[boundTo]; @@ -129,7 +131,7 @@ private Dictionary ReadModels(IEdmModel edmModel, entityAction.ReturnType = modelMapping[action.ReturnType.Definition]; } entity.Actions.Add(entityAction); - foreach (IEdmOperationParameter actionParameter in action.Parameters.Where(parameter => parameter.Name != BindingParameterName)) + foreach (IEdmOperationParameter actionParameter in action.Parameters.Where(parameter => parameter.Name != bindingParameterName)) { entityAction.Parameters.Add(new EntityActionParameterTransferObject { Name = actionParameter.Name, Type = modelMapping[actionParameter.Type.Definition] }); } diff --git a/OData/Configurations/ODataReadConfiguration.cs b/OData/Configurations/ODataReadConfiguration.cs index 70b3da7d..3a68f1d7 100644 --- a/OData/Configurations/ODataReadConfiguration.cs +++ b/OData/Configurations/ODataReadConfiguration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.OData.Configurations { - public class ODataReadConfiguration : ReadConfigurationBase + public class ODataReadConfiguration : ConfigurationBase { public string File { get; set; } public string Connection { get; set; } diff --git a/OData/KY.Generator.OData.csproj b/OData/KY.Generator.OData.csproj index 5a022942..035eaf20 100644 --- a/OData/KY.Generator.OData.csproj +++ b/OData/KY.Generator.OData.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/OData/ODataModule.cs b/OData/ODataModule.cs index 29dea03c..7a7ee561 100644 --- a/OData/ODataModule.cs +++ b/OData/ODataModule.cs @@ -1,10 +1,10 @@ using KY.Core.Dependency; using KY.Core.Module; -using KY.Generator.Configuration; +using KY.Generator.Command; using KY.Generator.Mappings; +using KY.Generator.OData.Commands; using KY.Generator.OData.Configurations; using KY.Generator.OData.Extensions; -using KY.Generator.OData.Readers; namespace KY.Generator.OData { @@ -17,7 +17,8 @@ public ODataModule(IDependencyResolver dependencyResolver) public override void Initialize() { this.DependencyResolver.Get().Initialize(); - this.DependencyResolver.Get().Map("odata-v4"); + this.DependencyResolver.Get() + .Register("odata-v4", "read"); } } } \ No newline at end of file diff --git a/OData/Transfers/ODataResultTransferObject.cs b/OData/TransferObjects/ODataResultTransferObject.cs similarity index 85% rename from OData/Transfers/ODataResultTransferObject.cs rename to OData/TransferObjects/ODataResultTransferObject.cs index ee5a8111..5f98b1e0 100644 --- a/OData/Transfers/ODataResultTransferObject.cs +++ b/OData/TransferObjects/ODataResultTransferObject.cs @@ -1,6 +1,6 @@ using KY.Generator.Transfer; -namespace KY.Generator.OData.Transfers +namespace KY.Generator.OData.TransferObjects { public class ODataResultTransferObject : ITransferObject { diff --git a/OpenApi/Readers/OpenApiReader.cs b/OpenApi/Commands/ReadOpenApiCommand.cs similarity index 74% rename from OpenApi/Readers/OpenApiReader.cs rename to OpenApi/Commands/ReadOpenApiCommand.cs index 0fc0f605..41b920a0 100644 --- a/OpenApi/Readers/OpenApiReader.cs +++ b/OpenApi/Commands/ReadOpenApiCommand.cs @@ -1,28 +1,28 @@ using System.Collections.Generic; using KY.Core; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.OpenApi.Configurations; using KY.Generator.OpenApi.DataAccess; +using KY.Generator.OpenApi.Readers; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; -namespace KY.Generator.OpenApi.Readers +namespace KY.Generator.OpenApi.Commands { - public class OpenApiReader : ITransferReader + public class ReadOpenApiCommand : IConfigurationCommand { private readonly OpenApiFileReader fileReader; private readonly OpenApiUrlReader urlReader; private readonly OpenApiDocumentReader documentReader; - public OpenApiReader(OpenApiFileReader fileReader, OpenApiUrlReader urlReader, OpenApiDocumentReader documentReader) + public ReadOpenApiCommand(OpenApiFileReader fileReader, OpenApiUrlReader urlReader, OpenApiDocumentReader documentReader) { this.fileReader = fileReader; this.urlReader = urlReader; this.documentReader = documentReader; } - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { Logger.Trace("Read OpenApi..."); OpenApiReadConfiguration configuration = (OpenApiReadConfiguration)configurationBase; @@ -35,6 +35,7 @@ public void Read(ConfigurationBase configurationBase, List tran this.urlReader.Read(configuration.File, transferObjects); } this.documentReader.Read(configuration, transferObjects); + return true; } } } \ No newline at end of file diff --git a/OpenApi/Configurations/OpenApiReadConfiguration.cs b/OpenApi/Configurations/OpenApiReadConfiguration.cs index 47744fb1..8cbf518b 100644 --- a/OpenApi/Configurations/OpenApiReadConfiguration.cs +++ b/OpenApi/Configurations/OpenApiReadConfiguration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.OpenApi.Configurations { - public class OpenApiReadConfiguration : ReadConfigurationBase + public class OpenApiReadConfiguration : ConfigurationBase { public string File { get; set; } public string Url { get; set; } diff --git a/OpenApi/DataAccess/OpenApiUrlReader.cs b/OpenApi/DataAccess/OpenApiUrlReader.cs index ebbb94e4..147273dd 100644 --- a/OpenApi/DataAccess/OpenApiUrlReader.cs +++ b/OpenApi/DataAccess/OpenApiUrlReader.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; diff --git a/OpenApi/KY.Generator.OpenApi.csproj b/OpenApi/KY.Generator.OpenApi.csproj index dd869087..d4de8ccc 100644 --- a/OpenApi/KY.Generator.OpenApi.csproj +++ b/OpenApi/KY.Generator.OpenApi.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + @@ -28,8 +28,4 @@ Download KY.Generator.CLI to use this module - - - - diff --git a/OpenApi/Languages/OpenApiLanguage.cs b/OpenApi/Languages/OpenApiLanguage.cs index 80c69cbc..e5ccbe6e 100644 --- a/OpenApi/Languages/OpenApiLanguage.cs +++ b/OpenApi/Languages/OpenApiLanguage.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -using KY.Generator.Languages; +using KY.Generator.Languages; namespace KY.Generator.OpenApi.Languages { diff --git a/OpenApi/OpenApiModule.cs b/OpenApi/OpenApiModule.cs index 192c5bf0..3b8c9dc6 100644 --- a/OpenApi/OpenApiModule.cs +++ b/OpenApi/OpenApiModule.cs @@ -1,7 +1,8 @@ using KY.Core.Dependency; using KY.Core.Module; -using KY.Generator.Configuration; +using KY.Generator.Command; using KY.Generator.Mappings; +using KY.Generator.OpenApi.Commands; using KY.Generator.OpenApi.Configurations; using KY.Generator.OpenApi.DataAccess; using KY.Generator.OpenApi.Languages; @@ -20,7 +21,8 @@ public override void Initialize() this.DependencyResolver.Bind().ToSelf(); this.DependencyResolver.Bind().ToSelf(); this.DependencyResolver.Bind().ToSelf(); - this.DependencyResolver.Get().Map("openApi"); + this.DependencyResolver.Get() + .Register("openApi", "read"); this.DependencyResolver.Get().Initialize(); } } diff --git a/Reflection.Tests/Data/CustomGeneric.cs b/Reflection.Tests/Data/CustomGeneric.cs index 8b6732bf..c1bad96b 100644 --- a/Reflection.Tests/Data/CustomGeneric.cs +++ b/Reflection.Tests/Data/CustomGeneric.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace KY.Generator.Reflection.Tests +namespace KY.Generator.Reflection.Tests { public class CustomGeneric { diff --git a/Reflection.Tests/Data/CustomTypeInArray.cs b/Reflection.Tests/Data/CustomTypeInArray.cs index 1d28f8f7..9a70e956 100644 --- a/Reflection.Tests/Data/CustomTypeInArray.cs +++ b/Reflection.Tests/Data/CustomTypeInArray.cs @@ -1,7 +1,4 @@ -using System; -using System.Text; - -namespace KY.Generator.Reflection.Tests +namespace KY.Generator.Reflection.Tests { public class CustomTypeInArray { diff --git a/Reflection.Tests/InterfaceTest.cs b/Reflection.Tests/InterfaceTest.cs index f717dbe8..fb8ce2e5 100644 --- a/Reflection.Tests/InterfaceTest.cs +++ b/Reflection.Tests/InterfaceTest.cs @@ -1,3 +1,4 @@ +using KY.Core; using KY.Generator.Csharp; using KY.Generator.Output; using KY.Generator.Reflection.Tests.Properties; @@ -7,7 +8,7 @@ namespace KY.Generator.Reflection.Tests { [TestClass] - public class InterfaceTest + public class InterfaceTest : MsTestBase { private MemoryOutput output; diff --git a/Reflection.Tests/KY.Generator.Reflection.Tests.csproj b/Reflection.Tests/KY.Generator.Reflection.Tests.csproj index c12d7962..772e786c 100644 --- a/Reflection.Tests/KY.Generator.Reflection.Tests.csproj +++ b/Reflection.Tests/KY.Generator.Reflection.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Reflection.Tests/ReflectionModelReaderTests.cs b/Reflection.Tests/ReflectionModelReaderTests.cs index ba302ce5..c9be3db6 100644 --- a/Reflection.Tests/ReflectionModelReaderTests.cs +++ b/Reflection.Tests/ReflectionModelReaderTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using KY.Core; using KY.Generator.Reflection.Readers; using KY.Generator.Transfer; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -8,7 +9,7 @@ namespace KY.Generator.Reflection.Tests { [TestClass] - public class ReflectionModelReaderTests + public class ReflectionModelReaderTests : MsTestBase { private ReflectionModelReader reader; diff --git a/Reflection/Readers/ReflectionReader.cs b/Reflection/Commands/ReadReflectionCommand.cs similarity index 62% rename from Reflection/Readers/ReflectionReader.cs rename to Reflection/Commands/ReadReflectionCommand.cs index 302a7fc2..3398ee02 100644 --- a/Reflection/Readers/ReflectionReader.cs +++ b/Reflection/Commands/ReadReflectionCommand.cs @@ -1,26 +1,27 @@ using System; using System.Collections.Generic; -using System.Linq; using KY.Core; -using KY.Generator.Configurations; +using KY.Generator.Command; +using KY.Generator.Configuration; using KY.Generator.Reflection.Configurations; +using KY.Generator.Reflection.Readers; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; -namespace KY.Generator.Reflection.Readers +namespace KY.Generator.Reflection.Commands { - internal class ReflectionReader : ITransferReader + internal class ReadReflectionCommand : IConfigurationCommand { private readonly ReflectionModelReader modelReader; - public ReflectionReader(ReflectionModelReader modelReader) + public ReadReflectionCommand(ReflectionModelReader modelReader) { this.modelReader = modelReader; } - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { - ReflectionReadConfiguration configuration = (ReflectionReadConfiguration)configurationBase; + Logger.Trace("Read reflection..."); + ReadReflectionConfiguration configuration = (ReadReflectionConfiguration)configurationBase; Type type = GeneratorTypeLoader.Get(configuration, configuration.Assembly, configuration.Namespace, configuration.Name); if (type != null) { @@ -31,6 +32,7 @@ public void Read(ConfigurationBase configurationBase, List tran Logger.Trace($"{selfModel.Name} ({selfModel.Namespace}) skipped through configuration"); } } + return true; } } } \ No newline at end of file diff --git a/Reflection/Writers/ReflectionWriter.cs b/Reflection/Commands/WriteReflectionCommand.cs similarity index 52% rename from Reflection/Writers/ReflectionWriter.cs rename to Reflection/Commands/WriteReflectionCommand.cs index 5b6718ab..1b309846 100644 --- a/Reflection/Writers/ReflectionWriter.cs +++ b/Reflection/Commands/WriteReflectionCommand.cs @@ -1,32 +1,36 @@ using System; using System.Collections.Generic; -using KY.Generator.Configurations; -using KY.Generator.Output; +using KY.Core; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Extensions; using KY.Generator.Reflection.Configurations; using KY.Generator.Templates; using KY.Generator.Transfer; using KY.Generator.Transfer.Writers; -namespace KY.Generator.Reflection.Writers +namespace KY.Generator.Reflection.Commands { - internal class ReflectionWriter : ITransferWriter + internal class WriteReflectionCommand : IConfigurationCommand { private readonly ModelWriter modelWriter; - public ReflectionWriter(ModelWriter modelWriter) + public WriteReflectionCommand(ModelWriter modelWriter) { this.modelWriter = modelWriter; } - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) + public bool Execute(IConfiguration configurationBase, List transferObjects) { - ReflectionWriteConfiguration configuration = (ReflectionWriteConfiguration)configurationBase; + Logger.Trace("Write reflection..."); + WriteReflectionConfiguration configuration = (WriteReflectionConfiguration)configurationBase; if (configuration.Language == null) { throw new InvalidOperationException($"Can not generate Reflection.Type for language {configuration.Language?.Name ?? "Empty"}"); } List files = this.modelWriter.Write(configuration, transferObjects); - files.ForEach(file => configuration.Language.Write(file, output)); + files.Write(configuration); + return true; } } } \ No newline at end of file diff --git a/Reflection/Configurations/ReflectionReadConfiguration.cs b/Reflection/Configurations/ReadReflectionConfiguration.cs similarity index 69% rename from Reflection/Configurations/ReflectionReadConfiguration.cs rename to Reflection/Configurations/ReadReflectionConfiguration.cs index 51dec8e6..2e6af83f 100644 --- a/Reflection/Configurations/ReflectionReadConfiguration.cs +++ b/Reflection/Configurations/ReadReflectionConfiguration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Reflection.Configurations { - public class ReflectionReadConfiguration : ReadConfigurationBase + public class ReadReflectionConfiguration : ConfigurationBase { public string Assembly { get; set; } public string Name { get; set; } diff --git a/Reflection/Configurations/ReflectionConfiguration.cs b/Reflection/Configurations/ReflectionConfiguration.cs new file mode 100644 index 00000000..5df9995e --- /dev/null +++ b/Reflection/Configurations/ReflectionConfiguration.cs @@ -0,0 +1,135 @@ +using System.Collections.Generic; +using KY.Generator.Configuration; +using KY.Generator.Languages; +using KY.Generator.Output; +using Newtonsoft.Json; + +namespace KY.Generator.Reflection.Configurations +{ + internal class ReflectionConfiguration : IConfigurationWithLanguage, IModelConfiguration + { + public ReadReflectionConfiguration Read { get; } + public WriteReflectionConfiguration Write { get; } + + public string Assembly + { + get => this.Read.Assembly; + set => this.Read.Assembly = value; + } + + public string Name + { + get => this.Read.Name; + set => this.Read.Name = value; + } + + public string Namespace + { + get => this.Read.Namespace; + set => this.Read.Namespace = value; + } + + public string RelativePath + { + get => this.Write.RelativePath; + set => this.Write.RelativePath = value; + } + + public bool AddHeader + { + get => this.Write.AddHeader; + set => this.Write.AddHeader = value; + } + + public bool SkipHeader + { + get => !this.AddHeader; + set => this.AddHeader = !value; + } + + public bool SkipSelf + { + get => this.Read.SkipSelf; + set => this.Read.SkipSelf = value; + } + + public bool SkipNamespace + { + get => this.Write.SkipNamespace; + set => this.Write.SkipNamespace = value; + } + + public List Usings + { + get => this.Write.Usings; + set => this.Write.Usings = value; + } + + public ConfigurationFormatting Formatting => this.Write.Formatting; + + public IOutput Output + { + get => this.Write.Output; + set => this.Write.Output = value; + } + + public ConfigurationEnvironment Environment => this.Write.Environment; + + public bool BeforeBuild + { + get => this.Read.BeforeBuild; + set + { + this.Read.BeforeBuild = value; + this.Write.BeforeBuild = value; + } + } + + [JsonIgnore] + [ConfigurationIgnore] + public ILanguage Language + { + get => this.Write.Language; + set => this.Write.Language = value; + } + + [JsonProperty("Language")] + [ConfigurationProperty("Language")] + public string LanguageKey + { + get => this.Write.LanguageKey; + set => this.Write.LanguageKey = value; + } + + public bool FormatNames + { + get => this.Write.FormatNames; + set => this.Write.FormatNames = value; + } + + public string Using + { + get => this.Write.Using; + set => this.Write.Using = value; + } + + public bool FieldsToProperties + { + get => this.Formatting.FieldsToProperties; + set => this.Formatting.FieldsToProperties = value; + } + + public bool PropertiesToFields + { + get => this.Formatting.PropertiesToFields; + set => this.Formatting.PropertiesToFields = value; + } + + public ReflectionConfiguration() + { + this.Read = new ReadReflectionConfiguration(); + this.Write = new WriteReflectionConfiguration(); + this.Write.Environment = this.Read.Environment; + } + } +} \ No newline at end of file diff --git a/Reflection/Configurations/ReflectionWriteConfiguration.cs b/Reflection/Configurations/WriteReflectionConfiguration.cs similarity index 77% rename from Reflection/Configurations/ReflectionWriteConfiguration.cs rename to Reflection/Configurations/WriteReflectionConfiguration.cs index 63af0ee2..9f842c23 100644 --- a/Reflection/Configurations/ReflectionWriteConfiguration.cs +++ b/Reflection/Configurations/WriteReflectionConfiguration.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Reflection.Configurations { - internal class ReflectionWriteConfiguration : ConfigurationBase, IModelConfiguration + internal class WriteReflectionConfiguration : ConfigurationWithLanguageBase, IModelConfiguration { public string Name { get; set; } public string Namespace { get; set; } @@ -23,10 +23,10 @@ public bool PropertiesToFields } public bool SkipNamespace { get; set; } - public List Usings { get; } + public List Usings { get; set; } public bool FormatNames { get; set; } - public ReflectionWriteConfiguration() + public WriteReflectionConfiguration() { this.Usings = new List(); } diff --git a/Reflection/KY.Generator.Reflection.csproj b/Reflection/KY.Generator.Reflection.csproj index 597ea184..b08483bb 100644 --- a/Reflection/KY.Generator.Reflection.csproj +++ b/Reflection/KY.Generator.Reflection.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Reflection/ReflectionModule.cs b/Reflection/ReflectionModule.cs index be2c66e3..7ae26d6c 100644 --- a/Reflection/ReflectionModule.cs +++ b/Reflection/ReflectionModule.cs @@ -1,13 +1,11 @@ using KY.Core.Dependency; using KY.Core.Module; using KY.Generator.Command; -using KY.Generator.Configuration; using KY.Generator.Mappings; using KY.Generator.Reflection.Commands; using KY.Generator.Reflection.Configurations; using KY.Generator.Reflection.Extensions; using KY.Generator.Reflection.Readers; -using KY.Generator.Reflection.Writers; namespace KY.Generator.Reflection { @@ -19,14 +17,14 @@ public ReflectionModule(IDependencyResolver dependencyResolver) public override void Initialize() { - this.DependencyResolver.Bind().To(); this.DependencyResolver.Get().Initialize(); this.DependencyResolver.Bind().ToSelf(); - this.DependencyResolver.Bind().ToSelf(); - this.DependencyResolver.Bind().ToSelf(); - this.DependencyResolver.Get() - .Map("reflection") - .Map("reflection"); + this.DependencyResolver.Bind().ToSelf(); + this.DependencyResolver.Bind().ToSelf(); + this.DependencyResolver.Get() + .Register("reflection") + .Register("reflection", "read") + .Register("reflection", "write"); } } } \ No newline at end of file diff --git a/Tests/DeserializationTests.cs b/Tests/DeserializationTests.cs index 59c8e3af..f5cafae9 100644 --- a/Tests/DeserializationTests.cs +++ b/Tests/DeserializationTests.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using System.Linq; -using System.Text; using KY.Core; -using KY.Core.Dependency; +using KY.Generator.Command; using KY.Generator.Configuration; +using KY.Generator.Configurations; +using KY.Generator.Core.Tests; +using KY.Generator.Exceptions; using KY.Generator.Tests.Models; using KY.Generator.Tests.Properties; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -11,134 +11,89 @@ namespace KY.Generator.Tests { [TestClass] - public class DeserializationTests + public class DeserializationTests : MsTestBase { - private IDependencyResolver resolver; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Get() - .Map("1") - .Map("2") - .Map("1") - .Map("2"); - this.resolver.Create().Initialize(); + this.runner = new TestConfigurationRunner() + .Initialize(); + this.runner.Resolver.Get() + .Register("1", "read") + .Register("2", "read") + .Register("1", "write") + .Register("2", "write"); } [TestMethod] public void EmptyConfiguration() { - ConfigurationsReader reader = this.resolver.Create(); + ConfigurationsReader reader = this.runner.Resolver.Create(); Assert.ThrowsException(() => reader.Parse(Resources.empty_configuration)); } [TestMethod] + [ExpectedException(typeof(UnknownCommandException))] public void EmptyGenerate() { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.empty_generate); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(0, sets[0].Configurations.Count, "Unexpected number of configurations"); - } - - [TestMethod] - public void EmptyConfigurationArray() - { - //string json = Encoding.UTF8.GetString(Resources.empty_configuration_array); - //ConfigurationsReader reader = this.resolver.Create(); - //List configurations = reader.Parse(json); - //Assert.AreEqual(2, configurations.Count, "Unexpected number of configurations"); - Assert.Inconclusive("Not implemented yet"); + ConfigurationsReader reader = this.runner.Resolver.Create(); + reader.Parse(Resources.empty_generate); } [TestMethod] public void OneGenerate() { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.one_generate); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(1, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test1", sets[0].Configurations[0].CastTo().Property1); + ConfigurationsReader reader = this.runner.Resolver.Create(); + ExecuteConfiguration configuration = reader.Parse(Resources.one_generate); + Assert.AreEqual(1, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Test1", configuration.Execute[0].CastTo().Property1); } [TestMethod] public void OneGenerateInArray() { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.one_generate_in_array); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(1, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test1", sets[0].Configurations[0].CastTo().Property1); + ConfigurationsReader reader = this.runner.Resolver.Create(); + ExecuteConfiguration configuration = reader.Parse(Resources.one_generate_in_array); + Assert.AreEqual(1, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Test1", configuration.Execute[0].CastTo().Property1); } [TestMethod] + [ExpectedException(typeof(InvalidConfigurationException))] public void OneGenerateInArrayArray() { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.one_generate_in_array_array); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(1, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test1", sets[0].Configurations[0].CastTo().Property1); - } - - [TestMethod] - public void TwoGenerateInArrayArray() - { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.two_generates_in_array_array); - Assert.AreEqual(2, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(1, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test1", sets[0].Configurations[0].CastTo().Property1); - Assert.AreEqual(1, sets[1].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test2", sets[1].Configurations[0].CastTo().Property2); + ConfigurationsReader reader = this.runner.Resolver.Create(); + ExecuteConfiguration configuration = reader.Parse(Resources.one_generate_in_array_array); } [TestMethod] public void OneReadOneGenerate() { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.one_read_one_generate); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(2, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test1", sets[0].Configurations[0].CastTo().Property1); - Assert.AreEqual("Test2", sets[0].Configurations[1].CastTo().Property1); + ConfigurationsReader reader = this.runner.Resolver.Create(); + ExecuteConfiguration configuration = reader.Parse(Resources.one_read_one_generate); + Assert.AreEqual(2, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Test1", configuration.Execute[0].CastTo().Property1); + Assert.AreEqual("Test2", configuration.Execute[1].CastTo().Property1); } [TestMethod] public void TwoReadsOneGenerate() { - ConfigurationsReader reader = this.resolver.Create(); - List sets = reader.Parse(Resources.two_reads_one_generate); - Assert.AreEqual(1, sets.Count, "Unexpected number of sets"); - Assert.AreEqual(3, sets[0].Configurations.Count, "Unexpected number of configurations"); - Assert.AreEqual("Test1", sets[0].Configurations[0].CastTo().Property1); - Assert.AreEqual("Test2", sets[0].Configurations[1].CastTo().Property2); - Assert.AreEqual("Test3", sets[0].Configurations[2].CastTo().Property1); - } - - [TestMethod] - public void OneReadOneGenerateTwice() - { - ConfigurationsReader reader = this.resolver.Create(); - List configurations = reader.Parse(Resources.one_read_one_generate_twice); - Assert.AreEqual(2, configurations.Count, "Unexpected number of sets"); - Assert.AreEqual(2, configurations[0].Configurations.Count, "Unexpected number of config 1 configurations"); - Assert.AreEqual(2, configurations[1].Configurations.Count, "Unexpected number of config 2 configurations"); - Assert.AreEqual("Test1", configurations[0].Configurations[0].CastTo().Property1); - Assert.AreEqual("Test2", configurations[0].Configurations[1].CastTo().Property1); - Assert.AreEqual("Test3", configurations[1].Configurations[0].CastTo().Property2); - Assert.AreEqual("Test4", configurations[1].Configurations[1].CastTo().Property2); + ConfigurationsReader reader = this.runner.Resolver.Create(); + ExecuteConfiguration configuration = reader.Parse(Resources.two_reads_one_generate); + Assert.AreEqual(3, configuration.Execute.Count, "Unexpected number of configurations"); + Assert.AreEqual("Test1", configuration.Execute[0].CastTo().Property1); + Assert.AreEqual("Test2", configuration.Execute[1].CastTo().Property2); + Assert.AreEqual("Test3", configuration.Execute[2].CastTo().Property1); } [TestMethod] public void OldConfig() { string json = Resources.old_config; - ConfigurationsReader reader = this.resolver.Create(); + ConfigurationsReader reader = this.runner.Resolver.Create(); Assert.ThrowsException(() => reader.Parse(json)); } @@ -146,7 +101,7 @@ public void OldConfig() public void OldConfigXml() { string json = Resources.old_config1; - ConfigurationsReader reader = this.resolver.Create(); + ConfigurationsReader reader = this.runner.Resolver.Create(); Assert.ThrowsException(() => reader.Parse(json)); } } diff --git a/Tests/FullStageTests.cs b/Tests/FullStageTests.cs index 8070e77f..32c15534 100644 --- a/Tests/FullStageTests.cs +++ b/Tests/FullStageTests.cs @@ -1,11 +1,8 @@ -using System.Collections.Generic; -using KY.Core.Dependency; +using KY.Core; using KY.Generator.AspDotNet; -using KY.Generator.Configuration; +using KY.Generator.Core.Tests; using KY.Generator.Csharp; using KY.Generator.EntityFramework; -using KY.Generator.Mappings; -using KY.Generator.Output; using KY.Generator.Tests.Properties; using KY.Generator.Tsql; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -13,46 +10,30 @@ namespace KY.Generator.Tests { [TestClass] - public class FullStageTests + public class FullStageTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; - private ConfigurationRunner runner; - private MemoryOutput output; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().ToSingleton(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); - this.runner = this.resolver.Create(); - this.output = this.resolver.Create(); + this.runner = new TestConfigurationRunner() + .Initialize() + .Initialize() + .Initialize() + .Initialize() + .Initialize(); } [TestMethod] public void FullProject() { - Assert.AreEqual(true, this.Run(Resources.full_project_generator), "Generation not successful"); - Assert.AreEqual(4, this.output.Files.Count); - Assert.AreEqual(Resources.User_cs, this.output.Files["Models\\User.cs"]); - Assert.AreEqual(Resources.UserController_cs, this.output.Files["Controllers\\UserController.cs"]); - Assert.AreEqual(Resources.UserRepository_cs, this.output.Files["Repositories\\UserRepository.cs"]); - Assert.AreEqual(Resources.DataContext, this.output.Files["Repositories\\DataContext.cs"]); - } - - private bool Run(string configuration) - { - List configurations = this.reader.Parse(configuration); - configurations.ForEach(x => x.Configurations.ForEach(y => y.AddHeader = false)); - return this.runner.Run(configurations, this.output); + Assert.AreEqual(true, this.runner.Run(Resources.full_project_generator), "Generation not successful"); + Assert.AreEqual(4, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.User_cs, this.runner.Output.Files["Models\\User.cs"]); + Assert.AreEqual(Resources.UserController_cs, this.runner.Output.Files["Controllers\\UserController.cs"]); + Assert.AreEqual(Resources.UserRepository_cs, this.runner.Output.Files["Repositories\\UserRepository.cs"]); + Assert.AreEqual(Resources.DataContext, this.runner.Output.Files["Repositories\\DataContext.cs"]); } } -} +} \ No newline at end of file diff --git a/Tests/KY.Generator.Tests.csproj b/Tests/KY.Generator.Tests.csproj index 34c235b1..4553c1fd 100644 --- a/Tests/KY.Generator.Tests.csproj +++ b/Tests/KY.Generator.Tests.csproj @@ -7,7 +7,7 @@ - + @@ -15,6 +15,7 @@ + diff --git a/Tests/Models/Reader1.cs b/Tests/Models/Read1Command.cs similarity index 60% rename from Tests/Models/Reader1.cs rename to Tests/Models/Read1Command.cs index 578ecc39..d4c418ca 100644 --- a/Tests/Models/Reader1.cs +++ b/Tests/Models/Read1Command.cs @@ -1,16 +1,16 @@ using System.Collections.Generic; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; namespace KY.Generator.Tests.Models { - internal class Reader1 : ITransferReader + internal class Read1Command : IConfigurationCommand { - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { Read1Configuration configuration = (Read1Configuration)configurationBase; + return configuration != null; } } } \ No newline at end of file diff --git a/Tests/Models/Read1Configuration.cs b/Tests/Models/Read1Configuration.cs index ddc26060..d3666e7f 100644 --- a/Tests/Models/Read1Configuration.cs +++ b/Tests/Models/Read1Configuration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Tests.Models { - internal class Read1Configuration : ReadConfigurationBase + internal class Read1Configuration : ConfigurationBase { public string Property1 { get; set; } } diff --git a/Tests/Models/Reader2.cs b/Tests/Models/Read2Command.cs similarity index 60% rename from Tests/Models/Reader2.cs rename to Tests/Models/Read2Command.cs index ce026be5..b10ba2df 100644 --- a/Tests/Models/Reader2.cs +++ b/Tests/Models/Read2Command.cs @@ -1,16 +1,16 @@ using System.Collections.Generic; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; namespace KY.Generator.Tests.Models { - internal class Reader2 : ITransferReader + internal class Read2Command : IConfigurationCommand { - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { Read2Configuration configuration = (Read2Configuration)configurationBase; + return configuration != null; } } } \ No newline at end of file diff --git a/Tests/Models/Read2Configuration.cs b/Tests/Models/Read2Configuration.cs index 6bddb994..1b9d37e7 100644 --- a/Tests/Models/Read2Configuration.cs +++ b/Tests/Models/Read2Configuration.cs @@ -1,8 +1,8 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Tests.Models { - internal class Read2Configuration : ReadConfigurationBase + internal class Read2Configuration : ConfigurationBase { public string Property2 { get; set; } } diff --git a/Tests/Models/Write1Command.cs b/Tests/Models/Write1Command.cs new file mode 100644 index 00000000..dfc642fd --- /dev/null +++ b/Tests/Models/Write1Command.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Transfer; + +namespace KY.Generator.Tests.Models +{ + internal class Write1Command : IConfigurationCommand + { + public bool Execute(IConfiguration configurationBase, List transferObjects) + { + Write1Configuration configuration = (Write1Configuration)configurationBase; + return configuration != null; + } + } +} \ No newline at end of file diff --git a/Tests/Models/Write1Configuration.cs b/Tests/Models/Write1Configuration.cs index 14c3c11c..1c57d3ad 100644 --- a/Tests/Models/Write1Configuration.cs +++ b/Tests/Models/Write1Configuration.cs @@ -1,4 +1,4 @@ -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Tests.Models { diff --git a/Tests/Models/Write2Command.cs b/Tests/Models/Write2Command.cs new file mode 100644 index 00000000..245a95be --- /dev/null +++ b/Tests/Models/Write2Command.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using KY.Generator.Command; +using KY.Generator.Configuration; +using KY.Generator.Transfer; + +namespace KY.Generator.Tests.Models +{ + internal class Write2Command : IConfigurationCommand + { + public bool Execute(IConfiguration configurationBase, List transferObjects) + { + Write2Configuration configuration = (Write2Configuration)configurationBase; + return configuration != null; + } + } +} \ No newline at end of file diff --git a/Tests/Models/Write2Configuration.cs b/Tests/Models/Write2Configuration.cs index 673c3914..e0ff6e66 100644 --- a/Tests/Models/Write2Configuration.cs +++ b/Tests/Models/Write2Configuration.cs @@ -1,5 +1,4 @@ using KY.Generator.Configuration; -using KY.Generator.Configurations; namespace KY.Generator.Tests.Models { diff --git a/Tests/Models/Writer1.cs b/Tests/Models/Writer1.cs deleted file mode 100644 index 068d5623..00000000 --- a/Tests/Models/Writer1.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Output; -using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; - -namespace KY.Generator.Tests.Models -{ - internal class Writer1 : ITransferWriter - { - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) - { - Write1Configuration configuration = (Write1Configuration)configurationBase; - } - } -} \ No newline at end of file diff --git a/Tests/Models/Writer2.cs b/Tests/Models/Writer2.cs deleted file mode 100644 index 3ff07463..00000000 --- a/Tests/Models/Writer2.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using KY.Generator.Configuration; -using KY.Generator.Configurations; -using KY.Generator.Output; -using KY.Generator.Transfer; -using KY.Generator.Transfer.Writers; - -namespace KY.Generator.Tests.Models -{ - internal class Writer2 : ITransferWriter - { - public void Write(ConfigurationBase configurationBase, List transferObjects, IOutput output) - { - Write2Configuration configuration = (Write2Configuration)configurationBase; - } - } -} \ No newline at end of file diff --git a/Tests/Properties/Resources.Designer.cs b/Tests/Properties/Resources.Designer.cs index 36ead016..8bce5d0f 100644 --- a/Tests/Properties/Resources.Designer.cs +++ b/Tests/Properties/Resources.Designer.cs @@ -97,18 +97,6 @@ internal static string empty_configuration { } } - /// - /// Looks up a localized string similar to [ - /// {}, - /// {} - ///]. - /// - internal static string empty_configuration_array { - get { - return ResourceManager.GetString("empty_configuration_array", resourceCulture); - } - } - /// /// Looks up a localized string similar to { /// "generate": {} @@ -256,66 +244,6 @@ internal static string one_read_one_generate { } } - /// - /// Looks up a localized string similar to { - /// "version": 2, - /// "generate": [ - /// [ - /// { - /// "Read": "1", - /// "Property1": "Test1" - /// }, - /// { - /// "Write": "1", - /// "Property1": "Test2" - /// } - /// ], - /// [ - /// { - /// "Read": "2", - /// "Property1": "Test3" - /// }, - /// { - /// "Write": "2", - /// "Property1": "Test4" - /// } - /// ] - /// ] - ///} - /// - ///. - /// - internal static string one_read_one_generate_twice { - get { - return ResourceManager.GetString("one_read_one_generate_twice", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to { - /// "version": 2, - /// "generate": [ - /// [ - /// { - /// "write": "1", - /// "property1": "Test1" - /// } - /// ], - /// [ - /// { - /// "write": "2", - /// "property2": "Test2" - /// } - /// ] - /// ] - ///}. - /// - internal static string two_generates_in_array_array { - get { - return ResourceManager.GetString("two_generates_in_array_array", resourceCulture); - } - } - /// /// Looks up a localized string similar to { /// "version": 2, diff --git a/Tests/Properties/Resources.resx b/Tests/Properties/Resources.resx index 9baef8da..be096a12 100644 --- a/Tests/Properties/Resources.resx +++ b/Tests/Properties/Resources.resx @@ -121,9 +121,6 @@ ..\Resources\empty-configuration.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - ..\Resources\empty-configuration-array.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - ..\Resources\empty-generate.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 @@ -148,9 +145,6 @@ ..\Resources\one-read-one-generate.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - - ..\Resources\one-read-one-generate-twice.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - ..\Resources\two-reads-one-generate.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 @@ -166,7 +160,4 @@ ..\Resources\DataContext.result;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - ..\Resources\two-generates-in-array-array.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - \ No newline at end of file diff --git a/Tests/Resources/empty-configuration-array.json b/Tests/Resources/empty-configuration-array.json deleted file mode 100644 index a362f22a..00000000 --- a/Tests/Resources/empty-configuration-array.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - {}, - {} -] \ No newline at end of file diff --git a/Tests/Resources/one-read-one-generate-twice.json b/Tests/Resources/one-read-one-generate-twice.json deleted file mode 100644 index b8f4733c..00000000 --- a/Tests/Resources/one-read-one-generate-twice.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": 2, - "generate": [ - [ - { - "Read": "1", - "Property1": "Test1" - }, - { - "Write": "1", - "Property1": "Test2" - } - ], - [ - { - "Read": "2", - "Property2": "Test3" - }, - { - "Write": "2", - "Property2": "Test4" - } - ] - ] -} - diff --git a/Tests/Resources/two-generates-in-array-array.json b/Tests/Resources/two-generates-in-array-array.json deleted file mode 100644 index bb95e4b2..00000000 --- a/Tests/Resources/two-generates-in-array-array.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": 2, - "generate": [ - [ - { - "write": "1", - "property1": "Test1" - } - ], - [ - { - "write": "2", - "property2": "Test2" - } - ] - ] -} \ No newline at end of file diff --git a/Tsql.Tests/FullStageTests.cs b/Tsql.Tests/FullStageTests.cs index 891485c8..eeb7562f 100644 --- a/Tsql.Tests/FullStageTests.cs +++ b/Tsql.Tests/FullStageTests.cs @@ -1,50 +1,31 @@ -using System.Collections.Generic; -using KY.Core.Dependency; -using KY.Generator.Configuration; +using KY.Core; +using KY.Generator.Core.Tests; using KY.Generator.Csharp; -using KY.Generator.Mappings; -using KY.Generator.Output; using KY.Generator.Tsql.Tests.Properties; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace KY.Generator.Tsql.Tests { [TestClass] - public class FullStageTests + public class FullStageTests : MsTestBase { - private IDependencyResolver resolver; - private ConfigurationsReader reader; - private ConfigurationRunner runner; - private MemoryOutput output; + private TestConfigurationRunner runner; [TestInitialize] public void Initialize() { - this.resolver = new DependencyResolver(); - this.resolver.Bind().ToSingleton(); - this.resolver.Bind().To(); - this.resolver.Bind().ToSingleton(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.resolver.Create().Initialize(); - this.reader = this.resolver.Create(); - this.runner = this.resolver.Create(); - this.output = this.resolver.Create(); + this.runner = new TestConfigurationRunner() + .Initialize() + .Initialize() + .Initialize(); } [TestMethod] public void TestMethod1() { - Assert.AreEqual(true, this.Run(Resources.tsql_generator), "Generation not successful"); - Assert.AreEqual(1, this.output.Files.Count); - Assert.AreEqual(Resources.User_cs, this.output.Files["User.cs"]); - } - - private bool Run(string configuration) - { - List sets = this.reader.Parse(configuration); - sets.ForEach(x => x.Configurations.ForEach(y => y.AddHeader = false)); - return this.runner.Run(sets, this.output); + Assert.AreEqual(true, this.runner.Run(Resources.tsql_generator), "Generation not successful"); + Assert.AreEqual(1, this.runner.Output.Files.Count); + Assert.AreEqual(Resources.User_cs, this.runner.Output.Files["User.cs"]); } } } \ No newline at end of file diff --git a/Tsql.Tests/KY.Generator.Tsql.Tests.csproj b/Tsql.Tests/KY.Generator.Tsql.Tests.csproj index 4243d656..e0edc1ad 100644 --- a/Tsql.Tests/KY.Generator.Tsql.Tests.csproj +++ b/Tsql.Tests/KY.Generator.Tsql.Tests.csproj @@ -7,13 +7,14 @@ - + + diff --git a/Tsql/Readers/TsqlReader.cs b/Tsql/Commands/ReadTsqlCommand.cs similarity index 95% rename from Tsql/Readers/TsqlReader.cs rename to Tsql/Commands/ReadTsqlCommand.cs index 5cd01fdf..4b9d1d64 100644 --- a/Tsql/Readers/TsqlReader.cs +++ b/Tsql/Commands/ReadTsqlCommand.cs @@ -2,21 +2,21 @@ using System.Collections.Generic; using System.Linq; using KY.Core; +using KY.Generator.Command; using KY.Generator.Configuration; -using KY.Generator.Configurations; using KY.Generator.Transfer; -using KY.Generator.Transfer.Readers; using KY.Generator.Tsql.Configurations; using KY.Generator.Tsql.Language; -using KY.Generator.Tsql.Transfers; +using KY.Generator.Tsql.TransferObjects; using KY.Generator.Tsql.Type; -namespace KY.Generator.Tsql.Readers +namespace KY.Generator.Tsql.Commands { - public class TsqlReader : ITransferReader + public class ReadTsqlCommand : IConfigurationCommand { - public void Read(ConfigurationBase configurationBase, List transferObjects) + public bool Execute(IConfiguration configurationBase, List transferObjects) { + Logger.Trace("Read TSQL..."); TsqlReadConfiguration configuration = (TsqlReadConfiguration)configurationBase; this.Validate(configuration); TsqlTypeReader typeReader = new TsqlTypeReader(configuration.Connection); @@ -104,6 +104,7 @@ public void Read(ConfigurationBase configurationBase, List tran storedProcedure.ReturnType = new TypeTransferObject { Name = "void", FromSystem = true }; transferObjects.Add(storedProcedure); } + return true; } private void Validate(TsqlReadConfiguration configuration) diff --git a/Tsql/Configurations/TsqlReadConfiguration.cs b/Tsql/Configurations/TsqlReadConfiguration.cs index a98a22be..e4a03121 100644 --- a/Tsql/Configurations/TsqlReadConfiguration.cs +++ b/Tsql/Configurations/TsqlReadConfiguration.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Tsql.Configurations { - public class TsqlReadConfiguration : ReadConfigurationBase + public class TsqlReadConfiguration : ConfigurationBase { public string Connection { get; set; } public List Entities { get; } diff --git a/Tsql/KY.Generator.Tsql.csproj b/Tsql/KY.Generator.Tsql.csproj index 5f836a17..8b89d7e7 100644 --- a/Tsql/KY.Generator.Tsql.csproj +++ b/Tsql/KY.Generator.Tsql.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Tsql/Transfers/StoredProcedureTransferObject.cs b/Tsql/TransferObjects/StoredProcedureTransferObject.cs similarity index 91% rename from Tsql/Transfers/StoredProcedureTransferObject.cs rename to Tsql/TransferObjects/StoredProcedureTransferObject.cs index 84710224..f7af6d31 100644 --- a/Tsql/Transfers/StoredProcedureTransferObject.cs +++ b/Tsql/TransferObjects/StoredProcedureTransferObject.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using KY.Generator.Transfer; -namespace KY.Generator.Tsql.Transfers +namespace KY.Generator.Tsql.TransferObjects { public class StoredProcedureTransferObject : ITransferObject { diff --git a/Tsql/TsqlModule.cs b/Tsql/TsqlModule.cs index 72ddb657..e37c0eb8 100644 --- a/Tsql/TsqlModule.cs +++ b/Tsql/TsqlModule.cs @@ -1,10 +1,10 @@ using KY.Core.Dependency; using KY.Core.Module; -using KY.Generator.Configuration; +using KY.Generator.Command; using KY.Generator.Mappings; +using KY.Generator.Tsql.Commands; using KY.Generator.Tsql.Configurations; using KY.Generator.Tsql.Language; -using KY.Generator.Tsql.Readers; namespace KY.Generator.Tsql { @@ -17,7 +17,8 @@ public TsqlModule(IDependencyResolver dependencyResolver) public override void Initialize() { this.DependencyResolver.Get().Initialize(); - this.DependencyResolver.Get().Map("tsql"); + this.DependencyResolver.Get() + .Register("tsql", "read"); } } } \ No newline at end of file diff --git a/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj b/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj index 8844ece8..8c6911cd 100644 --- a/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj +++ b/TypeScript.Tests/KY.Generator.TypeScript.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/TypeScript.Tests/TemplateWriterTests.cs b/TypeScript.Tests/TemplateWriterTests.cs index 35355428..75d3157c 100644 --- a/TypeScript.Tests/TemplateWriterTests.cs +++ b/TypeScript.Tests/TemplateWriterTests.cs @@ -1,3 +1,4 @@ +using KY.Core; using KY.Core.Dependency; using KY.Generator.Output; using KY.Generator.Templates; @@ -10,10 +11,11 @@ namespace KY.Generator.TypeScript.Tests { [TestClass] - public class TemplateWriterTests : Codeable + public class TemplateWriterTests : MsTestBase { private IDependencyResolver resolver; private IOutputCache output; + private static readonly Code Code = default; [TestInitialize] public void Initialize() diff --git a/TypeScript/KY.Generator.TypeScript.csproj b/TypeScript/KY.Generator.TypeScript.csproj index 1a2898cd..c2ece49a 100644 --- a/TypeScript/KY.Generator.TypeScript.csproj +++ b/TypeScript/KY.Generator.TypeScript.csproj @@ -18,7 +18,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/TypeScript/Languages/LanguageExtension.cs b/TypeScript/Languages/LanguageExtension.cs index 856e054d..e5135a80 100644 --- a/TypeScript/Languages/LanguageExtension.cs +++ b/TypeScript/Languages/LanguageExtension.cs @@ -1,4 +1,5 @@ -using KY.Generator.Languages; +using KY.Generator.Configuration; +using KY.Generator.Languages; namespace KY.Generator.TypeScript.Languages { @@ -8,5 +9,10 @@ public static bool IsTypeScript(this ILanguage language) { return language is TypeScriptLanguage; } + + public static bool IsTypeScript(this IConfiguration configuration) + { + return configuration is IConfigurationWithLanguage configurationWithLanguage && configurationWithLanguage.Language.IsTypeScript(); + } } } \ No newline at end of file diff --git a/TypeScript/Transfer/TypeScriptModelWriter.cs b/TypeScript/Transfer/TypeScriptModelWriter.cs index 30e12d88..51c24f85 100644 --- a/TypeScript/Transfer/TypeScriptModelWriter.cs +++ b/TypeScript/Transfer/TypeScriptModelWriter.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using KY.Generator.Configurations; +using KY.Generator.Configuration; using KY.Generator.Mappings; using KY.Generator.Templates; using KY.Generator.Templates.Extensions; @@ -21,7 +21,7 @@ public TypeScriptModelWriter(ITypeMapping typeMapping) protected override ClassTemplate WriteClass(IModelConfiguration configuration, ModelTransferObject model, string nameSpace, List files) { ClassTemplate classTemplate = base.WriteClass(configuration, model, nameSpace, files); - if (!model.IsAbstract && !model.IsInterface && configuration.Language.IsTypeScript()) + if (!model.IsAbstract && !model.IsInterface && configuration.IsTypeScript()) { ConstructorTemplate constructor = classTemplate.AddConstructor(); constructor.WithParameter(Code.Generic("Partial", classTemplate.ToType()), "init", Code.Null()) diff --git a/Watchdog/Configurations/WatchdogConfiguration.cs b/Watchdog/Configurations/WatchdogConfiguration.cs index c5125aa9..c2f95c7f 100644 --- a/Watchdog/Configurations/WatchdogConfiguration.cs +++ b/Watchdog/Configurations/WatchdogConfiguration.cs @@ -1,5 +1,5 @@ using System; -using KY.Generator.Configurations; +using KY.Generator.Configuration; namespace KY.Generator.Watchdog.Configurations { diff --git a/Watchdog/KY.Generator.Watchdog.csproj b/Watchdog/KY.Generator.Watchdog.csproj index 8251e965..15881d2c 100644 --- a/Watchdog/KY.Generator.Watchdog.csproj +++ b/Watchdog/KY.Generator.Watchdog.csproj @@ -17,7 +17,7 @@ Download KY.Generator.CLI to use this module - + diff --git a/Watchdog/WatchdogModule.cs b/Watchdog/WatchdogModule.cs index 062fb473..6c4c2a94 100644 --- a/Watchdog/WatchdogModule.cs +++ b/Watchdog/WatchdogModule.cs @@ -2,6 +2,7 @@ using KY.Core.Module; using KY.Generator.Command; using KY.Generator.Watchdog.Commands; +using KY.Generator.Watchdog.Configurations; namespace KY.Generator.Watchdog { @@ -13,7 +14,8 @@ public WatchdogModule(IDependencyResolver dependencyResolver) public override void Initialize() { - this.DependencyResolver.Bind().To(); + this.DependencyResolver.Get() + .Register("watchdog"); } } } \ No newline at end of file