using Microsoft.AspNetCore.Components; using MP.MONO.Core; using MP.MONO.UI.Data; using Newtonsoft.Json; namespace MP.MONO.UI.Pages { public partial class Info { #region Public Methods public async Task flushCache() { await Task.Delay(1); await MDService.FlushRedisCache(); // rimando a home NavManager.NavigateTo("", true); } #endregion Public Methods #region Protected Properties [Inject] protected CurrentDataService MDService { get; set; } = null!; #endregion Protected Properties #region Protected Methods protected override async Task OnInitializedAsync() { // validatore var mDV = new MachineDataValidator(); // dati macchina biosInfo = MachineDataValidator.biosInfo; cpuInfo = MachineDataValidator.cpuInfo; netInfo = MachineDataValidator.netInfo; osInfo = MachineDataValidator.osInfo; ramInfo = MachineDataValidator.ramInfo; volInfo = MachineDataValidator.volInfo; // check licenze licOk = await MachineDataValidator.testCurrInfo(); } #endregion Protected Methods #region Private Fields private string baseDir = $"{Directory.GetCurrentDirectory()}"; private Dictionary biosInfo = new Dictionary(); private Dictionary cpuInfo = new Dictionary(); private bool licOk = false; private Dictionary netInfo = new Dictionary(); private Dictionary osInfo = new Dictionary(); private Dictionary ramInfo = new Dictionary(); private Dictionary volInfo = new Dictionary(); private bool showBios = false; private bool showCpu = false; private bool showKeyMan = false; private bool showNet = false; private bool showOs = false; private bool showRam = false; private bool showVol = false; #endregion Private Fields #region Private Properties private string fileName { get; set; } = "InfoData.json"; private string licVal { get; set; } = ""; #endregion Private Properties #region Private Methods private void saveInfoData() { var fullData = biosInfo.Concat(cpuInfo).Concat(netInfo).Concat(osInfo).Concat(ramInfo).GroupBy(ele => ele.Key).OrderBy(x => x.Key).ToDictionary(ele => ele.Key, ele => ele.First().Value); string filePath = Path.Combine(baseDir, "temp", "InfoData.json"); File.WriteAllText(filePath, JsonConvert.SerializeObject(fullData, Formatting.Indented)); } private async Task SaveLic() { //se ho un valore x la licenza... if (!string.IsNullOrEmpty(licVal)) { string filePath = Path.Combine(baseDir, "Conf", "lic.file"); File.WriteAllText(filePath, licVal); } // check licenze licOk = await MachineDataValidator.testCurrInfo(); // se ok --> rivado ad home! if (licOk) { await Task.Delay(1); // rimando alla home NavManager.NavigateTo("/", true); } } private void ShowAll() { showBios = true; showCpu = true; showNet = true; showOs = true; showRam = true; showVol = true; } private void ToggleKeyMan() { showKeyMan = !showKeyMan; // salvo su disco... saveInfoData(); } #endregion Private Methods } }