using System; using System.Collections.Generic; using System.Net; using Shared.SimpleControl; namespace Shared { [System.Serializable] public class RemoteInfo { static RemoteInfo () { Current = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile ("RemoteInfoMsgList"))); if (Current == null) Current = new RemoteInfo (); } /// /// 从服务器读取相应数目的数据 /// public void ReadMsgList (bool needTip) { if (MainPage.LoginUser == null) return; #if HDL new System.Threading.Thread (() => { try { string jsonString = "{" + "\"RegID\":" + "\"" + UserConfig.Instance.tokenID + "\"" + "," + "}"; var revertObj = MainPage.RequestHttps (@"GetMsgList", jsonString, true); if (revertObj.StateCode == "SUCCESS") { var msgList = Newtonsoft.Json.JsonConvert.DeserializeObject> (revertObj.ResponseData.ToString ()); //清楚角标 new WebClient().DownloadData ($"https://global.hdlcontrol.com/HangZhouHdlCloudApi/ZigbeeUsers/CornerClear"); // if (msgList == null || msgList.Count == 0) return; if (msgList.Count == Current.RemoteInfoList.Count && msgList [msgList.Count - 1].MsgTime == Current.RemoteInfoList [Current.RemoteInfoList.Count - 1].MsgTime) return; Current.RemoteInfoList.Clear (); foreach (var msg in msgList) { Current.RemoteInfoList.Add (new RemoteInfoMsg () { Msg = msg.Msg, MsgID = msg.MsgID, MsgTime = msg.MsgTime, MsgType = msg.MsgType }); } Current.Save (); if (msgList.Count > 0) { Application.RunOnMainThread (() => { string tipMsg = Language.StringByID (SimpleControl.R.MyInternationalizationString.NewMessageReceived); if (needTip) { Alert alert = new Alert (Language.StringByID (SimpleControl.R.MyInternationalizationString.Tip), tipMsg, Language.StringByID (SimpleControl.R.MyInternationalizationString.Close), Language.StringByID (SimpleControl.R.MyInternationalizationString.Read)); alert.Show (); alert.ResultEventHandler += (sender, e) => { if (e) { if (Shared.Application.IsPad) { //SimpleControl.Pad.WarningList.ShowWarningListPage (); } else { SimpleControl.Phone.UserMiddle.ShowSettingView (); var msgView = new SimpleControl.Phone.WarningList (); SimpleControl.Phone.UserMiddle.SettingPageView.AddChidren (msgView); msgView.ShowWarningListPage (); SimpleControl.Phone.UserMiddle.SettingPageView.PageIndex = 1; } } }; } else { if (Shared.Application.IsPad) { //SimpleControl.Pad.WarningList.ShowWarningListPage (); } else { SimpleControl.Phone.UserMiddle.ShowSettingView (); var msgView = new SimpleControl.Phone.WarningList (); SimpleControl.Phone.UserMiddle.SettingPageView.AddChidren (msgView); msgView.ShowWarningListPage (); SimpleControl.Phone.UserMiddle.SettingPageView.PageIndex = 1; } } }); } } } catch (Exception ex) { Console.WriteLine (ex.Message); if (MainPage.LoginUser.AccountString == "750183166@qq.com") { Application.RunOnMainThread (() => { var ss = new Alert ("", ex.Message, "Close"); ss.Show (); }); } } finally { //Application.RunOnMainThread (() => { // MainPage.Loading.Hide (); //}); } }) { IsBackground = true}.Start(); #endif } public static RemoteInfo Current { get; private set; } public List RemoteInfoList = new List (); public void Del (RemoteInfoMsg msg) { RemoteInfoList.Remove (msg); Save (); } public void CleanAll () { Current.RemoteInfoList.Clear (); Save (); } public void Save () { var saveBytes = CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (Current)); IO.FileUtils.WriteFileByBytes ("RemoteInfoMsgList", saveBytes); } } [System.Serializable] public class RemoteInfoMsg { public long MsgID; public string Msg; public string MsgType; public DateTime MsgTime; } }