using System; using HardwareMonitorStatusWindow.Service; using PipeMethodCalls; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text.Json; using System.Threading.Tasks; namespace HardwareMonitorStatusWindow.StatusWindow; internal static class Data { private static PipeClient _pipeClient; private static IEnumerable _hardware; internal static ObservableCollection SensorEntries { get; set; } internal static async Task LoadComputer() { try { _pipeClient = new PipeClient(new HardwarePipeSerializer(), HardwareMonitorService.PipeName); await _pipeClient.ConnectAsync(); } catch (Exception exception) { } } internal static void RefreshComputer() { _hardware = _pipeClient.InvokeAsync(service => service.GetHardware()).Result; } internal static void CloseComputer() { _pipeClient.Dispose(); } internal static IList ComputerHardware => _hardware.ToList(); internal static void Load() { SensorEntries = JsonSerializer.Deserialize>(Settings.Default.Sensors); } internal static void Save() { Settings.Default.Sensors = JsonSerializer.Serialize(SensorEntries); Settings.Default.Save(); } }