using System; using System.Text; using HDL_ON.DAL.Server; namespace HDL_ON.DAL.Mqtt { [System.Serializable] public class MqttInfoConfig { public static readonly string ConfigFile = "MqttInfoConfig"; /// /// 接口类的返回信息 /// static MqttInfoConfig m_Current = null; /// /// 接口类的返回信息 /// public static MqttInfoConfig Current { get { if (m_Current == null) { try { var MqttInfoConfigBytes = FileUtils.ReadFile(ConfigFile); var MqttInfoConfigString = Encoding.UTF8.GetString(MqttInfoConfigBytes); MqttInfoConfig temp = null; if (MqttInfoConfigString != null) { temp = Newtonsoft.Json.JsonConvert.DeserializeObject(MqttInfoConfigString); } if (temp == null) { m_Current = new MqttInfoConfig { }; } else { m_Current = temp; } } catch { m_Current = new MqttInfoConfig { }; } } return m_Current; } } public HomeGatewayInfo HomeGatewayInfo = null; public MqttInfo mMqttInfo = null; /// /// 是否获取MQTT参数成功 /// public bool IfGetMqttInfoSuccess = false; byte[] GetMqttInfoConfigBytes() { return Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this)); } public void Refresh() { m_Current = null; Save(); } public void Save() { FileUtils.WriteFileByBytes(ConfigFile, GetMqttInfoConfigBytes()); } } }