161c57ffde
-aggiunta progetto originale (WEB) x conversione CONF
98 lines
2.5 KiB
C#
98 lines
2.5 KiB
C#
using ConfMan.IOB.Core;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace ConfMan.IOB.UI.Components
|
|
{
|
|
public partial class IniConverter
|
|
{
|
|
#region Public Methods
|
|
|
|
public async Task LoadINI()
|
|
{
|
|
checkOutDir();
|
|
await Task.Delay(1);
|
|
rawFileContent = File.ReadAllText(iniPath);
|
|
confINI=getMarkup(rawFileContent);
|
|
CurrentConf = IobConfTree.LoadFromINI(iniPath);
|
|
updateConf();
|
|
}
|
|
public async Task SaveJson()
|
|
{
|
|
checkOutDir();
|
|
await Task.Delay(1);
|
|
string fileName = Path.Combine(baseDir, $"Conf.json");
|
|
CurrentConf.SaveJson(fileName);
|
|
}
|
|
|
|
public async Task SaveYaml()
|
|
{
|
|
checkOutDir();
|
|
await Task.Delay(1);
|
|
string fileName = Path.Combine(baseDir, $"Conf.yml");
|
|
CurrentConf.SaveYaml(fileName);
|
|
}
|
|
|
|
private void updateConf()
|
|
{
|
|
// aggiorno conf JSON/YAML
|
|
confJson = getMarkup(CurrentConf.GetJson());
|
|
confYaml = getMarkup(CurrentConf.GetYaml());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converte la stringa in formato markup valido
|
|
/// </summary>
|
|
/// <param name="rawData"></param>
|
|
/// <returns></returns>
|
|
protected MarkupString getMarkup(string rawData)
|
|
{
|
|
return new MarkupString(rawData.Replace("\n", "<br/>").Replace(" ", " "));
|
|
}
|
|
|
|
protected string iniPath = @"C:\temp\DATA\CONF\SIMUL_01.ini";
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected string baseDir = @"c:\temp\IobConf";
|
|
|
|
protected string CodIOB = "NewIOB_00";
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected MarkupString confINI { get; set; }
|
|
protected MarkupString confJson { get; set; }
|
|
|
|
protected MarkupString confYaml { get; set; }
|
|
|
|
protected string rawFileContent = "";
|
|
|
|
protected IobConfTree CurrentConf { get; set; } = new IobConfTree();
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadINI();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
private void checkOutDir()
|
|
{
|
|
if (!Directory.Exists(baseDir))
|
|
{
|
|
Directory.CreateDirectory(baseDir);
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |