From f9181a9c8125136f597add7c30cb2ff508d54ba7 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 25 七月 2024 17:34:32 +0800
Subject: [PATCH] 2024年07月25日17:33:40

---
 HDL_ON/Common/ApiUtlis.cs |  201 ++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 170 insertions(+), 31 deletions(-)

diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs
index ae98d39..edc5d3a 100644
--- a/HDL_ON/Common/ApiUtlis.cs
+++ b/HDL_ON/Common/ApiUtlis.cs
@@ -72,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,18 +94,102 @@
             var waitPage = new Loading();
             MainPage.BaseView.AddChidren(waitPage);
             waitPage.Start(Language.StringByID(StringId.PleaseWait));
+           
 
             string code = StateCode.SUCCESS;
 
             Inverter.Ins.H5Page = null;//閲嶇疆鍏変紡椤甸潰
-
             var downloadDataThread = new System.Threading.Thread(() =>
             {
+                try
+                {
+                    //澧炲姞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)
+                    {
+                        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;
+                    }
+                    else
+                    {
+                        hadInternet = true;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    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;
                 }
@@ -109,6 +198,19 @@
                 code = Ins.HttpRequest.GetHomePager();
                 if (code != StateCode.SUCCESS)
                 {
+                    if (waitPage != null)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            try
+                            {
+                                waitPage.Hide();
+                                waitPage.RemoveFromParent();
+                                waitPage = null;
+                            }
+                            catch { }
+                        });
+                    }
                     MainPage.Log($"鍒锋柊浣忓畢淇℃伅澶辫触");
                     return;
                 }
@@ -117,6 +219,19 @@
                 code = Ins.HttpRequest.GetUserInfo();
                 if (code != StateCode.SUCCESS)
                 {
+                    if (waitPage != null)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            try
+                            {
+                                waitPage.Hide();
+                                waitPage.RemoveFromParent();
+                                waitPage = null;
+                            }
+                            catch { }
+                        });
+                    }
                     MainPage.Log($"鍒锋柊涓汉淇℃伅澶辫触");
                     return;
                 }
@@ -149,13 +264,25 @@
                     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
@@ -175,7 +302,7 @@
                                 FunctionList.List.ClearDatas();
                                 //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)
                                 {
@@ -254,8 +381,10 @@
                                     string videoList = videoInfo.Data.ToString();
                                     FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(videoList);
 
-                                    foreach (var video in FunctionList.List.videoIntercom)
+                                    for(int i =0;i< FunctionList.List.videoIntercom.Count;i++)
                                     {
+                                        var video = FunctionList.List.videoIntercom[i];
+
                                         if (video.interphoneType == InterphoneType.IMOUVISIAL.ToString())
                                         {
                                             UI.UI2.PersonalCenter.PirDevice.PirSend.LcSubAccessToken = video.subAccountToken;
@@ -265,19 +394,27 @@
                                             isInterphoneType_HDL = true;
                                             DB_ResidenceData.Instance.SupportFacePass = true;
                                             DB_ResidenceData.Instance.SaveResidenceData();
-
-                                            Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
+                                            DB_ResidenceData.Instance.SupportFVDevice = true;
                                         }
                                         else if (video.interphoneType == InterphoneType.FREEVIEW.ToString())
                                         {
+#if __IOS__
+                                            try
+                                            {
+                                                FunctionList.List.videoIntercom.Remove(video);
+                                                --i;
+                                            }catch(Exception ex)
+                                            {
+                                                MainPage.Log($"ios 鍏ㄨ閫氬紓甯� : {ex.Message}");
+                                            }
+
+#else
                                             //涓哄叏瑙嗛�氬彲瑙嗗璁�
                                             DB_ResidenceData.Instance.SupportFacePass = true;
                                             Entity.DB_ResidenceData.Instance.SupportVisitorManage = true;
                                             Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
-
-                                            //isInterphoneType_HDL = true;
                                             isInterphoneType_FREEVIEW = true;
-
+#endif
                                         }
                                     }
                                 }
