using System; using System.IO; using HMI.Core.Entity; using HMI.Core.Util; namespace HMI.Core.Setting { public class SystemSetting { public static SystemSetting Instance { get; private set; } /// /// 系统设置改变事件 /// public static event EventHandler SystemSettingChanged; static SystemSetting() { LoadFromXml(); } private SystemSetting() { } public string LogoPath { get; private set; } public string WindowTitle { get; private set; } public string PlcIp { get; private set; } public bool PlcEnabled { get; private set; } private static void LoadFromXml() { if (Instance != null) return; string XmlFilePath = PathHelper.ConfigFolder + "\\SystemConfig.xml"; if (!File.Exists(XmlFilePath)) { Instance = new SystemSetting(); } else { SystemSettingModel model = XmlHelper.DeserializeFromXml(XmlFilePath); SystemSetting setting = new SystemSetting(); BeanUtil.Copy(model, setting); Instance = setting; } } public static void ReLoad() { string XmlFilePath = PathHelper.ConfigFolder + "\\SystemConfig.xml"; if (!File.Exists(XmlFilePath)) { Instance = new SystemSetting(); } else { SystemSettingModel model = XmlHelper.DeserializeFromXml(XmlFilePath); SystemSetting setting = new SystemSetting(); BeanUtil.Copy(model, setting); Instance = setting; } SystemSettingChanged?.Invoke(null, Instance); } } public class SystemSettingModel : NotifyBase { private string logoPath; public string LogoPath { get => logoPath; set { Set(ref logoPath, value); } } private string windowTitle; public string WindowTitle { get => windowTitle; set { Set(ref windowTitle, value); } } private string plcIp; public string PlcIp { get => plcIp; set { Set(ref plcIp, value); } } private bool plcEnabled; public bool PlcEnabled { get => plcEnabled; set { Set(ref plcEnabled, value); } } } }