From 88a66f8374d63fbe9403258a9faa0fdcacf96571 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期五, 30 九月 2022 11:11:28 +0800 Subject: [PATCH] 获取云端数据code review --- HDL_ON/Common/ApiUtlis.cs | 258 +++++++++++++++++++++++++++++---------------------- 1 files changed, 148 insertions(+), 110 deletions(-) diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs index dba9d06..38f4711 100644 --- a/HDL_ON/Common/ApiUtlis.cs +++ b/HDL_ON/Common/ApiUtlis.cs @@ -43,6 +43,15 @@ } } /// <summary> + /// 璇诲彇璁惧鍔熻兘鏁版嵁瀹屾垚 + /// </summary> + bool complateDevice = false; + /// <summary> + /// 璇诲彇鍦烘櫙鏁版嵁瀹屾垚 + /// </summary> + bool complateScene = false; + + /// <summary> /// 鏍¢獙缃戝叧鏄惁鍦ㄧ嚎 /// </summary> public bool GatewayOnlineVerification() @@ -152,125 +161,161 @@ { MainPage.Log($"璇诲彇鎴块棿鏁版嵁澶辫触:Code:{roomResult.Code}; msg:{roomResult.message}"); } - //===================璁惧======================= - var deviceResult = Ins.HttpRequest.GetDeviceList("30","1"); - if (deviceResult.Code == StateCode.SUCCESS) - { - endTime = DateTime.Now.AddSeconds(5); - MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); - MainPage.Log($"sid鍒楄〃鑾峰彇===="+ deviceResult.Data.ToString()); - var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); - if (deviceList == null) - { - deviceList = new DevcieApiPack(); - } + //===================璁惧======================= + new System.Threading.Thread(() => + { try { - while (deviceList.totalPage != deviceList.pageNo) + complateDevice = false; + var deviceResult = Ins.HttpRequest.GetDeviceList("30", "1"); + if (deviceResult.Code == StateCode.SUCCESS) { - var deviceResult2 = Ins.HttpRequest.GetDeviceList("30", Convert.ToInt32(deviceList.pageNo) + 1 + ""); - if (deviceResult2.Code == StateCode.SUCCESS) + endTime = DateTime.Now.AddSeconds(5); + + MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); + MainPage.Log($"sid鍒楄〃鑾峰彇====" + deviceResult.Data.ToString()); + var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); + if (deviceList == null) { - var deviceList2 = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); - deviceList.pageNo = deviceList2.pageNo; - deviceList.list.AddRange(deviceList2.list); + deviceList = new DevcieApiPack(); } - } - }catch(Exception ex) - { - - } - - string delFile = ""; - if (FunctionList.List.GetDeviceFunctionList().Count > 0) - { - - for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;) - { - var localFunction = FunctionList.List.GetDeviceFunctionList()[i]; - //if (SPK.MusicSpkList().Contains(localFunction.spk)) - //{ - // i++; - // continue; - //} - var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); - - if (delFile == localFunction.savePath) + try { - i++; - continue; - } - delFile = localFunction.savePath; - FunctionList.List.DeleteFunction(localFunction); - } - } - //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� - foreach (var newFunction in deviceList.list) - { - newFunction.AssembleStatus(); - newFunction.SaveFunctionFile(); - FunctionList.List.IniFunctionList(newFunction.savePath); - } - endTime = DateTime.Now.AddSeconds(5); - } - else - { - MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); - } - - //===================鍦烘櫙========================== - var pack = Ins.HttpRequest.GetSceneList(); - if (pack.Code == StateCode.SUCCESS) - { - endTime = DateTime.Now.AddSeconds(100); - MainPage.Log($"璇诲彇鍦烘櫙鏁版嵁鎴愬姛"); - var sceneList = JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString()); - if (sceneList == null) - { - sceneList = new List<Scene>(); - } - FunctionList.List.scenes.Clear(); - - //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� - foreach (var tempScene in sceneList) - { - tempScene.SaveSceneFile(); - FunctionList.List.scenes.Add(tempScene); - } - //濡傛灉鏄竴绔彛闇�瑕佹彁鍓嶄笅杞藉満鏅暟鎹紝鍚﹀垯鎺у埗涓嶄簡涓�绔彛鍦烘櫙 - 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) + while (deviceList.totalPage != deviceList.pageNo) { - localScene.functions = serverTemp.functions; - localScene.SaveSceneFile(); + var deviceResult2 = Ins.HttpRequest.GetDeviceList("30", Convert.ToInt32(deviceList.pageNo) + 1 + ""); + if (deviceResult2.Code == StateCode.SUCCESS) + { + var deviceList2 = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); + deviceList.pageNo = deviceList2.pageNo; + deviceList.list.AddRange(deviceList2.list); + } } } + catch (Exception ex) + { + + } + finally + { + complateDevice = true; + } + + string delFile = ""; + if (FunctionList.List.GetDeviceFunctionList().Count > 0) + { + + for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;) + { + var localFunction = FunctionList.List.GetDeviceFunctionList()[i]; + //if (SPK.MusicSpkList().Contains(localFunction.spk)) + //{ + // i++; + // continue; + //} + var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); + + if (delFile == localFunction.savePath) + { + i++; + continue; + } + delFile = localFunction.savePath; + FunctionList.List.DeleteFunction(localFunction); + } + } + //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� + foreach (var newFunction in deviceList.list) + { + newFunction.AssembleStatus(); + newFunction.SaveFunctionFile(); + FunctionList.List.IniFunctionList(newFunction.savePath); + } + endTime = DateTime.Now.AddSeconds(5); } else { - IMessageCommon.Current.ShowErrorInfoAlter(packInfo.Code); + MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); } + }catch (Exception ex) + { + MainPage.Log($"============璁惧============{ex.Message}"); } - endTime = DateTime.Now.AddSeconds(5); - } - else + finally + { + complateDevice = true; + } + }) + { IsBackground = true }.Start(); + + //===================鍦烘櫙========================== + new System.Threading.Thread(() => { - MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁澶辫触:Code:{pack.Code}; Msg:{pack.message}"); - } + try + { + complateScene = true; + var pack = Ins.HttpRequest.GetSceneList(); + if (pack.Code == StateCode.SUCCESS) + { + endTime = DateTime.Now.AddSeconds(100); + MainPage.Log($"璇诲彇鍦烘櫙鏁版嵁鎴愬姛"); + var sceneList = JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString()); + if (sceneList == null) + { + sceneList = new List<Scene>(); + } + FunctionList.List.scenes.Clear(); + + //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� + foreach (var tempScene in sceneList) + { + tempScene.SaveSceneFile(); + FunctionList.List.scenes.Add(tempScene); + } + //濡傛灉鏄竴绔彛闇�瑕佹彁鍓嶄笅杞藉満鏅暟鎹紝鍚﹀垯鎺у埗涓嶄簡涓�绔彛鍦烘櫙 + 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 + { + MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁澶辫触:Code:{pack.Code}; Msg:{pack.message}"); + } + }catch(Exception ex) + { + MainPage.Log($"===鍦烘櫙==={ex.Message}"); + } + finally + { + complateScene = true; + } + }) + { IsBackground = true }.Start(); //===================璇诲彇閫昏緫鍒楄〃========================== UI.UI2.Intelligence.Automation.MainView.GetLogicList(); @@ -400,10 +445,6 @@ } System.Threading.Thread.Sleep(100); } - if (!DownloadDataComplete) - { - //downloadDataThread.Abort(); - } DownloadDataComplete = true; Application.RunOnMainThread(() => { @@ -413,9 +454,6 @@ waitPage = null; } }); - //鍒濆鍖栨暟鎹� - //SpatialInfo.CurrentSpatial.Clear(); - } catch { } finally -- Gitblit v1.8.0