@@ -287,6 +424,7 @@
                                 //濡傛灉妫�娴嬬嚎绋嬫病鍚姩锛屾墠缁х画涓嬮潰鎿嶄綔 鍥犱负App鏈夊彲鑳藉垰鍚姩椹笂鏀跺埌鎺ㄩ�佷簡锛岀劧鍚庢墠鎵ц鍒拌繖閲�
                                 if (HDLLinphone.Current.CheckIncomingCallThreadIsNull())
                                 {
+                                    
                                     //褰撳墠浣忓畢鏄疕DL鍙瀵硅绫诲瀷鐨勮澶�
                                     if (isInterphoneType_HDL)
                                     {
@@ -298,7 +436,6 @@
                                     }
                                     else if (isInterphoneType_FREEVIEW)
                                     {
-
                                         //HDLLinphone鍙瀵硅,鑾峰彇Sip璐﹀彿骞跺垵濮嬪寲SDK
                                         HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
                                         callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
@@ -320,23 +457,22 @@
                                 {
 
 #if __IOS__
-                                    string systemVersion = UIKit.UIDevice.CurrentDevice.SystemVersion;
-                                    string errorVersion = "16.2.0";
-                                    if (systemVersion.CompareTo(errorVersion) < 0)///鍏ㄨ閫氫笉鍏煎ios16浠ヤ笂鐨勭郴缁燂紝涓嶈鍔犺浇杩欎釜鍏�
-                                    {
-                                        List<VisitorTempPassword> dataList = new List<VisitorTempPassword>();
-                                        Dictionary<string, object> dictionary = new Dictionary<string, object>();
-                                        dictionary.Add("homeId", Entity.DB_ResidenceData.Instance.CurrentRegion.id);
-                                        var requestJson = HttpUtil.GetSignRequestJson(dictionary);
-                                        ResponsePackNew pack = HttpUtil.RequestHttpsPost(NewAPI.Api_Post_GetExtMemberInfo, requestJson);
-                                        if (pack != null)
-                                        {
-                                            var data = JsonConvert.DeserializeObject<FreeviewMemberInfo>(pack.Data.ToString());
-                                            //鐧诲綍鍏ㄨ閫�
-                                            Shared.IOS.HDLFVSDK.Video.Init("", data.extUserId, DB_ResidenceData.Instance.CurrentRegion.id, "78FF1E4D-FC0A-4E71-9B79-0448E4460BD7", "T0001", "120.77.53.170:9700", "120.77.53.170:21664");
-
-                                        }
-                                    }
+                                    //string systemVersion = UIKit.UIDevice.CurrentDevice.SystemVersion;
+                                    //string errorVersion = "16.2.0";
+                                    //if (systemVersion.CompareTo(errorVersion) < 0)///鍏ㄨ閫氫笉鍏煎ios16浠ヤ笂鐨勭郴缁燂紝涓嶈鍔犺浇杩欎釜鍏�
+                                    //{
+                                    //    List<VisitorTempPassword> dataList = new List<VisitorTempPassword>();
+                                    //    Dictionary<string, object> dictionary = new Dictionary<string, object>();
+                                    //    dictionary.Add("homeId", Entity.DB_ResidenceData.Instance.CurrentRegion.id);
+                                    //    var requestJson = HttpUtil.GetSignRequestJson(dictionary);
+                                    //    ResponsePackNew pack = HttpUtil.RequestHttpsPost(NewAPI.Api_Post_GetExtMemberInfo, requestJson);
+                                    //    if (pack != null)
+                                    //    {
+                                    //        var data = JsonConvert.DeserializeObject<FreeviewMemberInfo>(pack.Data.ToString());
+                                    //        //鐧诲綍鍏ㄨ閫�
+                                    //        Shared.IOS.HDLFVSDK.Video.Init("", data.extUserId, DB_ResidenceData.Instance.CurrentRegion.id, "78FF1E4D-FC0A-4E71-9B79-0448E4460BD7", "T0001", "120.77.53.170:9700", "120.77.53.170:21664");
+                                    //    }
+                                    //}
 #endif
                                 }
 
@@ -356,6 +492,7 @@
                         }
 
 
+                        //======================缇ゆ帶====================
                         if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl)
                         {
                             var pack = Ins.HttpRequest.GetGroupControlList();
@@ -388,6 +525,7 @@
                                                 }
                                                 readSidList.Clear();
                                             }
+                                            //FunctionList.List.Functions.AddRange(FunctionList.List.groupControls);
                                         }
                                         if (readSidList.Count > 0)
                                         {
@@ -482,11 +620,12 @@
 
                         //======================瀹夐槻====================
                         GetSecurityList();
+
+                        //===================璇诲彇閫昏緫鍒楄〃====================
+                        Logic.LogicList.Clear();//涓婚〉涓嬫媺寮哄埗鍒锋柊鑷姩鍖栧垪琛�
+                        MainView.GetLogicList();//璇诲彇鑷姩鍖栧垪琛�
                     })
                     { IsBackground = true }.Start();
-
-                    //===================璇诲彇閫昏緫鍒楄〃==========================
-                    Logic.LogicList.Clear();//涓婚〉涓嬫媺寮哄埗鍒锋柊鑷姩鍖栧垪琛�
 
                     //======================娉ㄥ唽鎺ㄩ��====================
                     httpRequest.RegisteredPush();

--
Gitblit v1.8.0