wxr
2022-09-30 88a66f8374d63fbe9403258a9faa0fdcacf96571
HDL_ON/Common/ApiUtlis.cs
@@ -43,6 +43,15 @@
            }
        }
        /// <summary>
        /// 读取设备功能数据完成
        /// </summary>
        bool complateDevice = false;
        /// <summary>
        /// 读取场景数据完成
        /// </summary>
        bool complateScene = false;
        /// <summary>
        /// 校验网关是否在线
        /// </summary>
        public bool GatewayOnlineVerification()
@@ -152,125 +161,161 @@
                    {
                        MainPage.Log($"读取房间数据失败:Code:{roomResult.Code}; msg:{roomResult.message}");
                    }
                    //===================设备=======================
                    var deviceResult = Ins.HttpRequest.GetDeviceList("30","1");
                    if (deviceResult.Code == StateCode.SUCCESS)
                    {
                        endTime = DateTime.Now.AddSeconds(5);
                        MainPage.Log($"读取设备信息成功");
                        MainPage.Log($"sid列表获取===="+ deviceResult.Data.ToString());
                        var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                        if (deviceList == null)
                        {
                            deviceList = new DevcieApiPack();
                        }
                    //===================设备=======================
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            while (deviceList.totalPage != deviceList.pageNo)
                            complateDevice = false;
                            var deviceResult = Ins.HttpRequest.GetDeviceList("30", "1");
                            if (deviceResult.Code == StateCode.SUCCESS)
                            {
                                var deviceResult2 = Ins.HttpRequest.GetDeviceList("30", Convert.ToInt32(deviceList.pageNo) + 1 + "");
                                if (deviceResult2.Code == StateCode.SUCCESS)
                                endTime = DateTime.Now.AddSeconds(5);
                                MainPage.Log($"读取设备信息成功");
                                MainPage.Log($"sid列表获取====" + deviceResult.Data.ToString());
                                var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                if (deviceList == null)
                                {
                                    var deviceList2 = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                    deviceList.pageNo = deviceList2.pageNo;
                                    deviceList.list.AddRange(deviceList2.list);
                                    deviceList = new DevcieApiPack();
                                }
                            }
                        }catch(Exception ex)
                        {
                        }
                        string delFile = "";
                        if (FunctionList.List.GetDeviceFunctionList().Count > 0)
                        {
                            for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;)
                            {
                                var localFunction = FunctionList.List.GetDeviceFunctionList()[i];
                                //if (SPK.MusicSpkList().Contains(localFunction.spk))
                                //{
                                //    i++;
                                //    continue;
                                //}
                                var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
                                if (delFile == localFunction.savePath)
                                try
                                {
                                    i++;
                                    continue;
                                }
                                delFile = localFunction.savePath;
                                FunctionList.List.DeleteFunction(localFunction);
                            }
                        }
                        //处理剩下的新增功能
                        foreach (var newFunction in deviceList.list)
                        {
                            newFunction.AssembleStatus();
                            newFunction.SaveFunctionFile();
                            FunctionList.List.IniFunctionList(newFunction.savePath);
                        }
                        endTime = DateTime.Now.AddSeconds(5);
                    }
                    else
                    {
                        MainPage.Log($"读取云端设备数据失败:Code:{deviceResult.Code};  Msg:{deviceResult.message}");
                    }
                    //===================场景==========================
                    var pack = Ins.HttpRequest.GetSceneList();
                    if (pack.Code == StateCode.SUCCESS)
                    {
                        endTime = DateTime.Now.AddSeconds(100);
                        MainPage.Log($"读取场景数据成功");
                        var sceneList = JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
                        if (sceneList == null)
                        {
                            sceneList = new List<Scene>();
                        }
                        FunctionList.List.scenes.Clear();
                        //处理剩下的新增功能
                        foreach (var tempScene in sceneList)
                        {
                            tempScene.SaveSceneFile();
                            FunctionList.List.scenes.Add(tempScene);
                        }
                        //如果是一端口需要提前下载场景数据,否则控制不了一端口场景
                        if (DB_ResidenceData.Instance.GatewayType == 0)
                        {
                            var sceneIds = new List<string>();
                            foreach (var tempScene in FunctionList.List.scenes)
                            {
                                sceneIds.Add(tempScene.userSceneId);
                            }
                            var packInfo = HttpRequest.GetSceneListInfo(sceneIds);
                            if (packInfo.Code == StateCode.SUCCESS)
                            {
                                var serverTempList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(packInfo.Data.ToString());
                                foreach (var localScene in FunctionList.List.scenes)
                                {
                                    var serverTemp = serverTempList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                                    if (serverTemp != null)
                                    while (deviceList.totalPage != deviceList.pageNo)
                                    {
                                        localScene.functions = serverTemp.functions;
                                        localScene.SaveSceneFile();
                                        var deviceResult2 = Ins.HttpRequest.GetDeviceList("30", Convert.ToInt32(deviceList.pageNo) + 1 + "");
                                        if (deviceResult2.Code == StateCode.SUCCESS)
                                        {
                                            var deviceList2 = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                            deviceList.pageNo = deviceList2.pageNo;
                                            deviceList.list.AddRange(deviceList2.list);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                }
                                finally
                                {
                                    complateDevice = true;
                                }
                                string delFile = "";
                                if (FunctionList.List.GetDeviceFunctionList().Count > 0)
                                {
                                    for (int i = 0; i < FunctionList.List.GetDeviceFunctionList().Count;)
                                    {
                                        var localFunction = FunctionList.List.GetDeviceFunctionList()[i];
                                        //if (SPK.MusicSpkList().Contains(localFunction.spk))
                                        //{
                                        //    i++;
                                        //    continue;
                                        //}
                                        var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId);
                                        if (delFile == localFunction.savePath)
                                        {
                                            i++;
                                            continue;
                                        }
                                        delFile = localFunction.savePath;
                                        FunctionList.List.DeleteFunction(localFunction);
                                    }
                                }
                                //处理剩下的新增功能
                                foreach (var newFunction in deviceList.list)
                                {
                                    newFunction.AssembleStatus();
                                    newFunction.SaveFunctionFile();
                                    FunctionList.List.IniFunctionList(newFunction.savePath);
                                }
                                endTime = DateTime.Now.AddSeconds(5);
                            }
                            else
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(packInfo.Code);
                                MainPage.Log($"读取云端设备数据失败:Code:{deviceResult.Code};  Msg:{deviceResult.message}");
                            }
                        }catch (Exception ex)
                        {
                            MainPage.Log($"============设备============{ex.Message}");
                        }
                        endTime = DateTime.Now.AddSeconds(5);
                    }
                    else
                        finally
                        {
                            complateDevice = true;
                        }
                    })
                    { IsBackground = true }.Start();
                    //===================场景==========================
                    new System.Threading.Thread(() =>
                    {
                        MainPage.Log($"读取云端场景数据失败:Code:{pack.Code}; Msg:{pack.message}");
                    }
                        try
                        {
                            complateScene = true;
                            var pack = Ins.HttpRequest.GetSceneList();
                            if (pack.Code == StateCode.SUCCESS)
                            {
                                endTime = DateTime.Now.AddSeconds(100);
                                MainPage.Log($"读取场景数据成功");
                                var sceneList = JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString());
                                if (sceneList == null)
                                {
                                    sceneList = new List<Scene>();
                                }
                                FunctionList.List.scenes.Clear();
                                //处理剩下的新增功能
                                foreach (var tempScene in sceneList)
                                {
                                    tempScene.SaveSceneFile();
                                    FunctionList.List.scenes.Add(tempScene);
                                }
                                //如果是一端口需要提前下载场景数据,否则控制不了一端口场景
                                if (DB_ResidenceData.Instance.GatewayType == 0)
                                {
                                    var sceneIds = new List<string>();
                                    foreach (var tempScene in FunctionList.List.scenes)
                                    {
                                        sceneIds.Add(tempScene.userSceneId);
                                    }
                                    var packInfo = HttpRequest.GetSceneListInfo(sceneIds);
                                    if (packInfo.Code == StateCode.SUCCESS)
                                    {
                                        var serverTempList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(packInfo.Data.ToString());
                                        foreach (var localScene in FunctionList.List.scenes)
                                        {
                                            var serverTemp = serverTempList.Find((obj) => obj.userSceneId == localScene.userSceneId);
                                            if (serverTemp != null)
                                            {
                                                localScene.functions = serverTemp.functions;
                                                localScene.SaveSceneFile();
                                            }
                                        }
                                    }
                                    else
                                    {
                                        IMessageCommon.Current.ShowErrorInfoAlter(packInfo.Code);
                                    }
                                }
                                endTime = DateTime.Now.AddSeconds(5);
                            }
                            else
                            {
                                MainPage.Log($"读取云端场景数据失败:Code:{pack.Code}; Msg:{pack.message}");
                            }
                        }catch(Exception ex)
                        {
                            MainPage.Log($"===场景==={ex.Message}");
                        }
                        finally
                        {
                            complateScene = true;
                        }
                    })
                    { IsBackground = true }.Start();
                    //===================读取逻辑列表==========================
                    UI.UI2.Intelligence.Automation.MainView.GetLogicList();
@@ -400,10 +445,6 @@
                        }
                        System.Threading.Thread.Sleep(100);
                    }
                    if (!DownloadDataComplete)
                    {
                        //downloadDataThread.Abort();
                    }
                    DownloadDataComplete = true;
                    Application.RunOnMainThread(() =>
                    {
@@ -413,9 +454,6 @@
                            waitPage = null;
                        }
                    });
                    //初始化数据
                    //SpatialInfo.CurrentSpatial.Clear();
                }
                catch { }
                finally