mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-30 23:51:34 +00:00 
			
		
		
		
	CLI
This commit is contained in:
		| @@ -8,48 +8,48 @@ using System.Diagnostics; | |||||||
| using System.IO; | using System.IO; | ||||||
| using System.Reflection; | using System.Reflection; | ||||||
|  |  | ||||||
| static void Main(string[] args) |  | ||||||
|  | if (args.Length > 0) | ||||||
| { | { | ||||||
|  |     if (args[0].ToLower() == "get-template" && args.Length >= 2) | ||||||
|     if (args.Length > 0) |  | ||||||
|     { |     { | ||||||
|         if (args[0].ToLower() == "get-template" && args.Length >= 2) |         try | ||||||
|         { |         { | ||||||
|             try |             var url = args[1]; | ||||||
|             { |  | ||||||
|                 var url = args[1]; |  | ||||||
|  |  | ||||||
|                 Parser.Default.ParseArguments<GetTemplateOptions>(args.Skip(2)) |             Parser.Default.ParseArguments<GetTemplateOptions>(args.Skip(2)) | ||||||
|                                    .WithParsed<GetTemplateOptions>(o => |                                .WithParsed<GetTemplateOptions>(o => | ||||||
|  |                                 { | ||||||
|  |                                     try | ||||||
|                                     { |                                     { | ||||||
|                                         try |                                         var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, o.Dir, false, o.Username, o.Password, o.AsyncSetters); | ||||||
|                                         { |                                         Console.WriteLine($"Generated successfully: {path}"); | ||||||
|                                             var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, o.Dir, o.Username, o.Password, o.AsyncSetters); |                                     } | ||||||
|                                             Console.WriteLine($"Generated successfully: {path}"); |                                     catch (Exception ex) | ||||||
|                                         } |                                     { | ||||||
|                                         catch (Exception ex) {  |                                         Console.WriteLine(ex.ToString()); | ||||||
|                                             Console.WriteLine(ex.ToString()); |                                     } | ||||||
|                                         } |                                 }); | ||||||
|                                     }); |             return; | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|             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(ex.ToString()); | ||||||
|  |             return; | ||||||
|             Console.WriteLine(version); |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |     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() | static void PrintHelp() | ||||||
| { | { | ||||||
|     var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion; |     var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion; | ||||||
| @@ -58,13 +58,13 @@ static void PrintHelp() | |||||||
|     Console.WriteLine("Usage: <command> [arguments]"); |     Console.WriteLine("Usage: <command> [arguments]"); | ||||||
|     Console.WriteLine(""); |     Console.WriteLine(""); | ||||||
|     Console.WriteLine("Available commands:"); |     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("\tversion\t\tPrint Esiur version."); | ||||||
|     Console.WriteLine(""); |     Console.WriteLine(""); | ||||||
|     Console.WriteLine("Global options:"); |     Console.WriteLine("Global options:"); | ||||||
|     Console.WriteLine("\t-u, --username\tAuthentication username."); |     Console.WriteLine("\t-u, --username\t\tAuthentication username."); | ||||||
|     Console.WriteLine("\t-p, --password\tAuthentication password."); |     Console.WriteLine("\t-p, --password\t\tAuthentication password."); | ||||||
|     Console.WriteLine("\t-d, --dir\tDirectory name where the generated models will be saved."); |     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."); |     Console.WriteLine("\t-a, --async-setters\tUse asynchronous property setters."); | ||||||
|  |  | ||||||
| } | } | ||||||
							
								
								
									
										8
									
								
								Esiur.CLI/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								Esiur.CLI/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | { | ||||||
|  |   "profiles": { | ||||||
|  |     "Esiur.CLI": { | ||||||
|  |       "commandName": "Project", | ||||||
|  |       "commandLineArgs": "get-template iip://phase.delta.iq/sys/phase -d c:\\temp\\a" | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -8,8 +8,8 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Esiur" Version="2.4.0" /> |     <PackageReference Include="Esiur" Version="2.4.5" /> | ||||||
|     <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" /> |     <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|   | |||||||
| @@ -40,7 +40,7 @@ internal class Program | |||||||
|             } |             } | ||||||
|             else |             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.Send("`" + fn + "` Not Found"); | ||||||
|                 sender.Close(); |                 sender.Close(); | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" /> |     <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" /> | ||||||
|     <PackageReference Include="System.Collections" Version="4.3.0" /> |     <PackageReference Include="System.Collections" Version="4.3.0" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,8 +17,8 @@ | |||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="MongoDB.Bson" Version="2.24.0" /> |     <PackageReference Include="MongoDB.Bson" Version="2.29.0" /> | ||||||
|     <PackageReference Include="MongoDB.Driver" Version="2.24.0" /> |     <PackageReference Include="MongoDB.Driver" Version="2.29.0" /> | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ | |||||||
|     <Copyright>Ahmed Kh. Zamil</Copyright> |     <Copyright>Ahmed Kh. Zamil</Copyright> | ||||||
|      <PackageProjectUrl>http://www.esiur.com</PackageProjectUrl> |      <PackageProjectUrl>http://www.esiur.com</PackageProjectUrl> | ||||||
|     <GeneratePackageOnBuild>true</GeneratePackageOnBuild> |     <GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||||||
|     <Version>2.4.4</Version> |     <Version>2.4.5</Version> | ||||||
|     <RepositoryUrl>https://github.com/esiur/esiur-dotnet</RepositoryUrl> |     <RepositoryUrl>https://github.com/esiur/esiur-dotnet</RepositoryUrl> | ||||||
|     <Authors>Ahmed Kh. Zamil</Authors> |     <Authors>Ahmed Kh. Zamil</Authors> | ||||||
|     <AssemblyVersion></AssemblyVersion> |     <AssemblyVersion></AssemblyVersion> | ||||||
| @@ -63,7 +63,7 @@ | |||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   <ItemGroup> |   <ItemGroup> | ||||||
|     <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.10.0" /> |     <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.11.0" /> | ||||||
|     <PackageReference Include="System.Collections" Version="4.3.0" /> |     <PackageReference Include="System.Collections" Version="4.3.0" /> | ||||||
|     <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> |     <PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> | ||||||
|     <PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" /> |     <PackageReference Include="System.Diagnostics.StackTrace" Version="4.3.0" /> | ||||||
| @@ -74,11 +74,11 @@ | |||||||
|     <PackageReference Include="System.Net.Security" Version="4.3.2" /> |     <PackageReference Include="System.Net.Security" Version="4.3.2" /> | ||||||
|     <PackageReference Include="System.Reflection.Emit" Version="4.7.0" /> |     <PackageReference Include="System.Reflection.Emit" Version="4.7.0" /> | ||||||
|     <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" /> |     <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" /> | ||||||
|     <PackageReference Include="System.Text.Json" Version="8.0.4" GeneratePathProperty="true" /> |     <PackageReference Include="System.Text.Json" Version="8.0.5" GeneratePathProperty="true" /> | ||||||
|     <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" /> |     <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" /> | ||||||
|  |  | ||||||
|     <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" PrivateAssets="all" /> |     <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" /> | ||||||
|     <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" /> |     <PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" PrivateAssets="all" /> | ||||||
|  |  | ||||||
|   </ItemGroup> |   </ItemGroup> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -177,7 +177,7 @@ public static class TemplateGenerator | |||||||
|         return (representationType.Nullable) ? name + "?" : name; |         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 |         try | ||||||
|         { |         { | ||||||
| @@ -200,14 +200,14 @@ public static class TemplateGenerator | |||||||
|             // no longer needed |             // no longer needed | ||||||
|             Warehouse.Remove(con); |             Warehouse.Remove(con); | ||||||
|  |  | ||||||
|             var tempDir = new DirectoryInfo(Path.GetTempPath() + Path.DirectorySeparatorChar |             var dstDir = new DirectoryInfo(tempDir ? Path.GetTempPath() + Path.DirectorySeparatorChar | ||||||
|                             + Misc.Global.GenerateCode(20) + Path.DirectorySeparatorChar + dir); |                             + Misc.Global.GenerateCode(20) + Path.DirectorySeparatorChar + dir : dir); | ||||||
|  |  | ||||||
|             if (!tempDir.Exists) |             if (!dstDir.Exists) | ||||||
|                 tempDir.Create(); |                 dstDir.Create(); | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 foreach (FileInfo file in tempDir.GetFiles()) |                 foreach (FileInfo file in dstDir.GetFiles()) | ||||||
|                     file.Delete(); |                     file.Delete(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -217,17 +217,17 @@ public static class TemplateGenerator | |||||||
|                 if (tmp.Type == TemplateType.Resource) |                 if (tmp.Type == TemplateType.Resource) | ||||||
|                 { |                 { | ||||||
|                     var source = GenerateClass(tmp, templates, asyncSetters); |                     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) |                 else if (tmp.Type == TemplateType.Record) | ||||||
|                 { |                 { | ||||||
|                     var source = GenerateRecord(tmp, templates); |                     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) |                 else if (tmp.Type == TemplateType.Enum) | ||||||
|                 { |                 { | ||||||
|                     var source = GenerateEnum(tmp, templates); |                     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}"; |                 "\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) |         catch (Exception ex) | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ | |||||||
|    #write-host "Lib is at $($lib)" |    #write-host "Lib is at $($lib)" | ||||||
|  |  | ||||||
|    $assembly =  [Reflection.Assembly]::LoadFile($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 |   $startupProject = GetStartupProject | ||||||
|    |    | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user