From 4ab5ecb0a4fa8ab66647427c4f90db9db302ea3b Mon Sep 17 00:00:00 2001 From: wxr <wxr@hdlchina.com.cn> Date: 星期二, 02 七月 2024 16:05:25 +0800 Subject: [PATCH] 音乐播放时间计算 --- HDL_ON/Common/ApiUtlis.cs | 426 ++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 342 insertions(+), 84 deletions(-) diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs index 0ac177c..d8172bf 100644 --- a/HDL_ON/Common/ApiUtlis.cs +++ b/HDL_ON/Common/ApiUtlis.cs @@ -4,6 +4,7 @@ using HDL_ON.DAL; using HDL_ON.DAL.Server; using HDL_ON.Entity; +using HDL_ON.UI.UI2.FuntionControlView.Video; using HDL_ON.UI.UI2.Intelligence.Automation; using Newtonsoft.Json; using Shared; @@ -71,13 +72,18 @@ /// 涓嬭浇鏁版嵁瀹屾垚鏍囪 /// </summary> public bool DownloadDataComplete = false; + + public bool hadInternet = true; /// <summary> /// 涓嬭浇鏁版嵁 /// </summary> public void DownloadData() { - if (MainPage.InternetStatus == 0 || MainPage.NoLoginMode) + if (MainPage.NoLoginMode) + { + DownloadDataComplete = true; return; + } endTime1 = DateTime.Now.AddSeconds(25); complateDevice = complateScene = false; @@ -89,49 +95,166 @@ MainPage.BaseView.AddChidren(waitPage); waitPage.Start(Language.StringByID(StringId.PleaseWait)); - string code = StateCode.SUCCESS; - Inverter.Ins.H5Page = null;//閲嶇疆鍏変紡椤甸潰 + string code = StateCode.SUCCESS; var downloadDataThread = new System.Threading.Thread(() => { try { - MainPage.Log($"杩涘叆璇诲彇浜戠鏁版嵁绾跨▼"); - //===================鍒锋柊Token======================= - code = Ins.HttpRequest.RefreshToken(); - if (code != StateCode.SUCCESS) + //澧炲姞3绉掍簯鏈嶅姟鍣ㄨ繛鎺ユ娴嬶紝杩炰笉涓婃湇鍔″櫒鐨勬椂鍊欎笉鍒锋柊鏁版嵁 + 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); + if (revertObj == null || revertObj.Code != StateCode.SUCCESS) { - MainPage.Log($"鍒锋柊token澶辫触"); + DownloadDataComplete = true; + hadInternet = 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($"{this.GetType()}:鍔犺浇缂撳瓨鎴块棿鏁版嵁寮傚父:{ex.Message}"); + } + + 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($"{this.GetType()}:鍔犺浇缂撳瓨璁惧鏁版嵁寮傚父:{ex.Message}"); + } + + return; } - MainPage.Log($"鍒锋柊token鎴愬姛"); - //===================鍒锋柊浣忓畢淇℃伅======================= - code = Ins.HttpRequest.GetHomePager(); - if (code != StateCode.SUCCESS) + else { - MainPage.Log($"鍒锋柊浣忓畢淇℃伅澶辫触"); - return; + hadInternet = true; } - MainPage.Log($"鍒锋柊浣忓畢淇℃伅鎴愬姛"); - //===================鍒锋柊涓汉淇℃伅======================= - code = Ins.HttpRequest.GetUserInfo(); - if (code != StateCode.SUCCESS) - { - MainPage.Log($"鍒锋柊涓汉淇℃伅澶辫触"); - return; - } - MainPage.Log($"鍒锋柊涓汉淇℃伅鎴愬姛"); } catch (Exception ex) { - MainPage.Log($"鍒锋柊鍩虹鏁版嵁澶辫触"); - } - - if (string.IsNullOrEmpty( DB_ResidenceData.Instance.CurrentRegion.id)) - { + MainPage.Log($"Error锛氫笅杞芥暟鎹�1锛歿ex.Message}"); + DownloadDataComplete = true; return; } + finally + { + if (!hadInternet) + { + Application.RunOnMainThread(() => + { + if (waitPage != null) + { + waitPage.Hide(); + waitPage.RemoveFromParent(); + } + }); + } + } + MainPage.Log($"杩涘叆璇诲彇浜戠鏁版嵁绾跨▼"); + //===================鍒锋柊Token======================= + code = Ins.HttpRequest.RefreshToken(); + if (code != StateCode.SUCCESS) + { + if (waitPage != null) + { + Application.RunOnMainThread(() => + { + try + { + waitPage.Hide(); + waitPage.RemoveFromParent(); + waitPage = null; + } + catch { } + }); + } + MainPage.Log($"鍒锋柊token澶辫触"); + return; + } + MainPage.Log($"鍒锋柊token鎴愬姛"); + //===================鍒锋柊浣忓畢淇℃伅======================= + code = Ins.HttpRequest.GetHomePager(); + if (code != StateCode.SUCCESS) + { + if (waitPage != null) + { + Application.RunOnMainThread(() => + { + try + { + waitPage.Hide(); + waitPage.RemoveFromParent(); + waitPage = null; + } + catch { } + }); + } + MainPage.Log($"鍒锋柊浣忓畢淇℃伅澶辫触"); + return; + } + MainPage.Log($"鍒锋柊浣忓畢淇℃伅鎴愬姛"); + //===================鍒锋柊涓汉淇℃伅======================= + code = Ins.HttpRequest.GetUserInfo(); + if (code != StateCode.SUCCESS) + { + if (waitPage != null) + { + Application.RunOnMainThread(() => + { + try + { + waitPage.Hide(); + waitPage.RemoveFromParent(); + waitPage = null; + } + catch { } + }); + } + MainPage.Log($"鍒锋柊涓汉淇℃伅澶辫触"); + return; + } + 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 { @@ -140,13 +263,26 @@ if (roomResult.Code == StateCode.SUCCESS) { MainPage.Log($"璇诲彇鎴块棿淇℃伅鎴愬姛"); - var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(roomResult.Data.ToString()); + var revData = JsonConvert.DeserializeObject<SpatialApiPack>(roomResult.Data.ToString()); if (revData == null) { revData = new SpatialApiPack(); } { SpatialInfo.CurrentSpatial.UpdateSpatialList(revData.list); + new System.Threading.Thread(() => + { + try + { + var ssd = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(revData.list)); + FileUtlis.Files.WriteFileByBytes("SpatialInfoData", ssd); + } + catch (Exception ex) + { + MainPage.Log($"{this.GetType()}:淇濆瓨鎴块棿淇℃伅寮傚父锛歿ex.Message}"); + } + }) + { IsBackground = true }.Start(); } } else @@ -164,9 +300,9 @@ if (deviceResult.Code == StateCode.SUCCESS) { FunctionList.List.ClearDatas(); - MainPage.Log($"============璁惧============寮�濮�" + FunctionList.List.Functions.Count); + //MainPage.Log($"============璁惧============寮�濮�" + FunctionList.List.Functions.Count); //MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); - //MainPage.Log($"sid鍒楄〃鑾峰彇====" + deviceResult.Data.ToString()); + MainPage.Log($"sid鍒楄〃鑾峰彇====\r\n", deviceResult.Data.ToString()); var deviceList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); if (deviceList == null) { @@ -190,7 +326,7 @@ } finally { - + } string delFile = ""; @@ -217,23 +353,77 @@ } } //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳� - int iiii = 0; + //int iiii = 0; foreach (var newFunction in deviceList.list) { newFunction.AssembleStatus(); newFunction.SaveFunctionFile(); - FunctionList.List.IniFunctionList(newFunction.savePath,true); - MainPage.Log($"============璁惧============{iiii++}"); + FunctionList.List.IniFunctionList(newFunction.savePath, true); + //MainPage.Log($"============璁惧============{iiii++}"); } + + //===================璇诲彇鍙瀵硅鏁版嵁========================== + //鍒ゆ柇鏄惁鏈夊彲瑙嗗璁叉暟鎹紝鏈夊垯鏄剧ず鍙瀵硅icon + //var flVideoInfo = HttpRequest.CheckFlVideo(); + //if(flVideoInfo.Code == StateCode.SUCCESS) + //{ + // FunctionList.List.videoIntercom1111 = Newtonsoft.Json.JsonConvert.DeserializeObject<UI.UI2.FuntionControlView.Video.VideoClouds>(flVideoInfo.Data.ToString()); + //} + + //======================鑾峰彇鍙瀵硅璁惧鍒楄〃==================== + bool isInterphoneType_HDL = false;//鏄惁涓篐DLLinphone鍙瀵硅 + var videoInfo = VideoSend.GetVideoInfoList(); + if (videoInfo.Code == StateCode.SUCCESS) + { + 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++) + { + var video = FunctionList.List.videoIntercom[i]; + + if (video.interphoneType == InterphoneType.HDL.ToString()) + { + isInterphoneType_HDL = true; + DB_ResidenceData.Instance.SupportFacePass = true; + DB_ResidenceData.Instance.SaveResidenceData(); + + } + } + } + + + //======================鑾峰彇Sip璐﹀彿骞朵笖鍒濆鍖朣DK鍙瀵硅璁惧鍒楄〃==================== + //濡傛灉妫�娴嬬嚎绋嬫病鍚姩锛屾墠缁х画涓嬮潰鎿嶄綔 鍥犱负App鏈夊彲鑳藉垰鍚姩椹笂鏀跺埌鎺ㄩ�佷簡锛岀劧鍚庢墠鎵ц鍒拌繖閲� + if (HDLLinphone.Current.CheckIncomingCallThreadIsNull()) + { + + //褰撳墠浣忓畢鏄疕DL鍙瀵硅绫诲瀷鐨勮澶� + if (isInterphoneType_HDL) + { + //HDLLinphone鍙瀵硅,鑾峰彇Sip璐﹀彿骞跺垵濮嬪寲SDK + HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo(); + callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id; + callVideoInfo.InterphoneType = InterphoneType.HDL.ToString(); + HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo); + } + else + { + Utlis.WriteLine("褰撳墠浣忓畢涓嶆敮鎸丠DL鍙瀵硅,閫�鍑虹櫥褰曟墍鏈夎处鍙�"); + //褰撳墠浣忓畢涓嶆敮鎸丠DL鍙瀵硅 + HDLLinphone.Current.LogoutAllAccount(); + } + } } else { MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁澶辫触:Code:{deviceResult.Code}; Msg:{deviceResult.message}"); } - }catch (Exception ex) + } + catch (Exception ex) { MainPage.Log($"============璁惧============{ex.Message}"); } @@ -242,12 +432,73 @@ complateDevice = true; MainPage.Log($"============璁惧============瀹屾垚" + FunctionList.List.Functions.Count); } - //}) - //{ IsBackground = true }.Start(); - ////===================鍦烘櫙========================== - //new System.Threading.Thread(() => - //{ + + //======================缇ゆ帶==================== + if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl) + { + var pack = Ins.HttpRequest.GetGroupControlList(); + if (pack != null) + { + if (pack.Code == StateCode.SUCCESS) + { + try + { + var groupControlList = JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString()); + var readSidList = new List<string>(); + 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.Code == StateCode.SUCCESS) + { + var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString()); + FunctionList.List.groupControls.AddRange(groupControlInfoList); + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + } + } + readSidList.Clear(); + } + //FunctionList.List.Functions.AddRange(FunctionList.List.groupControls); + } + if (readSidList.Count > 0) + { + var data = Ins.httpRequest.GetGroupControInfo(readSidList); + if (data != null) + { + if (data.Code == StateCode.SUCCESS) + { + var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString()); + FunctionList.List.groupControls.AddRange(groupControlInfoList); + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + } + } + readSidList.Clear(); + } + } + catch (Exception ex) + { + MainPage.Log($"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.Message}"); + } + } + else + { + IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); + } + } + } + //======================鍦烘櫙==================== try { complateScene = false; @@ -279,7 +530,7 @@ var packInfo = HttpRequest.GetSceneListInfo(sceneIds); if (packInfo.Code == StateCode.SUCCESS) { - var serverTempList = JsonConvert.DeserializeObject<List<Scene>>(packInfo.Data.ToString()); + 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); @@ -300,7 +551,8 @@ { MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁澶辫触:Code:{pack.Code}; Msg:{pack.message}"); } - }catch(Exception ex) + } + catch (Exception ex) { MainPage.Log($"===鍦烘櫙==={ex.Message}"); } @@ -308,18 +560,18 @@ { complateScene = true; } + + //======================瀹夐槻==================== + GetSecurityList(); + + //===================璇诲彇閫昏緫鍒楄〃==================== + Logic.LogicList.Clear();//涓婚〉涓嬫媺寮哄埗鍒锋柊鑷姩鍖栧垪琛� + MainView.GetLogicList();//璇诲彇鑷姩鍖栧垪琛� }) { IsBackground = true }.Start(); - //===================璇诲彇閫昏緫鍒楄〃========================== - Logic.LogicList.Clear();//涓婚〉涓嬫媺寮哄埗鍒锋柊鑷姩鍖栧垪琛� - - //======================瀹夐槻==================== - GetSecurityList(); //======================娉ㄥ唽鎺ㄩ��==================== httpRequest.RegisteredPush(); - - } catch (Exception ex) { @@ -342,12 +594,15 @@ try { FunctionList.List.Read3tyFunctionStatus(); - }catch(Exception ex) + } + catch (Exception ex) { - MainPage.Log("璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:"+ex.Message); + MainPage.Log("璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:" + ex.Message); } } }); + downloadDataThread.IsBackground = true; + downloadDataThread.Priority = System.Threading.ThreadPriority.Highest; downloadDataThread.Start(); //缃戠粶鍗¢】锛岀粓姝笅杞界嚎绋� @@ -357,7 +612,7 @@ { while (endTime1 > DateTime.Now) { - if ( complateDevice && complateScene) + if (complateDevice && complateScene) { break; } @@ -378,12 +633,12 @@ { if (DB_ResidenceData.Instance.CurrentRegion != null) { -#region 璇诲彇鏈湴鏁版嵁 + #region 璇诲彇鏈湴鏁版嵁 //鎼滅储缃戝叧 DriverLayer.Control.Ins.SearchLoaclGateway(); //閲嶆柊杩炴帴mqtt - DAL.Mqtt.MqttClient.DisConnectRemote("鍒锋柊鏁版嵁锛岄噸杩瀖qtt",false); -#endregion + DAL.Mqtt.MqttClient.DisConnectRemote("鍒锋柊鏁版嵁锛岄噸杩瀖qtt", false); + #endregion } } @@ -402,10 +657,10 @@ MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛"); var packList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); - foreach(var function in packList.list) + foreach (var function in packList.list) { function.SaveFunctionFile(); - FunctionList.List.IniFunctionList(function.savePath,true); + FunctionList.List.IniFunctionList(function.savePath, true); } } } @@ -415,40 +670,43 @@ /// </summary> public void GetSecurityList() { - var pack = Ins.HttpRequest.GetSecurityList(); - if (pack.Code == StateCode.SUCCESS) + lock (FunctionList.List.securities) { - var packList = JsonConvert.DeserializeObject<List<SecurityAlarm>>(pack.Data.ToString()); - 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); + } + 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 + { + MainPage.Log($"璇诲彇瀹夐槻鍒楄〃澶辫触:Code:{pack.Code}; Msg:{pack.message}"); + } } - } /// <summary> -- Gitblit v1.8.0