wei
2020-12-24 22fcd0d263770c8371bd03ca53f097a6ec1678f7
HDL_ON/Entity/FunctionList.cs
@@ -191,7 +191,7 @@
            }
            if (filePath.StartsWith("SceneData_"))
            {
                var sceneDataBytes = Common.FileUtlis.Files.ReadFile(filePath);
                var sceneDataBytes = FileUtlis.Files.ReadFile(filePath);
                var sceneDataString = System.Text.Encoding.UTF8.GetString(sceneDataBytes);
                var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(sceneDataString);
                List.scenes.Add(tempScene);
@@ -376,129 +376,6 @@
            }
            return pack.Code;
        }
        /// <summary>
        /// 下来云端设备数据
        /// </summary>
        public void DownloadFunctionList()
        {
            new Thread(() =>
            {
                var pm = new HttpServerRequest();
                var pack = pm.GetDeviceList();
                if (pack.Code == StateCode.SUCCESS)
                {
                    var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(pack.Data.ToString());
                    if (deviceList != null)
                    {
                        if (List.GetDeviceFunctionList().Count > 0)
                        {
                            for (int i = 0; i < List.GetDeviceFunctionList().Count;)
                            {
                                var localFunction = List.GetDeviceFunctionList()[i];
                                if (localFunction.functionCategory == FunctionCategory.Music)
                                {
                                    i++;
                                    continue;
                                }
                                var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
                                if (newFunction == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录
                                {
                                    List.DeleteFunction(localFunction);
                                }
                                else
                                {
                                    MainPage.Log($"deviceType:{localFunction.spk} local:{localFunction.modifyTime} server:{newFunction.modifyTime}");
                                    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.SaveFunctionFile();
                                    }
                                    deviceList.list.Remove(newFunction);//操作完的数据清理掉,剩下的就是新增的功能
                                }
                            }
                        }
                        //处理剩下的新增功能
                        foreach (var newFunction in deviceList.list)
                        {
                            newFunction.SaveFunctionFile();
                            List.IniFunctionList(newFunction.savePath);
                        }
                    }
                    //MainPage.Log($"读取云端设备数据:\r\n{ pack.Data.ToString()}");
                }
                else
                {
                    MainPage.Log($"读取云端设备数据失败:\r\nCode:{pack.Code};  Msg:{pack.message}");
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 下载云端场景数据
        /// </summary>
        public void DownloadSceneList()
        {
            new Thread(() =>
            {
                var pm = new HttpServerRequest();
                var pack = pm.GetSceneList();
                if(pack.Code == StateCode.SUCCESS)
                {
                    //MainPage.Log($"读取云端场景数据:\r\n{pack.Data.ToString()}");
                    var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
                    if (sceneList != null)
                    {
                        for (int i=0;i<List.scenes.Count;)
                        {
                            var localScene = List.scenes[i];
                            if (localScene == null)
                            {
                                List.scenes.Remove(localScene);
                                continue;
                            }
                            var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                            if (newScene == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录
                            {
                                List.DeleteScene(localScene,false);
                            }
                            else
                            {
                                i++;
                                if (localScene.modifyTime != newScene.modifyTime)
                                {
                                    localScene.name = newScene.name;
                                    localScene.collect = newScene.collect;
                                    localScene.modifyTime = newScene.modifyTime;
                                    localScene.roomIds = newScene.roomIds;
                                    localScene.SaveSceneFile();
                                }
                                sceneList.Remove(newScene);//操作完的数据清理掉,剩下的就是新增的功能
                            }
                        }
                        //处理剩下的新增功能
                        foreach (var newScene in sceneList)
                        {
                            newScene.SaveSceneFile();
                            List.scenes.Add(newScene);
                        }
                    }
                }
                else
                {
                    MainPage.Log($"读取云端场景数据失败:\r\nCode:{pack.Code};  Msg:{pack.message}");
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 删除场景