b351d5f521
- update NLog - update nuget
119 lines
3.0 KiB
C#
119 lines
3.0 KiB
C#
using IobConf.Core;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace IobConf.UI.Components
|
|
{
|
|
public partial class IniConverter
|
|
{
|
|
#region Public Methods
|
|
|
|
public void LoadINI()
|
|
{
|
|
checkOutDir();
|
|
if (File.Exists(iniPath))
|
|
{
|
|
fileOk = true;
|
|
rawFileContent = File.ReadAllText(iniPath);
|
|
confINI = getMarkup(rawFileContent);
|
|
CurrentConf = IobConfTree.LoadFromINI(iniPath);
|
|
updateConf();
|
|
}
|
|
else
|
|
{
|
|
fileOk = false;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
protected MarkupString confINI { get; set; }
|
|
protected MarkupString confJson { get; set; }
|
|
protected MarkupString confYaml { get; set; }
|
|
protected IobConfTree CurrentConf { get; set; } = new IobConfTree();
|
|
protected bool fileOk { get; set; } = false;
|
|
|
|
protected string iniPath
|
|
{
|
|
get => _iniPath;
|
|
set
|
|
{
|
|
if (!iniPath.Equals(value))
|
|
{
|
|
_iniPath = value;
|
|
LoadINI();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <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 override async Task OnInitializedAsync()
|
|
{
|
|
LoadINI();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private string _iniPath = @"C:\temp\DATA\CONF\SIMUL_01.ini";
|
|
|
|
private string baseDir = @"c:\temp\IobConf";
|
|
|
|
private string CodIOB = "NewIOB_00";
|
|
|
|
private string rawFileContent = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Methods
|
|
|
|
private void checkOutDir()
|
|
{
|
|
if (!Directory.Exists(baseDir))
|
|
{
|
|
Directory.CreateDirectory(baseDir);
|
|
}
|
|
}
|
|
|
|
private void updateConf()
|
|
{
|
|
// aggiorno conf JSON/YAML
|
|
confJson = getMarkup(CurrentConf.GetJson());
|
|
confYaml = getMarkup(CurrentConf.GetYaml());
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |