From c00da77d00a479fa5d022346a6d9075f90a5c087 Mon Sep 17 00:00:00 2001
From: wxr <wxr@hdlchina.com.cn>
Date: 星期六, 14 九月 2024 10:05:34 +0800
Subject: [PATCH] 退出登录时间调整,新风,音乐

---
 HDL_ON/Common/ApiUtlis.cs |  207 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 172 insertions(+), 35 deletions(-)

diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs
index e0a8a6a..2992899 100644
--- a/HDL_ON/Common/ApiUtlis.cs
+++ b/HDL_ON/Common/ApiUtlis.cs
@@ -72,12 +72,19 @@
         /// 涓嬭浇鏁版嵁瀹屾垚鏍囪
         /// </summary>
         public bool DownloadDataComplete = false;
+
+        /// <summary>
+        /// token鏄惁鏈夋晥
+        /// </summary>
+        public bool tokenInvalid = false;
+
+        public bool hadInternet = true;
         /// <summary>
         /// 涓嬭浇鏁版嵁
         /// </summary>
         public void DownloadData()
         {
-            if (MainPage.InternetStatus == 0 || MainPage.NoLoginMode)
+            if (MainPage.NoLoginMode)
             {
                 DownloadDataComplete = true;
                 return;
@@ -92,18 +99,101 @@
             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("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}");
+                        }
+                        return;
+                    }
+                    else
+                    {
+                        hadInternet = true;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    MainPage.Log("Error", $"涓嬭浇鏁版嵁1锛歿ex.StackTrace}");
+                    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;
                 }
@@ -112,6 +202,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;
                 }
@@ -120,6 +223,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;
                 }
@@ -152,13 +268,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("Error", $"{this.GetType()}:淇濆瓨鎴块棿淇℃伅寮傚父锛歿ex.StackTrace}");
+                                }
+                            })
+                            { IsBackground = true }.Start();
                         }
                     }
                     else
@@ -176,9 +305,8 @@
                             if (deviceResult.Code == StateCode.SUCCESS)
                             {
                                 FunctionList.List.ClearDatas();
-                                //MainPage.Log($"============璁惧============寮�濮�" + FunctionList.List.Functions.Count);
-                                //MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛");
-                                //MainPage.Log($"sid鍒楄〃鑾峰彇====" + deviceResult.Data.ToString());
+                                MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛");
+                                MainPage.Log($"sid鍒楄〃鑾峰彇====\r\n", deviceResult.Data.ToString());
                                 var deviceList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                 if (deviceList == null)
                                 {
@@ -202,7 +330,7 @@
                                 }
                                 finally
                                 {
-                                    
+
                                 }
 
                                 string delFile = "";
@@ -233,8 +361,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++}");
                                 }
 
@@ -257,7 +385,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];
 
@@ -281,7 +409,7 @@
                                                 --i;
                                             }catch(Exception ex)
                                             {
-                                                MainPage.Log($"ios 鍏ㄨ閫氬紓甯� : {ex.Message}");
+                                                MainPage.Log("Error", $"ios 鍏ㄨ閫氬紓甯� : {ex.StackTrace}");
                                             }
 
 #else
@@ -300,7 +428,7 @@
                                 //濡傛灉妫�娴嬬嚎绋嬫病鍚姩锛屾墠缁х画涓嬮潰鎿嶄綔 鍥犱负App鏈夊彲鑳藉垰鍚姩椹笂鏀跺埌鎺ㄩ�佷簡锛岀劧鍚庢墠鎵ц鍒拌繖閲�
                                 if (HDLLinphone.Current.CheckIncomingCallThreadIsNull())
                                 {
-                                    
+
                                     //褰撳墠浣忓畢鏄疕DL鍙瀵硅绫诲瀷鐨勮澶�
                                     if (isInterphoneType_HDL)
                                     {
@@ -357,16 +485,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)
@@ -380,16 +508,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);
@@ -423,7 +551,7 @@
                                     }
                                     catch (Exception ex)
                                     {
-                                        MainPage.Log($"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.Message}");
+                                        MainPage.Log("Error", $"璇诲彇缁勬帶鍒楄〃澶辫触:{ex.StackTrace}");
                                     }
                                 }
                                 else
@@ -485,9 +613,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
                         {
@@ -496,18 +625,19 @@
 
                         //======================瀹夐槻====================
                         GetSecurityList();
+
+                        //===================璇诲彇閫昏緫鍒楄〃====================
+                        Logic.LogicList.Clear();//涓婚〉涓嬫媺寮哄埗鍒锋柊鑷姩鍖栧垪琛�
+                        MainView.GetLogicList();//璇诲彇鑷姩鍖栧垪琛�
                     })
                     { IsBackground = true }.Start();
-
-                    //===================璇诲彇閫昏緫鍒楄〃==========================
-                    Logic.LogicList.Clear();//涓婚〉涓嬫媺寮哄埗鍒锋柊鑷姩鍖栧垪琛�
 
                     //======================娉ㄥ唽鎺ㄩ��====================
                     httpRequest.RegisteredPush();
                 }
                 catch (Exception ex)
                 {
-                    MainPage.Log($"鏁版嵁鍒濆鍖栧け璐ワ細{ex.Message}");
+                    MainPage.Log("Error", $"鏁版嵁鍒濆鍖栧け璐ワ細{ex.StackTrace}");
                 }
                 finally
                 {
@@ -526,9 +656,10 @@
                     try
                     {
                         FunctionList.List.Read3tyFunctionStatus();
-                    }catch(Exception ex)
+                    }
+                    catch (Exception ex)
                     {
-                        MainPage.Log("璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:"+ex.Message);
+                        MainPage.Log("Error", "璇诲彇绗笁鏂硅澶囩姸鎬佸け璐�:" + ex.StackTrace);
                     }
                 }
             });
@@ -564,13 +695,18 @@
                 {
                     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}");
+                        }
                     }
                 }
             })
@@ -650,4 +786,5 @@
 
 
     }
-}
\ No newline at end of file
+}
+

--
Gitblit v1.8.0