From 488efb508eb0648773fe7b68e810e04bcd7ca075 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期五, 11 十二月 2020 15:58:15 +0800
Subject: [PATCH] 20201211

---
 HDL_ON/Entity/FunctionList.cs |   81 ++++++++++++++++++++++++++++++----------
 1 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/HDL_ON/Entity/FunctionList.cs b/HDL_ON/Entity/FunctionList.cs
index 22da38f..fcc971a 100644
--- a/HDL_ON/Entity/FunctionList.cs
+++ b/HDL_ON/Entity/FunctionList.cs
@@ -18,7 +18,7 @@
                 {
                     _FunctionList = new FunctionList();
                     #region 鎭㈠鏁版嵁
-                    var filePathList = FileUtils.ReadFiles();
+                    var filePathList = Common.FileUtlis.Files.ReadFiles();
                     foreach (var filePath in filePathList)
                     {
                         _FunctionList.IniFunctionList(filePath);
@@ -109,9 +109,14 @@
         {
             if (filePath.StartsWith("FunctionData_"))
             {
-                var functionDataBytes = FileUtils.ReadFile(filePath);
+                var functionDataBytes = Common.FileUtlis.Files.ReadFile(filePath);
                 var functionDataString = System.Text.Encoding.UTF8.GetString(functionDataBytes);
                 var tempFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString);
+                if (tempFunction == null)
+                {
+                    Common.FileUtlis.Files.DeleteFile(filePath);
+                    return;
+                }
                 if (tempFunction.DeleteSign)
                 {
                     //todo 鍒犻櫎浜戠鏁版嵁 20201203--App涓嶈兘鍒犻櫎鍔熻兘鏁版嵁
@@ -165,7 +170,7 @@
             }
             if (filePath.StartsWith("SceneData_"))
             {
-                var sceneDataBytes = FileUtils.ReadFile(filePath);
+                var sceneDataBytes = Common.FileUtlis.Files.ReadFile(filePath);
                 var sceneDataString = System.Text.Encoding.UTF8.GetString(sceneDataBytes);
                 var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(sceneDataString);
                 List.scenes.Add(tempScene);
@@ -344,6 +349,24 @@
         }
 
         /// <summary>
+        /// 鍔熻兘缁戝畾鎴块棿
+        /// </summary>
+        public string FunctionsBindRooms(List<string> roomIds,List<string> deviceIds)
+        {
+            var pm = new HttpServerRequest();
+            var pack = pm.BindDeviceToRoom(deviceIds, roomIds);
+            if(pack.Code == StateCode.SUCCESS)
+            {
+
+            }
+            else
+            {
+                Utlis.ShowTip(Shared.Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code);
+            }
+            return pack.Code;
+        }
+
+        /// <summary>
         /// 涓嬫潵浜戠璁惧鏁版嵁
         /// </summary>
         public void DownloadFunctionList()
@@ -365,8 +388,9 @@
                         //    }
                         //})
                         //{ IsBackground = true }.Start();
-                        foreach (var localFunction in List.GetAllDeviceFunctionList())
+                        for (int i =0;i < List.GetAllDeviceFunctionList().Count;)
                         {
+                            var localFunction = List.GetAllDeviceFunctionList()[i];
                             var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
                             if (newFunction == null)//濡傛灉浜戠鏈�鏂版暟鎹病鏈夎鏉℃暟鎹紝鍒欐湰鍦伴渶瑕佸垹鎺夎鏁版嵁璁板綍
                             {
@@ -374,6 +398,7 @@
                             }
                             else
                             {
+                                i++;
                                 if (localFunction.modifyTime != newFunction.modifyTime)
                                 {
                                     localFunction.name = newFunction.name;
@@ -393,7 +418,7 @@
                             List.IniFunctionList(newFunction.savePath);
                         }
                     }
-                    MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁:\r\n{ pack.Data.ToString()}");
+                    //MainPage.Log($"璇诲彇浜戠璁惧鏁版嵁:\r\n{ pack.Data.ToString()}");
                 }
                 else
                 {
@@ -414,7 +439,7 @@
                 var pack = pm.GetSceneList();
                 if(pack.Code == StateCode.SUCCESS)
                 {
-                    MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁:\r\n{pack.Data.ToString()}");
+                    //MainPage.Log($"璇诲彇浜戠鍦烘櫙鏁版嵁:\r\n{pack.Data.ToString()}");
                     var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
                     if (sceneList != null)
                     {
@@ -426,8 +451,9 @@
                         //    }
                         //})
                         //{ IsBackground = true }.Start();
-                        foreach (var localScene in List.scenes)
+                        for(int i=0;i<List.scenes.Count;)
                         {
+                            var localScene = List.scenes[i];
                             var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                             if (newScene == null)//濡傛灉浜戠鏈�鏂版暟鎹病鏈夎鏉℃暟鎹紝鍒欐湰鍦伴渶瑕佸垹鎺夎鏁版嵁璁板綍
                             {
@@ -435,6 +461,7 @@
                             }
                             else
                             {
+                                i++;
                                 if (localScene.modifyTime != newScene.modifyTime)
                                 {
                                     localScene.name = newScene.name;
@@ -468,12 +495,12 @@
         /// </summary>
         public void DelAllFunctionData()
         {
-            var filePathList = FileUtils.ReadFiles();
+            var filePathList = Common.FileUtlis.Files.ReadFiles();
             foreach (var filePath in filePathList)
             {
                 if (filePath.StartsWith("FunctionData_") && filePath.Length == 13 + 28)
                 {
-                    FileUtils.DeleteFile(filePath);
+                    Common.FileUtlis.Files.DeleteFile(filePath);
                 }
             }
             _FunctionList = new FunctionList();
@@ -489,7 +516,7 @@
                 var packCode = pm.DeleteScene(scene.userSceneId);
                 if (packCode == StateCode.SUCCESS)
                 {
-                    FileUtils.DeleteFile(scene.savePath);
+                    Common.FileUtlis.Files.DeleteFile(scene.savePath);
                     List.scenes.Remove(scene);
                 }
                 else
@@ -499,7 +526,7 @@
             }
             else
             {
-                FileUtils.DeleteFile(scene.savePath);
+                Common.FileUtlis.Files.DeleteFile(scene.savePath);
                 List.scenes.Remove(scene);
             }
         }
@@ -546,7 +573,7 @@
                     _FunctionList.fans.Remove(_FunctionList.fans.Find((obj) => obj.deviceId == delTemp.deviceId));
                     break;
             }
-            FileUtils.DeleteFile(delTemp.savePath);
+            Common.FileUtlis.Files.DeleteFile(delTemp.savePath);
         }
 
         bool lockReadFunctionStatus = false;
@@ -571,17 +598,29 @@
                 lockReadFunctionStatus = true;
                 try
                 {
-                    foreach (var function in GetAllDeviceFunctionList())
+                    if (DriverLayer.Control.Ins.IsRemote)
                     {
-                        switch (function.functionCategory)
+                        var functionIds = new List<string>();
+                        foreach (var function in GetAllDeviceFunctionList())
                         {
-                            case FunctionCategory.Light:
-                            case FunctionCategory.Electrical:
-                            case FunctionCategory.SwitchDevice:
-                            case FunctionCategory.Curtain:
-                            case FunctionCategory.Thermostat:
-                                DriverLayer.Control.Ins.SendReadCommand(function);
-                                break;
+                            functionIds.Add(function.deviceId);
+                        }
+                        DriverLayer.Control.Ins.SendApiReadCommand(functionIds);
+                    }
+                    else
+                    {
+                        foreach (var function in GetAllDeviceFunctionList())
+                        {
+                            switch (function.functionCategory)
+                            {
+                                case FunctionCategory.Light:
+                                case FunctionCategory.Electrical:
+                                case FunctionCategory.SwitchDevice:
+                                case FunctionCategory.Curtain:
+                                case FunctionCategory.Thermostat:
+                                    DriverLayer.Control.Ins.SendReadCommand(function);
+                                    break;
+                            }
                         }
                     }
                 }

--
Gitblit v1.8.0