wxr
2024-04-22 7a5dc2a6d15d14f70b64310c597a05cfe97208bd
HDL_ON/Common/ApiUtlis.cs
@@ -6,6 +6,7 @@
using HDL_ON.Entity;
using HDL_ON.UI.UI2.FuntionControlView.Video;
using HDL_ON.UI.UI2.Intelligence.Automation;
using MyJar;
using Newtonsoft.Json;
using Shared;
@@ -77,7 +78,7 @@
        /// </summary>
        public void DownloadData()
        {
            if (MainPage.InternetStatus == 0 || MainPage.NoLoginMode)
            if (MainPage.NoLoginMode)
            {
                DownloadDataComplete = true;
                return;
@@ -97,6 +98,57 @@
            var downloadDataThread = new System.Threading.Thread(() =>
            {
                try
                {//增加3秒云服务器连接检测,连不上服务器的时候不刷新数据
                        var dataList = new List<GlobalRegionListRes>();
                        var requestJson = HttpUtil.GetSignRequestJson(new GetRegionListObj() { regionMark = HttpUtil.RegionMark });
                    var revertObj = HttpUtil.RequestHttpsPost(NewAPI.API_POST_GlobalRegionList, requestJson, HttpUtil.GlobalRequestHttpsHost, "", 3);
                    if (revertObj == null || revertObj.Code != StateCode.SUCCESS)
                    {
                        DownloadDataComplete = true;
                        try
                        {
                            var spatialInfoDataBytes = FileUtlis.Files.ReadFile("SpatialInfoData");
                            if (spatialInfoDataBytes != null)
                            {
                                var spatialInfoDataString = System.Text.Encoding.UTF8.GetString(spatialInfoDataBytes);
                                if (spatialInfoDataString != null && !string.IsNullOrEmpty(spatialInfoDataString))
                                {
                                    var spatialInfoDataList = JsonConvert.DeserializeObject<List<SpatialInfo>>(spatialInfoDataString);
                                    SpatialInfo.CurrentSpatial.UpdateSpatialList(spatialInfoDataList);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"{this.GetType()}:加载缓存房间数据异常:{ex.Message}");
                        }
                        try
                        {
                            var fileList = Common.FileUtlis.Files.ReadFiles();
                            foreach (var file in fileList)
                            {
                                FunctionList.List.IniFunctionList(file, true);
                            }
                            Room.CurrentSpatial.InitRoomListFunctions();
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"{this.GetType()}:加载缓存设备数据异常:{ex.Message}");
                        }
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"Error:下载数据1:{ex.Message}");
                    DownloadDataComplete = true;
                    return;
                }
                MainPage.Log($"进入读取云端数据线程");
                //===================刷新Token=======================
                code = Ins.HttpRequest.RefreshToken();