wxr
2024-09-23 b2f25bfca6471fe3bfa041da8e4a1d01fd00f6ed
HDL_ON/Common/ApiUtlis.cs
@@ -73,6 +73,11 @@
        /// </summary>
        public bool DownloadDataComplete = false;
        /// <summary>
        /// token是否有效
        /// </summary>
        public bool tokenInvalid = false;
        public bool hadInternet = true;
        /// <summary>
        /// 下载数据
@@ -127,7 +132,7 @@
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"{this.GetType()}:加载缓存房间数据异常:{ex.Message}");
                            MainPage.Log("Error",$"{this.GetType()}:加载缓存房间数据异常:{ex.StackTrace}");
                        }
                        try
@@ -141,10 +146,8 @@
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"{this.GetType()}:加载缓存设备数据异常:{ex.Message}");
                            MainPage.Log("Error", $"{this.GetType()}:加载缓存设备数据异常:{ex.StackTrace}");
                        }
                        return;
                    }
                    else
@@ -154,7 +157,7 @@
                }
                catch (Exception ex)
                {
                    MainPage.Log($"Error:下载数据1:{ex.Message}");
                    MainPage.Log("Error", $"下载数据1:{ex.StackTrace}");
                    DownloadDataComplete = true;
                    return;
                }
@@ -177,6 +180,48 @@
                code = Ins.HttpRequest.RefreshToken();
                if (code != StateCode.SUCCESS)
                {
                    DownloadDataComplete = true;
                    hadInternet = false;
                    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("Error", $"{this.GetType()}:加载缓存房间数据异常:{ex.StackTrace}");
                    }
                    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("Error", $"{this.GetType()}:加载缓存设备数据异常:{ex.StackTrace}");
                    }
                    MainPage.Log($"刷新token失败");
                    return;
                }
                else
                {
                    hadInternet = true;
                }
                if (code != StateCode.SUCCESS)
                {
                    if (waitPage != null)
                    {
                        Application.RunOnMainThread(() =>
@@ -190,7 +235,6 @@
                            catch { }
                        });
                    }
                    MainPage.Log($"刷新token失败");
                    return;
                }
                MainPage.Log($"刷新token成功");
@@ -277,9 +321,10 @@
                                {
                                    var ssd = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(revData.list));
                                    FileUtlis.Files.WriteFileByBytes("SpatialInfoData", ssd);
                                }catch(Exception ex)
                                }
                                catch (Exception ex)
                                {
                                    MainPage.Log($"{this.GetType()}:保存房间信息异常:{ex.Message}");
                                    MainPage.Log("Error", $"{this.GetType()}:保存房间信息异常:{ex.StackTrace}");
                                }
                            })
                            { IsBackground = true }.Start();
@@ -301,7 +346,7 @@
                            {
                                FunctionList.List.ClearDatas();
                                MainPage.Log($"读取设备信息成功");
                                MainPage.Log($"sid列表获取====\r\n" , deviceResult.Data.ToString());
                                MainPage.Log($"sid列表获取====\r\n", deviceResult.Data.ToString());
                                var deviceList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                if (deviceList == null)
                                {
@@ -325,7 +370,7 @@
                                }
                                finally
                                {
                                }
                                string delFile = "";
@@ -356,8 +401,8 @@
                                foreach (var newFunction in deviceList.list)
                                {
                                    newFunction.AssembleStatus();
                                    newFunction.SaveFunctionFile();
                                    FunctionList.List.IniFunctionList(newFunction.savePath,true);
                                    newFunction.SaveFunctionFile();
                                    FunctionList.List.IniFunctionList(newFunction.savePath, true);
                                    //MainPage.Log($"============设备============{iiii++}");
                                }
@@ -380,7 +425,7 @@
                                    string videoList = videoInfo.Data.ToString();
                                    FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(videoList);
                                    for(int i =0;i< FunctionList.List.videoIntercom.Count;i++)
                                    for (int i = 0; i < FunctionList.List.videoIntercom.Count; i++)
                                    {
                                        var video = FunctionList.List.videoIntercom[i];
@@ -404,7 +449,7 @@
                                                --i;
                                            }catch(Exception ex)
                                            {
                                                MainPage.Log($"ios 全视通异常 : {ex.Message}");
                                                MainPage.Log("Error", $"ios 全视通异常 : {ex.StackTrace}");
                                            }
#else
@@ -423,7 +468,7 @@
                                //如果检测线程没启动,才继续下面操作 因为App有可能刚启动马上收到推送了,然后才执行到这里
                                if (HDLLinphone.Current.CheckIncomingCallThreadIsNull())
                                {
                                    //当前住宅是HDL可视对讲类型的设备
                                    if (isInterphoneType_HDL)
                                    {
@@ -480,16 +525,16 @@
                            {
                                MainPage.Log($"读取云端设备数据失败:Code:{deviceResult.Code};  Msg:{deviceResult.message}");
                            }
                        }catch (Exception ex)
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"============设备============{ex.Message}");
                            MainPage.Log("Error", $"============设备============{ex.StackTrace}");
                        }
                        finally
                        {
                            complateDevice = true;
                            MainPage.Log($"============设备============完成" + FunctionList.List.Functions.Count);
                        }
                        //======================群控====================
                        if (DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl)
