// See https://aka.ms/new-console-template for more information using ConfMan.IOB.CApp; using Spectre.Console; using System.Diagnostics; using System.Net; AnsiConsole.Write( new FigletText("ConfMan.IOB") .LeftAligned() .Color(Color.Blue1)); var rule = new Rule("[green]IOB configuration file manager[/]"); rule.Alignment = Justify.Left; AnsiConsole.Write(rule); AnsiConsole.WriteLine(); var fileType = ".ini"; AnsiConsole.MarkupLineInterpolated($"Conf file type: [yellow]{fileType}[/]"); var typeOk = AnsiConsole.Confirm("Confermi tipo file?"); while (!typeOk) { fileType = AnsiConsole.Ask("Inserisci il type desiderato:"); AnsiConsole.WriteLine(fileType); typeOk = AnsiConsole.Confirm("Confermi tipo file?"); } // aggiungo "*" se mancasse... if (fileType.Substring(0, 1) != "*") { fileType = $"*{fileType}"; } AnsiConsole.MarkupLineInterpolated($"Confermato file type: [green]{fileType}[/]"); //var path = new TextPath(@"C:\Steamware\IOB-WIN-NEXT\DATA\CONF"); string sPath = @"C:\temp\DATA\CONF"; var path = new TextPath(sPath); AnsiConsole.WriteLine($"Default conf path:"); AnsiConsole.Write(path); //AnsiConsole.WriteLine(); var fileList = Directory.GetFiles(sPath, 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)) { path = new TextPath(sPath); AnsiConsole.Write(path); // verifico esista la directory... if (!Directory.Exists(sPath)) { AnsiConsole.MarkupLine("Attenzione: path inserito [red]non[/] valido!"); } else { // recupero il numero di file ini cercati fileList = Directory.GetFiles(sPath, fileType); AnsiConsole.MarkupLineInterpolated($"Trovati [yellow]{fileList.Count()}[/] file..."); pathOK = AnsiConsole.Confirm("Confermi il Path?"); } } } rule = new Rule("[green]TAGS[/] selection"); rule.Alignment = Justify.Left; AnsiConsole.Write(rule); string hostName = Dns.GetHostName(); var hostAddress = Dns.GetHostAddresses(hostName); string hostAddr = ""; if (hostAddress != null) { if (hostAddress.Count() > 1) { var ipList = hostAddress.Select(x => $"{x}").ToList(); hostAddr = AnsiConsole.Prompt( new SelectionPrompt() .Title("Selezione indirizzo [green]IP[/]") .MoreChoicesText("[grey](Move up and down to reveal more)[/]") .AddChoices(ipList)); } else { hostAddr = $"{hostAddress[0]}"; } } var custName = AnsiConsole.Ask("Inserisci valore per [yellow]Customer[/]:","SteamWare"); var HostOS = AnsiConsole.Ask("Inserisci valore per [yellow]OS[/]:","WIN"); var HostName = AnsiConsole.Ask("Inserisci valore per [yellow]HostName[/]:", hostName); var HostAddr = AnsiConsole.Ask("Inserisci valore per [yellow]HostAddress (IP)[/]:", hostAddr); // salvo i tagList... Dictionary newTags = new Dictionary(); newTags.Add("Customer", custName); newTags.Add("HostOS", HostOS); newTags.Add("HostName", HostName); newTags.Add("HostAddr", HostAddr); AnsiConsole.WriteLine(); // ora processa tutti i file, andando ad aggiungere in coda i TAGS selezionati... Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var confFile in fileList) { TagManager tMan = new TagManager(confFile); tMan.addTagList(newTags); } sw.Stop(); var elTime = sw.Elapsed; rule = new Rule("File update [green]Completed[/]!"); rule.Alignment = Justify.Left; AnsiConsole.Write(rule); AnsiConsole.MarkupLineInterpolated($"Processati [yellow]{fileList.Count()}[/] file in {elTime.TotalMilliseconds}ms");