New file |
| | |
| | | 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"; |
| | | |
| | | /// <summary> |
| | | /// 接口类的返回信息 |
| | | /// </summary> |
| | | static MqttInfoConfig m_Current = null; |
| | | /// <summary> |
| | | /// 接口类的返回信息 |
| | | /// </summary> |
| | | 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<MqttInfoConfig>(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; |
| | | |
| | | /// <summary> |
| | | /// 是否获取MQTT参数成功 |
| | | /// </summary> |
| | | 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()); |
| | | } |
| | | } |
| | | } |