From 271faaf6664166dc368639b9f2e577f63f901be5 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期三, 23 十二月 2020 22:23:57 +0800
Subject: [PATCH] 20201223-99

---
 HDL_ON/Common/ApiUtlis.cs |   94 ++++++++++++++++++++++++++++++----------------
 1 files changed, 61 insertions(+), 33 deletions(-)

diff --git a/HDL_ON/Common/ApiUtlis.cs b/HDL_ON/Common/ApiUtlis.cs
index 069acdc..52a8ac9 100644
--- a/HDL_ON/Common/ApiUtlis.cs
+++ b/HDL_ON/Common/ApiUtlis.cs
@@ -19,7 +19,7 @@
         {
             get
             {
-                if(apiUtlis == null)
+                if (apiUtlis == null)
                 {
                     apiUtlis = new ApiUtlis();
                 }
@@ -33,7 +33,7 @@
         {
             get
             {
-                if(httpRequest == null)
+                if (httpRequest == null)
                 {
                     httpRequest = new HttpServerRequest();
                 }
@@ -47,7 +47,7 @@
         {
             bool result = DB_ResidenceData.Instance.HomeGateway.gatewayStatus;
 
-            if(!result)
+            if (!result)
             {
 
             }
@@ -55,7 +55,7 @@
             return result;
         }
 
-        public bool DownloadDataComplete = false;
+        public bool DownloadDataComplete = true;
         /// <summary>
         /// 涓嬭浇鏁版嵁
         /// </summary>
@@ -64,18 +64,21 @@
             if (MainPage.InternetStatus == 0)
                 return;
             //绾跨▼寮�濮嬫椂闂�
-            var beginTime = DateTime.MinValue;
+            var endTime = DateTime.Now.AddSeconds(6);
+
+            MainPage.Log($"寮�濮嬪悓姝ヤ簯绔暟鎹�");
 
             DownloadDataComplete = false;
 
             var waitPage = new Loading();
             MainPage.BaseView.AddChidren(waitPage);
-            waitPage.Start();
+            waitPage.Start(Language.StringByID(StringId.PleaseWait));
 
             string code = StateCode.SUCCESS;
 
             var downloadDataThread = new System.Threading.Thread(() =>
             {
+                MainPage.Log($"杩涘叆璇诲彇浜戠鏁版嵁绾跨▼");
                 //===================鍒锋柊Token=======================
                 code = Ins.HttpRequest.RefreshToken();
                 if (code != StateCode.SUCCESS)
@@ -128,9 +131,12 @@
                     {
                         MainPage.Log($"璇诲彇鎴块棿淇℃伅鎴愬姛");
                         var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(roomResult.Data.ToString());
-                        if (revData != null)
+                        if (revData == null)
                         {
-                            SpatialInfo.CurrentSpatial.UpdateSpatialList(revData.list, OptionType.Cover);
+                            revData = new SpatialApiPack();
+                        }
+                        {
+                            SpatialInfo.CurrentSpatial.UpdateSpatialList(revData.list);
                         }
                     }
                     else
@@ -143,7 +149,10 @@
                     {
                         MainPage.Log($"璇诲彇璁惧淇℃伅鎴愬姛");
                         var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
-                        if (deviceList != null)
+                        if (deviceList == null)
+                        {
+                            deviceList = new DevcieApiPack();
+                        }
                         {
                             if (FunctionList.List.GetDeviceFunctionList().Count > 0)
                             {
@@ -166,12 +175,13 @@
                                         i++;
                                         if (localFunction.modifyTime != newFunction.modifyTime)
                                         {
+                                            //鍙紭鍖�
                                             localFunction.name = newFunction.name;
                                             localFunction.collect = newFunction.collect;
                                             localFunction.modifyTime = newFunction.modifyTime;
                                             localFunction.roomIds = newFunction.roomIds;
                                             localFunction.bus = newFunction.bus;
-                                            localFunction.SaveFunctionData(false);
+                                            localFunction.SaveFunctionFile();
                                         }
                                         deviceList.list.Remove(newFunction);//鎿嶄綔瀹岀殑鏁版嵁娓呯悊鎺夛紝鍓╀笅鐨勫氨鏄柊澧炵殑鍔熻兘
                                     }
@@ -180,7 +190,7 @@
                             //澶勭悊鍓╀笅鐨勬柊澧炲姛鑳�
                             foreach (var newFunction in deviceList.list)
                             {
-                                newFunction.SaveFunctionData(false);
+                                newFunction.SaveFunctionFile();
                                 FunctionList.List.IniFunctionList(newFunction.savePath);
                             }
                         }
@@ -194,9 +204,12 @@
                     var pack = Ins.HttpRequest.GetSceneList();
                     if (pack.Code == StateCode.SUCCESS)
                     {
-                        MainPage.Log($"璇诲彇鍦烘櫙鏁版嵁鎴愬姛");//:\r\n{pack.Data.ToString()}");
+                        MainPage.Log($"璇诲彇鍦烘櫙鏁版嵁鎴愬姛");
                         var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
-                        if (sceneList != null)
+                        if (sceneList == null)
+                        {
+                            sceneList = new List<Scene>();
+                        }
                         {
                             for (int i = 0; i < FunctionList.List.scenes.Count;)
                             {
@@ -249,7 +262,8 @@
                 {
                     Application.RunOnMainThread(() =>
                     {
-                        beginTime = DateTime.Now;
+                        MainPage.Log($"缁撴潫璇诲彇浜戠鏁版嵁绾跨▼");
+                        endTime = DateTime.MinValue;
                         DownloadDataComplete = true;
                         waitPage.Hide();
                         waitPage.RemoveFromParent();
@@ -257,34 +271,48 @@
                 }
             });
             downloadDataThread.IsBackground = true;
+            downloadDataThread.Priority = System.Threading.ThreadPriority.Highest;
             downloadDataThread.Start();
 
             //缃戠粶鍗¢】锛岀粓姝笅杞界嚎绋�
-            new System.Threading.Thread(() => {
-                while (beginTime.AddSeconds(6) > DateTime.Now)
+            new System.Threading.Thread(() =>
+            {
+                try
                 {
-                    if(DownloadDataComplete)
+                    while (endTime > DateTime.Now)
                     {
-                        break;
+                        if (DownloadDataComplete)
+                        {
+                            break;
+                        }
+                        System.Threading.Thread.Sleep(100);
                     }
-                    System.Threading.Thread.Sleep(100);
-                }
-                if (DownloadDataComplete)
-                {
-                    //涓嬭浇瀹屾垚鍒濆鍖栨暟鎹�
-                    SpatialInfo.CurrentSpatial.Clear();
-                    
-
-                }
-                else
-                {
-                    downloadDataThread.Abort();
-                    Application.RunOnMainThread(() => {
+                    if (!DownloadDataComplete)
+                    {
+                        //downloadDataThread.Abort();
+                    }
+                    DownloadDataComplete = true;
+                    Application.RunOnMainThread(() =>
+                    {
                         waitPage.Hide();
                         waitPage.RemoveFromParent();
                     });
+                    //鍒濆鍖栨暟鎹�
+                    //SpatialInfo.CurrentSpatial.Clear();
+
                 }
-            }) { IsBackground = true }.Start();
+                catch { }
+                finally
+                {
+                    #region 璇诲彇鏈湴鏁版嵁
+                    //璇诲彇闊充箰淇℃伅
+                    UI.Music.A31MusicModel.ReadMusicStates();
+                    //鎼滅储缃戝叧
+                    DriverLayer.Control.Ins.SearchLoaclGateway();
+                    #endregion
+                }
+            })
+            { IsBackground = true }.Start();
         }
     }
-}
+}
\ No newline at end of file

--
Gitblit v1.8.0