From acc8caee31c4be90bd38d1af18136b0e84f6fe94 Mon Sep 17 00:00:00 2001 From: wxr <wxr@hdlchina.com.cn> Date: 星期五, 27 九月 2024 14:01:19 +0800 Subject: [PATCH] Merge branch 'feature/v2.7_迭代' into feature/V2.7_Google --- HDL_ON/Common/ApiUtlis.cs | 256 ++++++++++++++++++++++++++++++++++---------------- 1 files changed, 172 insertions(+), 84 deletions(-) diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs index edc5d3a..7d6dbd5 100644 --- a/HDL_ON/Common/ApiUtlis.cs +++ b/HDL_ON/Common/ApiUtlis.cs @@ -1,9 +1,10 @@ 锘縰sing System; using System.Collections.Generic; -using HDL_ON; -using HDL_ON.DAL; +using System.Net.Http; +using System.Threading.Tasks; using HDL_ON.DAL.Server; using HDL_ON.Entity; +using HDL_ON.UI; using HDL_ON.UI.UI2.FuntionControlView.Video; using HDL_ON.UI.UI2.Intelligence.Automation; using Newtonsoft.Json; @@ -73,6 +74,11 @@ /// </summary> public bool DownloadDataComplete = false; + /// <summary> + /// token鏄惁鏈夋晥 + /// </summary> + public bool IsValidToken = false; + public bool hadInternet = true; /// <summary> /// 涓嬭浇鏁版嵁 @@ -104,7 +110,7 @@ try { //澧炲姞3绉掍簯鏈嶅姟鍣ㄨ繛鎺ユ娴嬶紝杩炰笉涓婃湇鍔″櫒鐨勬椂鍊欎笉鍒锋柊鏁版嵁 - hadInternet = true; + //hadInternet = true; var dataList = new List<GlobalRegionListRes>(); var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark }); var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost, "", 3); @@ -127,7 +133,7 @@ } catch (Exception ex) { - MainPage.Log($"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.Message}"); + MainPage.Log("Error",$"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.StackTrace}"); } try @@ -141,10 +147,8 @@ } catch (Exception ex) { - MainPage.Log($"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.Message}"); + MainPage.Log("Error", $"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.StackTrace}"); } - - return; } else @@ -154,12 +158,13 @@ } catch (Exception ex) { - MainPage.Log($"Error锛氫笅杞芥暟鎹�1锛歿ex.Message}"); + MainPage.Log("Error", $"涓嬭浇鏁版嵁1锛歿ex.StackTrace}"); DownloadDataComplete = true; return; } finally { + MainPage.Log("鏈嶅姟鍣ㄨ繛鎺ョ姸鎬�:" + hadInternet); if (!hadInternet) { Application.RunOnMainThread(() => @@ -177,6 +182,42 @@ code = Ins.HttpRequest.RefreshToken(); if (code != StateCode.SUCCESS) { + DownloadDataComplete = true; + IsValidToken= false; + try + { + var spatialInfoDataBytes = FileUtlis.Files.ReadFile("SpatialInfoData"); + if (spatialInfoDataBytes != null) + { + var spatialInfoDataString = System.Text.Encoding.UTF8.GetString(spatialInfoDataBytes); + if (spatialInfoDataString != null && !string.IsNullOrEmpty(spatialInfoDataString)) + { + var spatialInfoDataList = JsonConvert.DeserializeObject<List<SpatialInfo>>(spatialInfoDataString); + SpatialInfo.CurrentSpatial.UpdateSpatialList(spatialInfoDataList); + } + } + } + catch (Exception ex) + { + MainPage.Log("Error", $"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.StackTrace}"); + } + + try + { + var fileList = Common.FileUtlis.Files.ReadFiles(); + foreach (var file in fileList) + { + FunctionList.List.IniFunctionList(file, true); + } + Room.CurrentSpatial.InitRoomListFunctions(); + } + catch (Exception ex) + { + MainPage.Log("Error", $"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.StackTrace}"); + } + MainPage.Log($"鍒锋柊token澶辫触"); + + if (waitPage != null) { Application.RunOnMainThread(() => @@ -190,8 +231,11 @@ catch { } }); } - MainPage.Log($"鍒锋柊token澶辫触"); return; + } + else + { + hadInternet = true; } MainPage.Log($"鍒锋柊token鎴愬姛"); //===================鍒锋柊浣忓畢淇℃伅======================= @@ -237,26 +281,6 @@ } 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; - //} - - //return; - try { //===================鎴块棿======================= @@ -277,9 +301,10 @@ { var ssd = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(revData.list)); FileUtlis.Files.WriteFileByBytes("SpatialInfoData", ssd); - }catch(Exception ex) + } + catch (Exception ex) { - MainPage.Log($"{this.GetType()}:淇濆瓨鎴块棿淇℃伅寮傚父锛歿ex.Message}"); + MainPage.Log("Error", $"{this.GetType()}:淇濆瓨鎴块棿淇℃伅寮傚父锛歿ex.StackTrace}"); } }) { IsBackground = true }.Start(); @@ -300,9 +325,8 @@ if (deviceResult.Code == StateCode.SUCCESS) { FunctionList.List.ClearDatas(); - //MainPage.Log($"============璁惧============寮�濮�" + FunctionList.List.Functions.Count); - //MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); - MainPage.Log($"sid鍒楄〃鑾峰彇====\r\n" , deviceResult.Data.ToString()); + MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); + //MainPage.Log($"sid鍒楄〃鑾峰彇====\r\n", deviceResult.Data.ToString()); var deviceList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); if (deviceList == null) { @@ -326,7 +350,7 @@ } finally { - + } string delFile = ""; @@ -357,8 +381,8 @@ foreach (var newFunction in deviceList.list) { newFunction.AssembleStatus(); - newFunction.SaveFunctionFile(); - FunctionList.List.IniFunctionList(newFunction.savePath,true); + newFunction.SaveFunctionFile(); + FunctionList.List.IniFunctionList(newFunction.savePath, true); //MainPage.Log($"============璁惧============{iiii++}"); } @@ -373,7 +397,6 @@ //} //======================鑾峰彇鍙瀵硅璁惧鍒楄〃==================== - bool isInterphoneType_HDL = false;//鏄惁涓篐DLLinphone鍙瀵硅 bool isInterphoneType_FREEVIEW = false;//鏄惁涓哄叏瑙嗛�氬彲瑙嗗璁� var videoInfo = VideoSend.GetVideoInfoList(); if (videoInfo.Code == StateCode.SUCCESS) @@ -381,7 +404,7 @@ string videoList = videoInfo.Data.ToString(); FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(videoList); - for(int i =0;i< FunctionList.List.videoIntercom.Count;i++) + for (int i = 0; i < FunctionList.List.videoIntercom.Count; i++) { var video = FunctionList.List.videoIntercom[i]; @@ -405,7 +428,7 @@ --i; }catch(Exception ex) { - MainPage.Log($"ios 鍏ㄨ閫氬紓甯� : {ex.Message}"); + MainPage.Log("Error", $"ios 鍏ㄨ閫氬紓甯� : {ex.StackTrace}"); } #else @@ -424,7 +447,7 @@ //濡傛灉妫�娴嬬嚎绋嬫病鍚姩锛屾墠缁х画涓嬮潰鎿嶄綔 鍥犱负App鏈夊彲鑳藉垰鍚姩椹笂鏀跺埌鎺ㄩ�佷簡锛岀劧鍚庢墠鎵ц鍒拌繖閲� if (HDLLinphone.Current.CheckIncomingCallThreadIsNull()) { - + //褰撳墠浣忓畢鏄疕DL鍙瀵硅绫诲瀷鐨勮澶� if (isInterphoneType_HDL) { @@ -481,16 +504,16 @@ { MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); } - }catch (Exception ex) + } + catch (Exception ex) { - MainPage.Log($"============璁惧============{ex.Message}"); + MainPage.Log("Error", $"============璁惧============{ex.StackTrace}"); } finally { complateDevice = true; MainPage.Log($"============璁惧============瀹屾垚" + FunctionList.List.Functions.Count); } - //======================缇ゆ帶==================== if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl) @@ -504,16 +527,16 @@ { var groupControlList = JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString()); var readSidList = new List<string>(); - foreach(var temp in groupControlList) + foreach (var temp in groupControlList) { FunctionList.List.groupControls.Clear(); readSidList.Add(temp.userDeviceGroupControlId); if (readSidList.Count >= 20) { var data = Ins.httpRequest.GetGroupControInfo(readSidList); - if(data != null) + if (data != null) { - if(data.Code == StateCode.SUCCESS) + if (data.Code == StateCode.SUCCESS) { var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString()); FunctionList.List.groupControls.AddRange(groupControlInfoList); @@ -547,7 +570,7 @@ } catch (Exception ex) { - MainPage.Log($"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.Message}"); + MainPage.Log("Error", $"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.StackTrace}"); } } else @@ -609,9 +632,10 @@ { MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁澶辫触:Code:{pack.Code}; Msg:{pack.message}"); } - }catch(Exception ex) + } + catch (Exception ex) { - MainPage.Log($"===鍦烘櫙==={ex.Message}"); + MainPage.Log("Error", $"===鍦烘櫙==={ex.StackTrace}"); } finally { @@ -632,7 +656,7 @@ } catch (Exception ex) { - MainPage.Log($"鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}"); + MainPage.Log("Error", $"鏁版嵁鍒濆鍖栧け璐ワ細{ex.StackTrace}"); } finally { @@ -651,9 +675,10 @@ try { FunctionList.List.Read3tyFunctionStatus(); - }catch(Exception ex) + } + catch (Exception ex) { - MainPage.Log("璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:"+ex.Message); + MainPage.Log("Error", "璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:" + ex.StackTrace); } } }); @@ -689,13 +714,46 @@ { if (DB_ResidenceData.Instance.CurrentRegion != null) { -#region 璇诲彇鏈湴鏁版嵁 - //鎼滅储缃戝叧 - DriverLayer.Control.Ins.SearchLoaclGateway(); - //閲嶆柊杩炴帴mqtt - DAL.Mqtt.MqttClient.DisConnectRemote("鍒锋柊鏁版嵁锛岄噸杩瀖qtt",false); -#endregion + try + { + #region 璇诲彇鏈湴鏁版嵁 + //鎼滅储缃戝叧 + DriverLayer.Control.Ins.SearchLoaclGateway(); + //閲嶆柊杩炴帴mqtt + DAL.Mqtt.MqttClient.DisConnectRemote("鍒锋柊鏁版嵁锛岄噸杩瀖qtt", false); + #endregion + } + catch (Exception ex){ + MainPage.Log("Error", $"璇诲彇鏈湴鏁版嵁寮傚父锛歿ex.StackTrace}"); + } + try + { + HomePage.LoadEvent_CheckTokenValid(); + if (IsValidToken && !UserInfo.Current.IsTipedInvalidToken) + { + UserInfo.Current.IsTipedInvalidToken = true; + UserInfo.Current.SaveUserInfo(); + Application.RunOnMainThread(() => + { + try + { + new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.TokenInvalidTipMsg, StringId.OfflineControl, StringId.GoLogin, () => + { + HDLCommon.Current.Logout(); + }); + } + catch (Exception ex) + { + MainPage.Log("Error", $"鎻愮ず鐧诲綍鍑瘉绐楀彛鍔犺浇寮傚父:{ex.StackTrace}"); + } + }); + } + } + catch (Exception ex) + { + MainPage.Log("Error", $"鏇存柊鐧诲綍鍑瘉鏂规硶璋冪敤寮傚父:{ex.StackTrace}"); + } } } }) @@ -728,39 +786,50 @@ { lock (FunctionList.List.securities) { - var pack = Ins.HttpRequest.GetSecurityList(); - if (pack.Code == StateCode.SUCCESS) + try { - var packList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(pack.Data.ToString()); - Console.WriteLine("瀹夐槻鎬绘暟锛�" + packList.Count); - var sidList = new List<string>(); - foreach (var function in packList) + var pack = Ins.HttpRequest.GetSecurityList(); + if (pack.Code == StateCode.SUCCESS) { - sidList.Add(function.sid); - } - var infoListPack = Ins.httpRequest.GetSecurityInfo(sidList, new List<string>()); - var infoList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(infoListPack.Data.ToString()); - if (infoList != null) - { - var filePathList = FileUtlis.Files.ReadFiles().FindAll((obj) => obj.StartsWith("SecurityData_")); - if (filePathList != null) + var packList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(pack.Data.ToString()); + Console.WriteLine("瀹夐槻鎬绘暟锛�" + packList.Count); + var sidList = new List<string>(); + foreach (var function in packList) { - foreach (var file in filePathList) + sidList.Add(function.sid); + } + if (sidList.Count == 0) + { + return; + } + var infoListPack = Ins.httpRequest.GetSecurityInfo(sidList, new List<string>()); + var infoList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(infoListPack.Data.ToString()); + if (infoList != null) + { + var filePathList = FileUtlis.Files.ReadFiles().FindAll((obj) => obj.StartsWith("SecurityData_")); + if (filePathList != null) { - FileUtlis.Files.DeleteFile(file); + foreach (var file in filePathList) + { + FileUtlis.Files.DeleteFile(file); + } + } + FunctionList.List.securities.Clear(); + foreach (var function in infoList) + { + function.SaveFile(); + FunctionList.List.IniFunctionList(function.savePath, true); } } - FunctionList.List.securities.Clear(); - foreach (var function in infoList) - { - function.SaveFile(); - FunctionList.List.IniFunctionList(function.savePath, true); - } + } + else + { + MainPage.Log($"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{pack.Code}; Msg:{pack.message}"); } } - else + catch (Exception ex) { - MainPage.Log($"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{pack.Code}; Msg:{pack.message}"); + MainPage.Log("Error", $"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{ex.StackTrace}"); } } } @@ -773,6 +842,25 @@ var pack = Ins.HttpRequest.GetSecurityList(); } + //public async Task<bool> CanConnectToHost() + //{ + // try + // { + // using (HttpClient client = new HttpClient()) + // { + // client.Timeout = TimeSpan.FromSeconds(3); // 瓒呮椂鏃堕棿 + // HttpResponseMessage response = await client.GetAsync(HttpUtil.GlobalRequestHttpsHost); + // return response.IsSuccessStatusCode; + // } + // } + // catch (Exception ex) + // { + // MainPage.Log(ex.StackTrace); + // return false; + // } + //} + } -} \ No newline at end of file +} + -- Gitblit v1.8.0