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