From 22fcd0d263770c8371bd03ca53f097a6ec1678f7 Mon Sep 17 00:00:00 2001 From: wei <kaede@kaededeMacBook-Air.local> Date: 星期四, 24 十二月 2020 12:06:26 +0800 Subject: [PATCH] 20201224-2 --- HDL_ON/Common/ApiUtlis.cs | 168 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 132 insertions(+), 36 deletions(-) diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs index c564f63..8b144ce 100644 --- a/HDL_ON/Common/ApiUtlis.cs +++ b/HDL_ON/Common/ApiUtlis.cs @@ -19,7 +19,7 @@ { get { - if(apiUtlis == null) + if (apiUtlis == null) { apiUtlis = new ApiUtlis(); } @@ -33,7 +33,7 @@ { get { - if(httpRequest == null) + if (httpRequest == null) { httpRequest = new HttpServerRequest(); } @@ -47,7 +47,7 @@ { bool result = DB_ResidenceData.Instance.HomeGateway.gatewayStatus; - if(!result) + if (!result) { } @@ -55,7 +55,7 @@ return result; } - public bool DownloadDataComplete = false; + public bool DownloadDataComplete = true; /// <summary> /// 涓嬭浇鏁版嵁 /// </summary> @@ -63,23 +63,30 @@ { if (MainPage.InternetStatus == 0) return; + //绾跨▼寮�濮嬫椂闂� + var endTime = DateTime.Now.AddSeconds(5); + + MainPage.Log($"寮�濮嬪悓姝ヤ簯绔暟鎹�"); DownloadDataComplete = false; var waitPage = new Loading(); MainPage.BaseView.AddChidren(waitPage); - waitPage.Start(); + waitPage.Start(Language.StringByID(StringId.PleaseWait)); string code = StateCode.SUCCESS; - new System.Threading.Thread(() => { + var downloadDataThread = new System.Threading.Thread(() => + { + MainPage.Log($"杩涘叆璇诲彇浜戠鏁版嵁绾跨▼"); //===================鍒锋柊Token======================= code = Ins.HttpRequest.RefreshToken(); - if(code != StateCode.SUCCESS) + if (code != StateCode.SUCCESS) { MainPage.Log($"鍒锋柊token澶辫触"); return; } + endTime = DateTime.Now.AddSeconds(5); MainPage.Log($"鍒锋柊token鎴愬姛"); //===================鍒锋柊浣忓畢淇℃伅======================= code = Ins.HttpRequest.GetHomePager(); @@ -88,6 +95,7 @@ MainPage.Log($"鍒锋柊浣忓畢淇℃伅澶辫触"); return; } + endTime = DateTime.Now.AddSeconds(5); MainPage.Log($"鍒锋柊浣忓畢淇℃伅鎴愬姛"); //===================鍒锋柊涓汉淇℃伅======================= code = Ins.HttpRequest.GetUserInfo(); @@ -96,25 +104,26 @@ MainPage.Log($"鍒锋柊涓汉淇℃伅澶辫触"); return; } + endTime = DateTime.Now.AddSeconds(5); MainPage.Log($"鍒锋柊涓汉淇℃伅鎴愬姛"); - int count = 0; - while (count < 10) - { - if (DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) - { - System.Threading.Thread.Sleep(200); - } - else - { - break; - } - count++; - } - if (DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) - { - return; - } + //int count = 0; + //while (count < 10) + //{ + // if (DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) + // { + // System.Threading.Thread.Sleep(200); + // } + // else + // { + // break; + // } + // count++; + //} + //if (DB_ResidenceData.Instance.CheckWhetherGatewayIdIsNull()) + //{ + // return; + //} try @@ -123,12 +132,17 @@ var roomResult = Ins.HttpRequest.GetRoomList(); if (roomResult.Code == StateCode.SUCCESS) { + endTime = DateTime.Now.AddSeconds(100); MainPage.Log($"璇诲彇鎴块棿淇℃伅鎴愬姛"); var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(roomResult.Data.ToString()); - if (revData != null) + if (revData == null) { - SpatialInfo.CurrentSpatial.UpdateSpatialList(revData.list, OptionType.Cover); + revData = new SpatialApiPack(); } + { + SpatialInfo.CurrentSpatial.UpdateSpatialList(revData.list); + } + endTime = DateTime.Now.AddSeconds(5); } else { @@ -138,9 +152,13 @@ var deviceResult = Ins.HttpRequest.GetDeviceList(); if (deviceResult.Code == StateCode.SUCCESS) { + endTime = DateTime.Now.AddSeconds(100); MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); - if (deviceList != null) + if (deviceList == null) + { + deviceList = new DevcieApiPack(); + } { if (FunctionList.List.GetDeviceFunctionList().Count > 0) { @@ -163,12 +181,13 @@ i++; if (localFunction.modifyTime != newFunction.modifyTime) { + //鍙紭鍖� localFunction.name = newFunction.name; localFunction.collect = newFunction.collect; localFunction.modifyTime = newFunction.modifyTime; localFunction.roomIds = newFunction.roomIds; localFunction.bus = newFunction.bus; - localFunction.SaveFunctionData(false); + localFunction.SaveFunctionFile(); } deviceList.list.Remove(newFunction);//鎿嶄綔瀹岀殑鏁版嵁娓呯悊鎺夛紝鍓╀笅鐨勫氨鏄柊澧炵殑鍔熻兘 } @@ -177,10 +196,11 @@ //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� foreach (var newFunction in deviceList.list) { - newFunction.SaveFunctionData(false); + newFunction.SaveFunctionFile(); FunctionList.List.IniFunctionList(newFunction.savePath); } } + endTime = DateTime.Now.AddSeconds(5); } else { @@ -191,10 +211,12 @@ var pack = Ins.HttpRequest.GetSceneList(); if (pack.Code == StateCode.SUCCESS) { - MainPage.Log($"璇诲彇鍦烘櫙鏁版嵁鎴愬姛");//:\r\n{pack.Data.ToString()}"); + endTime = DateTime.Now.AddSeconds(100); + MainPage.Log($"璇诲彇鍦烘櫙鏁版嵁鎴愬姛"); var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString()); - if (sceneList != null) + if (sceneList == null) { + sceneList = new List<Scene>(); for (int i = 0; i < FunctionList.List.scenes.Count;) { var localScene = FunctionList.List.scenes[i]; @@ -217,7 +239,7 @@ localScene.collect = newScene.collect; localScene.modifyTime = newScene.modifyTime; localScene.roomIds = newScene.roomIds; - localScene.SaveSceneData(false); + localScene.SaveSceneFile(); } sceneList.Remove(newScene);//鎿嶄綔瀹岀殑鏁版嵁娓呯悊鎺夛紝鍓╀笅鐨勫氨鏄柊澧炵殑鍔熻兘 } @@ -225,10 +247,38 @@ //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� foreach (var newScene in sceneList) { - newScene.SaveSceneData(false); + newScene.SaveSceneFile(); FunctionList.List.scenes.Add(newScene); } } + //濡傛灉鏄竴绔彛闇�瑕佹彁鍓嶄笅杞藉満鏅暟鎹紝鍚﹀垯鎺у埗涓嶄簡涓�绔彛鍦烘櫙 + if (DB_ResidenceData.Instance.GatewayType == 0) + { + var sceneIds = new List<string>(); + foreach (var tempScene in FunctionList.List.scenes) + { + sceneIds.Add(tempScene.userSceneId); + } + var packInfo = HttpRequest.GetSceneListInfo(sceneIds); + if (packInfo.Code == StateCode.SUCCESS) + { + var serverTempList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(packInfo.Data.ToString()); + foreach (var localScene in FunctionList.List.scenes) + { + var serverTemp = serverTempList.Find((obj) => obj.userSceneId == localScene.userSceneId); + if (serverTemp != null) + { + localScene.functions = serverTemp.functions; + localScene.SaveSceneFile(); + } + } + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(packInfo.Code); + } + } + endTime = DateTime.Now.AddSeconds(5); } else { @@ -237,20 +287,66 @@ //===================璇诲彇閫昏緫鍒楄〃========================== UI.UI2.Intelligence.Automation.MainView.GetLogicList(); - }catch(Exception ex) + } + catch (Exception ex) { MainPage.Log($"鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}"); } finally { - Application.RunOnMainThread(() => { + Application.RunOnMainThread(() => + { + MainPage.Log($"缁撴潫璇诲彇浜戠鏁版嵁绾跨▼"); + endTime = DateTime.MinValue; DownloadDataComplete = true; waitPage.Hide(); waitPage.RemoveFromParent(); }); } + }); + downloadDataThread.IsBackground = true; + downloadDataThread.Priority = System.Threading.ThreadPriority.Highest; + downloadDataThread.Start(); + + //缃戠粶鍗¢】锛岀粓姝笅杞界嚎绋� + new System.Threading.Thread(() => + { + try + { + while (endTime > DateTime.Now) + { + if (DownloadDataComplete) + { + break; + } + System.Threading.Thread.Sleep(100); + } + if (!DownloadDataComplete) + { + //downloadDataThread.Abort(); + } + DownloadDataComplete = true; + Application.RunOnMainThread(() => + { + waitPage.Hide(); + waitPage.RemoveFromParent(); + }); + //鍒濆鍖栨暟鎹� + //SpatialInfo.CurrentSpatial.Clear(); + + } + catch { } + finally + { + #region 璇诲彇鏈湴鏁版嵁 + //璇诲彇闊充箰淇℃伅 + UI.Music.A31MusicModel.ReadMusicStates(); + //鎼滅储缃戝叧 + DriverLayer.Control.Ins.SearchLoaclGateway(); + #endregion + } }) { IsBackground = true }.Start(); } } -} +} \ No newline at end of file -- Gitblit v1.8.0