From 264c1e1cd8c72245fdd1cea8efd9f3c1a93f68a3 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Sat, 12 Oct 2024 05:21:04 +0300 Subject: [PATCH] CLI --- Esiur.CLI/Program.cs | 68 +++++++++---------- Esiur.CLI/Properties/launchSettings.json | 8 +++ ...ur.Examples.StandaloneWebServerDemo.csproj | 4 +- .../Program.cs | 2 +- .../Esiur.Stores.EntityCore.csproj | 2 +- .../Esiur.Stores.MongoDB.csproj | 4 +- Esiur/Esiur.csproj | 10 +-- Esiur/Proxy/TemplateGenerator.cs | 22 +++--- Esiur/Tools/Esiur.psm1 | 4 +- 9 files changed, 66 insertions(+), 58 deletions(-) create mode 100644 Esiur.CLI/Properties/launchSettings.json diff --git a/Esiur.CLI/Program.cs b/Esiur.CLI/Program.cs index b1a6200..89e90f1 100644 --- a/Esiur.CLI/Program.cs +++ b/Esiur.CLI/Program.cs @@ -8,48 +8,48 @@ using System.Diagnostics; using System.IO; using System.Reflection; -static void Main(string[] args) + +if (args.Length > 0) { - - if (args.Length > 0) + if (args[0].ToLower() == "get-template" && args.Length >= 2) { - if (args[0].ToLower() == "get-template" && args.Length >= 2) + try { - try - { - var url = args[1]; + var url = args[1]; - Parser.Default.ParseArguments(args.Skip(2)) - .WithParsed(o => + Parser.Default.ParseArguments(args.Skip(2)) + .WithParsed(o => + { + try { - try - { - var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, o.Dir, o.Username, o.Password, o.AsyncSetters); - Console.WriteLine($"Generated successfully: {path}"); - } - catch (Exception ex) { - Console.WriteLine(ex.ToString()); - } - }); - return; - } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - return; - } + var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, o.Dir, false, o.Username, o.Password, o.AsyncSetters); + Console.WriteLine($"Generated successfully: {path}"); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + }); + return; } - else if (args[0].ToLower() == "version") + catch (Exception ex) { - var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion; - - Console.WriteLine(version); + Console.WriteLine(ex.ToString()); + return; } } + else if (args[0].ToLower() == "version") + { + var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion; - PrintHelp(); + Console.WriteLine("Esiur " + version); + return; + } } +PrintHelp(); + + static void PrintHelp() { var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion; @@ -58,13 +58,13 @@ static void PrintHelp() Console.WriteLine("Usage: [arguments]"); Console.WriteLine(""); Console.WriteLine("Available commands:"); - Console.WriteLine("\tget-template\t\tGet a template from an IIP link."); + Console.WriteLine("\tget-template\tGet a template from an IIP link."); Console.WriteLine("\tversion\t\tPrint Esiur version."); Console.WriteLine(""); Console.WriteLine("Global options:"); - Console.WriteLine("\t-u, --username\tAuthentication username."); - Console.WriteLine("\t-p, --password\tAuthentication password."); - Console.WriteLine("\t-d, --dir\tDirectory name where the generated models will be saved."); + Console.WriteLine("\t-u, --username\t\tAuthentication username."); + Console.WriteLine("\t-p, --password\t\tAuthentication password."); + Console.WriteLine("\t-d, --dir\t\tDirectory name where the generated models will be saved."); Console.WriteLine("\t-a, --async-setters\tUse asynchronous property setters."); } \ No newline at end of file diff --git a/Esiur.CLI/Properties/launchSettings.json b/Esiur.CLI/Properties/launchSettings.json new file mode 100644 index 0000000..983a993 --- /dev/null +++ b/Esiur.CLI/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Esiur.CLI": { + "commandName": "Project", + "commandLineArgs": "get-template iip://phase.delta.iq/sys/phase -d c:\\temp\\a" + } + } +} \ No newline at end of file diff --git a/Esiur.Examples.StandaloneWebServerDemo/Esiur.Examples.StandaloneWebServerDemo.csproj b/Esiur.Examples.StandaloneWebServerDemo/Esiur.Examples.StandaloneWebServerDemo.csproj index 2f01281..c8c8222 100644 --- a/Esiur.Examples.StandaloneWebServerDemo/Esiur.Examples.StandaloneWebServerDemo.csproj +++ b/Esiur.Examples.StandaloneWebServerDemo/Esiur.Examples.StandaloneWebServerDemo.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/Esiur.Examples.StandaloneWebServerDemo/Program.cs b/Esiur.Examples.StandaloneWebServerDemo/Program.cs index d7ac681..008b9c0 100644 --- a/Esiur.Examples.StandaloneWebServerDemo/Program.cs +++ b/Esiur.Examples.StandaloneWebServerDemo/Program.cs @@ -40,7 +40,7 @@ internal class Program } else { - sender.Response.Number = Esiur.Net.Packets.HTTPResponsePacket.ResponseCode.NotFound; + sender.Response.Number = Esiur.Net.Packets.HTTP.HTTPResponseCode.NotFound; sender.Send("`" + fn + "` Not Found"); sender.Close(); } diff --git a/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj b/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj index d772f7a..8e01fa9 100644 --- a/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj +++ b/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj @@ -22,7 +22,7 @@ - + diff --git a/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj b/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj index adbeaac..41cbc73 100644 --- a/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj +++ b/Esiur.Stores.MongoDB/Esiur.Stores.MongoDB.csproj @@ -17,8 +17,8 @@ - - + + diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index d110b1c..72ef6af 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -5,7 +5,7 @@ Ahmed Kh. Zamil http://www.esiur.com true - 2.4.4 + 2.4.5 https://github.com/esiur/esiur-dotnet Ahmed Kh. Zamil @@ -63,7 +63,7 @@ - + @@ -74,11 +74,11 @@ - + - - + + diff --git a/Esiur/Proxy/TemplateGenerator.cs b/Esiur/Proxy/TemplateGenerator.cs index cefee23..991c7a1 100644 --- a/Esiur/Proxy/TemplateGenerator.cs +++ b/Esiur/Proxy/TemplateGenerator.cs @@ -177,7 +177,7 @@ public static class TemplateGenerator return (representationType.Nullable) ? name + "?" : name; } - public static string GetTemplate(string url, string dir = null, string username = null, string password = null, bool asyncSetters = false) + public static string GetTemplate(string url, string dir = null, bool tempDir = false, string username = null, string password = null, bool asyncSetters = false) { try { @@ -200,14 +200,14 @@ public static class TemplateGenerator // no longer needed Warehouse.Remove(con); - var tempDir = new DirectoryInfo(Path.GetTempPath() + Path.DirectorySeparatorChar - + Misc.Global.GenerateCode(20) + Path.DirectorySeparatorChar + dir); + var dstDir = new DirectoryInfo(tempDir ? Path.GetTempPath() + Path.DirectorySeparatorChar + + Misc.Global.GenerateCode(20) + Path.DirectorySeparatorChar + dir : dir); - if (!tempDir.Exists) - tempDir.Create(); + if (!dstDir.Exists) + dstDir.Create(); else { - foreach (FileInfo file in tempDir.GetFiles()) + foreach (FileInfo file in dstDir.GetFiles()) file.Delete(); } @@ -217,17 +217,17 @@ public static class TemplateGenerator if (tmp.Type == TemplateType.Resource) { var source = GenerateClass(tmp, templates, asyncSetters); - File.WriteAllText(tempDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source); } else if (tmp.Type == TemplateType.Record) { var source = GenerateRecord(tmp, templates); - File.WriteAllText(tempDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source); } else if (tmp.Type == TemplateType.Enum) { var source = GenerateEnum(tmp, templates); - File.WriteAllText(tempDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + tmp.ClassName + ".Generated.cs", source); } } @@ -248,10 +248,10 @@ public static class TemplateGenerator "\r\n } \r\n}"; - File.WriteAllText(tempDir.FullName + Path.DirectorySeparatorChar + "Esiur.Generated.cs", typesFile); + File.WriteAllText(dstDir.FullName + Path.DirectorySeparatorChar + "Esiur.Generated.cs", typesFile); - return tempDir.FullName; + return dstDir.FullName; } catch (Exception ex) diff --git a/Esiur/Tools/Esiur.psm1 b/Esiur/Tools/Esiur.psm1 index 90f3c3a..a2ba17e 100644 --- a/Esiur/Tools/Esiur.psm1 +++ b/Esiur/Tools/Esiur.psm1 @@ -1,11 +1,11 @@ function Get-Template($url, $dir, $username, $password, $asyncSetters) { - $lib = Resolve-Path -Path "$($PSScriptRoot)\..\lib\netstandard2.0\Esiur.dll" + $lib = Resolve-Path -Path "$($PSScriptRoot)\..\lib\netstandard2.0\Esiur.dll" #write-host "Lib is at $($lib)" $assembly = [Reflection.Assembly]::LoadFile($lib) - $tempPath = [Esiur.Proxy.TemplateGenerator]::GetTemplate($url, $dir, $username,$password, $asyncSetters); + $tempPath = [Esiur.Proxy.TemplateGenerator]::GetTemplate($url, $dir, true, $username,$password, $asyncSetters); $startupProject = GetStartupProject