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()); } /// /// Converte la stringa in formato markup valido /// /// /// protected MarkupString getMarkup(string rawData) { return new MarkupString(rawData.Replace("\n", "
").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 } }