From 381251fc8e934a14476a401c54fa944242274b38 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Tue, 13 Aug 2024 00:24:22 +0300 Subject: [PATCH] dotnet-cli --- Esiur.CLI/Esiur.CLI.csproj | 19 +++++ Esiur.CLI/Program.cs | 76 ++++++++++++++++++ .../Esiur.Stores.EntityCore.csproj | 2 +- Esiur.sln | 8 +- Esiur/Data/StringKeyList.cs | 78 +++++-------------- Esiur/Esiur.csproj | 6 +- Esiur/LICENSE | 2 +- 7 files changed, 128 insertions(+), 63 deletions(-) create mode 100644 Esiur.CLI/Esiur.CLI.csproj create mode 100644 Esiur.CLI/Program.cs diff --git a/Esiur.CLI/Esiur.CLI.csproj b/Esiur.CLI/Esiur.CLI.csproj new file mode 100644 index 0000000..9389e91 --- /dev/null +++ b/Esiur.CLI/Esiur.CLI.csproj @@ -0,0 +1,19 @@ + + + + Exe + net8.0 + enable + enable + + true + esiur + ./nupkg + + + + + + + + diff --git a/Esiur.CLI/Program.cs b/Esiur.CLI/Program.cs new file mode 100644 index 0000000..baf6adf --- /dev/null +++ b/Esiur.CLI/Program.cs @@ -0,0 +1,76 @@ + +using Esiur.Data; +using Microsoft.CodeAnalysis; +using System; +using System.Diagnostics; +using System.Reflection; + +static void Main(string[] args) +{ + + if (args.Length > 0) + { + if (args[0].ToLower() == "get-template" && args.Length >= 2) + { + try + { + var url = args[1]; + + var parameters = GetParams(args, 2); + + + var username = args.ElementAtOrDefault(3); + var password = args.ElementAtOrDefault(4); + var asyncSetters = Convert.ToBoolean(args.ElementAtOrDefault(5)); + + var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, + parameters["-d"] ?? parameters["--dir"], + parameters["-u"] ?? parameters["--username"], + parameters["-p"] ?? parameters["--password"], + parameters["-d"] ?? parameters["--dir"] + parameters.Contains ["--a"] ?? parameters["--dir"]); + + Console.WriteLine($"Generated successfully: {path}"); + + return; + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + return; + } + } + } + + PrintHelp(); +} + +static StringKeyList GetParams(string[] args, int offset) +{ + var rt = new StringKeyList(); + for(var i = offset; i< args.Length; i+=2) + { + var v = args.Length >= (i + 1) ? args[i+1] : null; + rt.Add(args[i], v); + } + + return rt; +} + +static void PrintHelp() +{ + var version = FileVersionInfo.GetVersionInfo(typeof(Esiur.Core.AsyncReply).Assembly.Location).FileVersion; + + + Console.WriteLine("Usage: [arguments]"); + Console.WriteLine(""); + Console.WriteLine("Available commands:"); + Console.WriteLine("\tget-template\t\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\tName of the directory to generate model inside."); + +} \ No newline at end of file diff --git a/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj b/Esiur.Stores.EntityCore/Esiur.Stores.EntityCore.csproj index 2213ce8..d772f7a 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.sln b/Esiur.sln index 2fa3f3b..3104510 100644 --- a/Esiur.sln +++ b/Esiur.sln @@ -12,7 +12,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Security.Cryptography", "Esiur.Security.Cryptography\Esiur.Security.Cryptography.csproj", "{C0C55C1A-7C48-41EB-9A65-27BC99D82F6D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.Examples.StandaloneWebServerDemo", "Esiur.Examples.StandaloneWebServerDemo\Esiur.Examples.StandaloneWebServerDemo.csproj", "{A00BBD34-601D-4803-94AE-B807DC75D53A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Esiur.Examples.StandaloneWebServerDemo", "Esiur.Examples.StandaloneWebServerDemo\Esiur.Examples.StandaloneWebServerDemo.csproj", "{A00BBD34-601D-4803-94AE-B807DC75D53A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Esiur.CLI", "Esiur.CLI\Esiur.CLI.csproj", "{5C193127-20D1-4709-90C4-DF714D7E6700}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -44,6 +46,10 @@ Global {A00BBD34-601D-4803-94AE-B807DC75D53A}.Debug|Any CPU.Build.0 = Debug|Any CPU {A00BBD34-601D-4803-94AE-B807DC75D53A}.Release|Any CPU.ActiveCfg = Release|Any CPU {A00BBD34-601D-4803-94AE-B807DC75D53A}.Release|Any CPU.Build.0 = Release|Any CPU + {5C193127-20D1-4709-90C4-DF714D7E6700}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C193127-20D1-4709-90C4-DF714D7E6700}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C193127-20D1-4709-90C4-DF714D7E6700}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C193127-20D1-4709-90C4-DF714D7E6700}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Esiur/Data/StringKeyList.cs b/Esiur/Data/StringKeyList.cs index 6d5f0f1..c6c4db9 100644 --- a/Esiur/Data/StringKeyList.cs +++ b/Esiur/Data/StringKeyList.cs @@ -37,27 +37,24 @@ namespace Esiur.Data; public class StringKeyList : IEnumerable> { - //private List m_keys = new List(); - //private List m_values = new List(); - private List> m_Variables = new List>(); private bool allowMultiple; - public delegate void Modified(string Key, string NewValue); + public delegate void Modified(string key, string newValue); public event Modified OnModified; - public StringKeyList(bool AllowMultipleValues = false) + public StringKeyList(bool allowMultipleValues = false) { - allowMultiple = AllowMultipleValues; + allowMultiple = allowMultipleValues; } - public void Add(string Key, string Value) + public void Add(string key, string value) { if (OnModified != null) - OnModified(Key, Value); + OnModified(key, value); - var key = Key.ToLower(); + key = key.ToLower(); if (!allowMultiple) { @@ -71,14 +68,14 @@ public class StringKeyList : IEnumerable> } } - m_Variables.Add(new KeyValuePair(Key, Value)); + m_Variables.Add(new KeyValuePair(key, value)); } - public string this[string Key] + public string this[string key] { get { - var key = Key.ToLower(); + key = key.ToLower(); foreach (var kv in m_Variables) if (kv.Key.ToLower() == key) return kv.Value; @@ -87,7 +84,7 @@ public class StringKeyList : IEnumerable> } set { - var key = Key.ToLower(); + key = key.ToLower(); var toRemove = m_Variables.Where(x => x.Key.ToLower() == key).ToArray(); @@ -95,16 +92,15 @@ public class StringKeyList : IEnumerable> m_Variables.Remove(item); - m_Variables.Add(new KeyValuePair(Key, value)); + m_Variables.Add(new KeyValuePair(key, value)); - OnModified?.Invoke(Key, value); + OnModified?.Invoke(key, value); } } IEnumerator> IEnumerable>.GetEnumerator() { - //return m_keys.GetEnumerator(); return m_Variables.GetEnumerator(); } @@ -122,26 +118,6 @@ public class StringKeyList : IEnumerable> } - /* - public string[] Keys - { - get - { - return m_keys.ToArray(); - } - } - - - //public Dictionary.ValueCollection Values - public string[] Values - { - get - { - //return m_Variables.Values; - return m_values.ToArray(); - } - } - */ public List GetValues(string Key) { @@ -156,21 +132,21 @@ public class StringKeyList : IEnumerable> return values; } - public void RemoveAll(string Key) + public void RemoveAll(string key) { - while (Remove(Key)) { } + while (Remove(key)) { } } - public bool Remove(string Key) + public bool Remove(string key) { - var key = Key.ToLower(); + key = key.ToLower(); foreach (var kv in m_Variables) { if (kv.Key.ToLower() == key) { if (OnModified != null) - OnModified(Key, null); + OnModified(key, null); m_Variables.Remove(kv); return true; } @@ -184,36 +160,24 @@ public class StringKeyList : IEnumerable> get { return m_Variables.Count; } } - public bool ContainsKey(string Key) + public bool ContainsKey(string key) { - var key = Key.ToLower(); + key = key.ToLower(); foreach (var kv in m_Variables) if (kv.Key.ToLower() == key) return true; return false; } - /* - public bool ContainsKey(string Key) - { - //return m_Variables.ContainsKey(Key); - return m_keys.Contains(Key.ToLower()); - } - */ - public bool ContainsValue(string Value) + public bool ContainsValue(string value) { - var value = Value.ToLower(); + value = value.ToLower(); foreach (var kv in m_Variables) if (kv.Value.ToLower() == value) return true; return false; } - //internal KeyList() - //{ - // m_Session = Session; - // m_Server = Server; - //} } \ No newline at end of file diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 5d2fd79..5c3f370 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -63,7 +63,7 @@ - + @@ -74,10 +74,10 @@ - + - + diff --git a/Esiur/LICENSE b/Esiur/LICENSE index 40ac504..bc48053 100644 --- a/Esiur/LICENSE +++ b/Esiur/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2023 Esiur Foundation, Ahmed Kh. Zamil. +Copyright (c) 2017-2024 Esiur Foundation, Ahmed Kh. Zamil. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal