ConfMan.IOB:
- aggiunto conf YAML x default
This commit is contained in:
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Deserializza dato filePath
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
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<CAConf>(input);
|
||||
}
|
||||
return retObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,23 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DebugType>full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Spectre.Console" Version="0.45.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="12.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="conf.yaml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+22
-18
@@ -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<string>("Inserisci il type desiderato:");
|
||||
AnsiConsole.WriteLine(fileType);
|
||||
currConf.FileType = AnsiConsole.Ask<string>("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<string>("Inserisci il percorso completo:");
|
||||
if (!string.IsNullOrEmpty(sPath))
|
||||
currConf.ConfDir = AnsiConsole.Ask<string>("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<string>("Inserisci valore per [yellow]Customer[/]:","SteamWare");
|
||||
var HostOS = AnsiConsole.Ask<string>("Inserisci valore per [yellow]OS[/]:","WIN");
|
||||
var custName = AnsiConsole.Ask<string>("Inserisci valore per [yellow]Customer[/]:", currConf.Customer);
|
||||
var HostOS = AnsiConsole.Ask<string>("Inserisci valore per [yellow]OS[/]:", currConf.OS);
|
||||
var HostName = AnsiConsole.Ask<string>("Inserisci valore per [yellow]HostName[/]:", hostName);
|
||||
var HostAddr = AnsiConsole.Ask<string>("Inserisci valore per [yellow]HostAddress (IP)[/]:", hostAddr);
|
||||
// salvo i tagList...
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
ConfDir: C:\Steamware\IOB-WIN-NEXT\DATA\CONF
|
||||
Customer: Steamware
|
||||
FileType: .ini
|
||||
OS: WIN
|
||||
Reference in New Issue
Block a user