From f265d747302cbacbe65cd5de5af4f40cf45af178 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Wed, 28 Dec 2022 15:45:32 +0100 Subject: [PATCH] ConfMan.IOB: - aggiunto conf YAML x default --- ConfMan.IOB.CApp/CAConf.cs | 50 ++++++++++++++++++++++++ ConfMan.IOB.CApp/ConfMan.IOB.CApp.csproj | 15 +++++++ ConfMan.IOB.CApp/Program.cs | 40 ++++++++++--------- ConfMan.IOB.CApp/conf.yaml | 4 ++ 4 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 ConfMan.IOB.CApp/CAConf.cs create mode 100644 ConfMan.IOB.CApp/conf.yaml diff --git a/ConfMan.IOB.CApp/CAConf.cs b/ConfMan.IOB.CApp/CAConf.cs new file mode 100644 index 0000000..bd82e65 --- /dev/null +++ b/ConfMan.IOB.CApp/CAConf.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using YamlDotNet.Serialization.NamingConventions; +using YamlDotNet.Serialization; +using System.Reflection.Metadata; + +namespace ConfMan.IOB.CApp +{ + public class CAConf + { + public string ConfDir { get; set; } = ""; + public string Customer { get; set; } = ""; + public string FileType { get; set; } = ""; + public string OS { get; set; } = ""; + + public CAConf() + { + this.FileType = ".ini"; + this.ConfDir = @"C:\Steamware\IOB-WIN-NEXT\DATA\CONF"; + this.Customer = "ACME"; + this.OS = "WIN"; + } + } + public class CMan + { + /// + /// Deserializza dato filePath + /// + /// + public static CAConf readConf(string filePath) + { + CAConf retObj = new CAConf(); + if (File.Exists(filePath)) + { + var deserializer = new DeserializerBuilder() + .WithNamingConvention(new PascalCaseNamingConvention()) + .Build(); + string rawData = File.ReadAllText(filePath); + + var input = new StringReader(rawData); + retObj = deserializer.Deserialize(input); + } + return retObj; + } + } +} diff --git a/ConfMan.IOB.CApp/ConfMan.IOB.CApp.csproj b/ConfMan.IOB.CApp/ConfMan.IOB.CApp.csproj index be160a5..9ab638f 100644 --- a/ConfMan.IOB.CApp/ConfMan.IOB.CApp.csproj +++ b/ConfMan.IOB.CApp/ConfMan.IOB.CApp.csproj @@ -7,8 +7,23 @@ enable + + full + + + + full + + + + + + + + Always + diff --git a/ConfMan.IOB.CApp/Program.cs b/ConfMan.IOB.CApp/Program.cs index 5778ee8..86ef61e 100644 --- a/ConfMan.IOB.CApp/Program.cs +++ b/ConfMan.IOB.CApp/Program.cs @@ -3,6 +3,7 @@ using ConfMan.IOB.CApp; using Spectre.Console; using System.Diagnostics; using System.Net; +using static System.Net.Mime.MediaTypeNames; AnsiConsole.Write( new FigletText("ConfMan.IOB") @@ -12,50 +13,53 @@ var rule = new Rule("[green]IOB configuration file manager[/]"); rule.Alignment = Justify.Left; AnsiConsole.Write(rule); +// recupero configurazione... +CAConf currConf = new CAConf(); +if (File.Exists("conf.yaml")) +{ + currConf = CMan.readConf("conf.yaml"); +} AnsiConsole.WriteLine(); -var fileType = ".ini"; -AnsiConsole.MarkupLineInterpolated($"Conf file type: [yellow]{fileType}[/]"); +AnsiConsole.MarkupLineInterpolated($"Conf file type: [yellow]{currConf.FileType}[/]"); var typeOk = AnsiConsole.Confirm("Confermi tipo file?"); while (!typeOk) { - fileType = AnsiConsole.Ask("Inserisci il type desiderato:"); - AnsiConsole.WriteLine(fileType); + currConf.FileType = AnsiConsole.Ask("Inserisci il type desiderato:"); + AnsiConsole.WriteLine(currConf.FileType); typeOk = AnsiConsole.Confirm("Confermi tipo file?"); } // aggiungo "*" se mancasse... -if (fileType.Substring(0, 1) != "*") +if (currConf.FileType.Substring(0, 1) != "*") { - fileType = $"*{fileType}"; + currConf.FileType = $"*{currConf.FileType}"; } -AnsiConsole.MarkupLineInterpolated($"Confermato file type: [green]{fileType}[/]"); +AnsiConsole.MarkupLineInterpolated($"Confermato file type: [green]{currConf.FileType}[/]"); -//var path = new TextPath(@"C:\Steamware\IOB-WIN-NEXT\DATA\CONF"); -string sPath = @"C:\temp\DATA\CONF"; -var path = new TextPath(sPath); +var path = new TextPath(currConf.ConfDir); AnsiConsole.WriteLine($"Default conf path:"); AnsiConsole.Write(path); //AnsiConsole.WriteLine(); -var fileList = Directory.GetFiles(sPath, fileType); +var fileList = Directory.GetFiles(currConf.ConfDir, currConf.FileType); AnsiConsole.MarkupLineInterpolated($"Trovati [yellow]{fileList.Count()}[/] file..."); var pathOK = AnsiConsole.Confirm("Confermi il Path?"); while (!pathOK) { - sPath = AnsiConsole.Ask("Inserisci il percorso completo:"); - if (!string.IsNullOrEmpty(sPath)) + currConf.ConfDir = AnsiConsole.Ask("Inserisci il percorso completo:"); + if (!string.IsNullOrEmpty(currConf.ConfDir)) { - path = new TextPath(sPath); + path = new TextPath(currConf.ConfDir); AnsiConsole.Write(path); // verifico esista la directory... - if (!Directory.Exists(sPath)) + if (!Directory.Exists(currConf.ConfDir)) { AnsiConsole.MarkupLine("Attenzione: path inserito [red]non[/] valido!"); } else { // recupero il numero di file ini cercati - fileList = Directory.GetFiles(sPath, fileType); + fileList = Directory.GetFiles(currConf.ConfDir, currConf.FileType); AnsiConsole.MarkupLineInterpolated($"Trovati [yellow]{fileList.Count()}[/] file..."); pathOK = AnsiConsole.Confirm("Confermi il Path?"); } @@ -84,8 +88,8 @@ if (hostAddress != null) hostAddr = $"{hostAddress[0]}"; } } -var custName = AnsiConsole.Ask("Inserisci valore per [yellow]Customer[/]:","SteamWare"); -var HostOS = AnsiConsole.Ask("Inserisci valore per [yellow]OS[/]:","WIN"); +var custName = AnsiConsole.Ask("Inserisci valore per [yellow]Customer[/]:", currConf.Customer); +var HostOS = AnsiConsole.Ask("Inserisci valore per [yellow]OS[/]:", currConf.OS); var HostName = AnsiConsole.Ask("Inserisci valore per [yellow]HostName[/]:", hostName); var HostAddr = AnsiConsole.Ask("Inserisci valore per [yellow]HostAddress (IP)[/]:", hostAddr); // salvo i tagList... diff --git a/ConfMan.IOB.CApp/conf.yaml b/ConfMan.IOB.CApp/conf.yaml new file mode 100644 index 0000000..0cfa3d7 --- /dev/null +++ b/ConfMan.IOB.CApp/conf.yaml @@ -0,0 +1,4 @@ +ConfDir: C:\Steamware\IOB-WIN-NEXT\DATA\CONF +Customer: Steamware +FileType: .ini +OS: WIN \ No newline at end of file