@@ -503,16 +548,16 @@
                                    {
                                        var groupControlList = JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
                                        var readSidList = new List<string>();
                                        foreach(var temp in groupControlList)
                                        foreach (var temp in groupControlList)
                                        {
                                            FunctionList.List.groupControls.Clear();
                                            readSidList.Add(temp.userDeviceGroupControlId);
                                            if (readSidList.Count >= 20)
                                            {
                                                var data = Ins.httpRequest.GetGroupControInfo(readSidList);
                                                if(data != null)
                                                if (data != null)
                                                {
                                                    if(data.Code == StateCode.SUCCESS)
                                                    if (data.Code == StateCode.SUCCESS)
                                                    {
                                                        var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString());
                                                        FunctionList.List.groupControls.AddRange(groupControlInfoList);
@@ -546,7 +591,7 @@
                                    }
                                    catch (Exception ex)
                                    {
                                        MainPage.Log($"读取组控列表失败:{ex.Message}");
                                        MainPage.Log("Error", $"读取组控列表失败:{ex.StackTrace}");
                                    }
                                }
                                else
@@ -608,9 +653,10 @@
                            {
                                MainPage.Log($"读取云端场景数据失败:Code:{pack.Code}; Msg:{pack.message}");
                            }
                        }catch(Exception ex)
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"===场景==={ex.Message}");
                            MainPage.Log("Error", $"===场景==={ex.StackTrace}");
                        }
                        finally
                        {
@@ -631,7 +677,7 @@
                }
                catch (Exception ex)
                {
                    MainPage.Log($"数据初始化失败:{ex.Message}");
                    MainPage.Log("Error", $"数据初始化失败:{ex.StackTrace}");
                }
                finally
                {
@@ -650,9 +696,10 @@
                    try
                    {
                        FunctionList.List.Read3tyFunctionStatus();
                    }catch(Exception ex)
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log("读取第三方设备状态失败:"+ex.Message);
                        MainPage.Log("Error", "读取第三方设备状态失败:" + ex.StackTrace);
                    }
                }
            });
@@ -688,13 +735,18 @@
                {
                    if (DB_ResidenceData.Instance.CurrentRegion != null)
                    {
#region 读取本地数据
                        //搜索网关
                        DriverLayer.Control.Ins.SearchLoaclGateway();
                        //重新连接mqtt
                        DAL.Mqtt.MqttClient.DisConnectRemote("刷新数据,重连mqtt",false);
#endregion
                        try
                        {
                            #region 读取本地数据
                            //搜索网关
                            DriverLayer.Control.Ins.SearchLoaclGateway();
                            //重新连接mqtt
                            DAL.Mqtt.MqttClient.DisConnectRemote("刷新数据,重连mqtt", false);
                            #endregion
                        }
                        catch (Exception ex){
                            MainPage.Log("Error", $"读取本地数据异常:{ex.StackTrace}");
                        }
                    }
                }
            })
@@ -774,4 +826,5 @@
    }
}
}