2
wei
2021-03-09 d41f1d4a478c1afcc43f3a5abb0ba76e376bc7c1
HDL_ON/Common/ApiUtlis.cs
@@ -46,7 +46,7 @@
        public bool GatewayOnlineVerification()
        {
            bool result = DB_ResidenceData.Instance.HomeGateway.gatewayStatus;
            DriverLayer.Control.Ins.GatewayOnline_Cloud = result;
            if (!result)
            {
@@ -159,44 +159,59 @@
                        {
                            deviceList = new DevcieApiPack();
                        }
                            if (FunctionList.List.GetDeviceFunctionList().Count > 0)
                            {
                        string delFile = "";
                        if (FunctionList.List.GetDeviceFunctionList().Count > 0)
                        {
                            for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;)
                            {
                                var localFunction = FunctionList.List.GetDeviceFunctionList()[i];
                                if (localFunction.functionCategory == FunctionCategory.Music)
                                if (localFunction.Spk_Prefix == FunctionCategory.Music || string.IsNullOrEmpty(localFunction.Spk_Prefix))
                                {
                                    i++;
                                    continue;
                                }
                                var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
                                if (newFunction == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录
                                //if (newFunction == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录
                                //{
                                //    FunctionList.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();
                                //    //}
                                //    localFunction = newFunction;
                                //    localFunction.SaveFunctionFile();
                                //    deviceList.list.Remove(newFunction);//操作完的数据清理掉,剩下的就是新增的功能
                                //}
                                if (delFile == localFunction.savePath)
                                {
                                    FunctionList.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);//操作完的数据清理掉,剩下的就是新增的功能
                                    continue;
                                }
                                delFile = localFunction.savePath;
                                FunctionList.List.DeleteFunction(localFunction);
                            }
                            //处理剩下的新增功能
                            foreach (var newFunction in deviceList.list)
                            {
                                newFunction.SaveFunctionFile();
                                FunctionList.List.IniFunctionList(newFunction.savePath);
                            }
                        }
                        //处理剩下的新增功能
                        foreach (var newFunction in deviceList.list)
                        {
                            newFunction.SaveFunctionFile();
                            FunctionList.List.IniFunctionList(newFunction.savePath);
                        }
                        endTime = DateTime.Now.AddSeconds(5);
                    }
@@ -216,15 +231,15 @@
                        {
                            sceneList = new List<Scene>();
                        }
                            for (int i = 0; i < FunctionList.List.scenes.Count;)
                        for (int i = 0; i < FunctionList.List.scenes.Count;)
                        {
                            var localScene = FunctionList.List.scenes[i];
                            if (localScene == null)
                            {
                                var localScene = FunctionList.List.scenes[i];
                                if (localScene == null)
                                {
                                    FunctionList.List.scenes.Remove(localScene);
                                    continue;
                                }
                                var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                                FunctionList.List.scenes.Remove(localScene);
                                continue;
                            }
                            var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                            if (newScene == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录
                            {
                                FunctionList.List.DeleteScene(localScene, false);
@@ -238,16 +253,17 @@
                                    localScene.collect = newScene.collect;
                                    localScene.modifyTime = newScene.modifyTime;
                                    localScene.roomIds = newScene.roomIds;
                                    localScene.image = newScene.image;
                                    localScene.SaveSceneFile();
                                }
                                sceneList.Remove(newScene);//操作完的数据清理掉,剩下的就是新增的功能
                            }
                            //处理剩下的新增功能
                            foreach (var tempScene in sceneList)
                            {
                                tempScene.SaveSceneFile();
                                FunctionList.List.scenes.Add(tempScene);
                            }
                        }
                        //处理剩下的新增功能
                        foreach (var tempScene in sceneList)
                        {
                            tempScene.SaveSceneFile();
                            FunctionList.List.scenes.Add(tempScene);
                        }
                        //如果是一端口需要提前下载场景数据,否则控制不了一端口场景
                        if (DB_ResidenceData.Instance.GatewayType == 0)
@@ -300,6 +316,10 @@
                        waitPage.Hide();
                        waitPage.RemoveFromParent();
                    });
                    //不考虑网关情况,直接订阅
                    DAL.Mqtt.MqttClient.InitState();
                    FunctionList.List.Read3tyFunctionStatus();
                }
            });
            downloadDataThread.IsBackground = true;