wxr
2023-02-15 7ff70bc7c9460c395b59952d55df6e5d6a12a718
HDL_ON/Common/ApiUtlis.cs
@@ -51,6 +51,8 @@
        /// 读取场景数据完成
        /// </summary>
        bool complateScene = false;
        //线程结束时间
        DateTime endTime1;
        /// <summary>
        /// 校验网关是否在线
@@ -69,7 +71,7 @@
        /// <summary>
        /// 下载数据完成标记
        /// </summary>
        public bool DownloadDataComplete = true;
        public bool DownloadDataComplete = false;
        /// <summary>
        /// 下载数据
        /// </summary>
@@ -77,8 +79,8 @@
        {
            if (MainPage.InternetStatus == 0 || MainPage.NoLoginMode)
                return;
            //线程开始时间
            var endTime = DateTime.Now.AddSeconds(5);
            endTime1 = DateTime.Now.AddSeconds(25);
            complateDevice = complateScene = false;
            MainPage.Log($"开始同步云端数据");
@@ -102,7 +104,6 @@
                    MainPage.Log($"刷新token失败");
                    return;
                }
                endTime = DateTime.Now.AddSeconds(5);
                MainPage.Log($"刷新token成功");
                //===================刷新住宅信息=======================
                code = Ins.HttpRequest.GetHomePager();
@@ -111,7 +112,6 @@
                    MainPage.Log($"刷新住宅信息失败");
                    return;
                }
                endTime = DateTime.Now.AddSeconds(5);
                MainPage.Log($"刷新住宅信息成功");
                //===================刷新个人信息=======================
                code = Ins.HttpRequest.GetUserInfo();
@@ -120,7 +120,6 @@
                    MainPage.Log($"刷新个人信息失败");
                    return;
                }
                endTime = DateTime.Now.AddSeconds(5);
                MainPage.Log($"刷新个人信息成功");
                //int count = 0;
@@ -148,7 +147,6 @@
                    var roomResult = Ins.HttpRequest.GetRoomList();
                    if (roomResult.Code == StateCode.SUCCESS)
                    {
                        endTime = DateTime.Now.AddSeconds(100);
                        MainPage.Log($"读取房间信息成功");
                        var revData = Newtonsoft.Json.JsonConvert.DeserializeObject<SpatialApiPack>(roomResult.Data.ToString());
                        if (revData == null)
@@ -158,7 +156,6 @@
                        {
                            SpatialInfo.CurrentSpatial.UpdateSpatialList(revData.list);
                        }
                        endTime = DateTime.Now.AddSeconds(5);
                    }
                    else
                    {
@@ -174,11 +171,11 @@
                            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());
                                FunctionList.List.ClearDatas();
                                MainPage.Log($"============设备============开始" + FunctionList.List.Functions.Count);
                                //MainPage.Log($"读取设备信息成功");
                                //MainPage.Log($"sid列表获取====" + deviceResult.Data.ToString());
                                var deviceList = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                if (deviceList == null)
                                {
                                    deviceList = new DevcieApiPack();
@@ -190,7 +187,7 @@
                                        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());
                                            var deviceList2 = JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString());
                                            deviceList.pageNo = deviceList2.pageNo;
                                            deviceList.list.AddRange(deviceList2.list);
                                        }
@@ -198,11 +195,10 @@
                                }
                                catch (Exception ex)
                                {
                                }
                                finally
                                {
                                    complateDevice = true;
                                }
                                string delFile = "";
@@ -229,13 +225,101 @@
                                    }
                                }
                                //处理剩下的新增功能
                                int iiii = 0;
                                foreach (var newFunction in deviceList.list)
                                {
                                    newFunction.AssembleStatus();
                                    newFunction.SaveFunctionFile();
                                    FunctionList.List.IniFunctionList(newFunction.savePath);
                                    FunctionList.List.IniFunctionList(newFunction.savePath,true);
                                    MainPage.Log($"============设备============{iiii++}");
                                }
                                endTime = DateTime.Now.AddSeconds(5);
                                //===================读取可视对讲数据==========================
                                //判断是否有可视对讲数据,有则显示可视对讲icon
                                //var flVideoInfo = HttpRequest.CheckFlVideo();
                                //if(flVideoInfo.Code == StateCode.SUCCESS)
                                //{
                                //    FunctionList.List.videoIntercom1111 = Newtonsoft.Json.JsonConvert.DeserializeObject<UI.UI2.FuntionControlView.Video.VideoClouds>(flVideoInfo.Data.ToString());
                                //}
                                //======================获取可视对讲设备列表====================
                                bool isInterphoneType_HDL = false;//是否为HDLLinphone可视对讲
                                bool isInterphoneType_FREEVIEW = false;//是否为全视通可视对讲
                                var videoInfo = VideoSend.GetVideoInfoList();
                                if (videoInfo.Code == StateCode.SUCCESS)
                                {
                                    string videoList = videoInfo.Data.ToString();
                                    FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(videoList);
                                    foreach (var video in FunctionList.List.videoIntercom)
                                    {
                                        if (video.interphoneType == InterphoneType.IMOUVISIAL.ToString())
                                        {
                                            UI.UI2.PersonalCenter.PirDevice.PirSend.LcSubAccessToken = video.subAccountToken;
                                        }
                                        else if (video.interphoneType == InterphoneType.HDL.ToString())
                                        {
                                            isInterphoneType_HDL = true;
                                            DB_ResidenceData.Instance.SupportFacePass = true;
                                            DB_ResidenceData.Instance.SaveResidenceData();
                                            Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
                                        }
                                        else if (video.interphoneType == InterphoneType.FREEVIEW.ToString())
                                        {
                                            //为全视通可视对讲
                                            DB_ResidenceData.Instance.SupportFacePass = true;
                                            Entity.DB_ResidenceData.Instance.SupportVisitorManage = true;
                                            Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
                                            //isInterphoneType_HDL = true;
                                            isInterphoneType_FREEVIEW = true;
                                        }
                                    }
                                }
                                //======================获取Sip账号并且初始化SDK可视对讲设备列表====================
                                //如果检测线程没启动,才继续下面操作 因为App有可能刚启动马上收到推送了,然后才执行到这里
                                if (HDLLinphone.Current.CheckIncomingCallThreadIsNull())
                                {
                                    //当前住宅是HDL可视对讲类型的设备
                                    if (isInterphoneType_HDL)
                                    {
                                        //HDLLinphone可视对讲,获取Sip账号并初始化SDK
                                        HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
                                        callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
                                        callVideoInfo.InterphoneType = InterphoneType.HDL.ToString();
                                        HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo);
                                    }
                                    else if (isInterphoneType_FREEVIEW)
                                    {
                                        //HDLLinphone可视对讲,获取Sip账号并初始化SDK
                                        HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
                                        callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
                                        callVideoInfo.InterphoneType = InterphoneType.FREEVIEW.ToString();
                                        HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo);
                                    }
                                    else
                                    {
                                        Utlis.WriteLine("当前住宅不支持HDL可视对讲,退出登录所有账号");
                                        //当前住宅不支持HDL可视对讲
                                        HDLLinphone.Current.LogoutAllAccount();
                                    }
                                }
                                //======================登录全视通====================
                                if (isInterphoneType_FREEVIEW)
                                {
#if __IOS__
                        //登录全视通
                        Shared.IOS.HDLFVSDK.Video.Init("", DB_ResidenceData.Instance.CurrentRegion.id);
#endif
                                }
                            }
                            else
                            {
@@ -248,6 +332,7 @@
                        finally
                        {
                            complateDevice = true;
                            MainPage.Log($"============设备============完成" + FunctionList.List.Functions.Count);
                        }
                    })
                    { IsBackground = true }.Start();
@@ -257,11 +342,10 @@
                    {
                        try
                        {
                            complateScene = true;
                            complateScene = false;
                            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)
@@ -303,7 +387,6 @@
                                        IMessageCommon.Current.ShowErrorInfoAlter(packInfo.Code);
                                    }
                                }
                                endTime = DateTime.Now.AddSeconds(5);
                            }
                            else
                            {
@@ -324,85 +407,6 @@
                    Logic.LogicList.Clear();//主页下拉强制刷新自动化列表
                    //UI.UI2.Intelligence.Automation.MainView.GetLogicList();
                    //===================读取可视对讲数据==========================
                    //判断是否有可视对讲数据,有则显示可视对讲icon
                    //var flVideoInfo = HttpRequest.CheckFlVideo();
                    //if(flVideoInfo.Code == StateCode.SUCCESS)
                    //{
                    //    FunctionList.List.videoIntercom1111 = Newtonsoft.Json.JsonConvert.DeserializeObject<UI.UI2.FuntionControlView.Video.VideoClouds>(flVideoInfo.Data.ToString());
                    //}
                    //======================获取可视对讲设备列表====================
                    bool isInterphoneType_HDL = false;//是否为HDLLinphone可视对讲
                    bool isInterphoneType_FREEVIEW = false;//是否为全视通可视对讲
                    var videoInfo = VideoSend.GetVideoInfoList();
                    if (videoInfo.Code == StateCode.SUCCESS)
                    {
                        string videoList = videoInfo.Data.ToString();
                        FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(videoList);
                        foreach (var video in FunctionList.List.videoIntercom)
                        {
                            if (video.interphoneType == InterphoneType.IMOUVISIAL.ToString())
                            {
                                UI.UI2.PersonalCenter.PirDevice.PirSend.LcSubAccessToken = video.subAccountToken;
                            } else if (video.interphoneType == InterphoneType.HDL.ToString()) {
                                isInterphoneType_HDL = true;
                                DB_ResidenceData.Instance.SupportFacePass = true;
                                DB_ResidenceData.Instance.SaveResidenceData();
                                Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
                            }
                            else if (video.interphoneType == InterphoneType.FREEVIEW.ToString())
                            {
                                //为全视通可视对讲
                                DB_ResidenceData.Instance.SupportFacePass = true;
                                Entity.DB_ResidenceData.Instance.SupportVisitorManage = true;
                                Entity.DB_ResidenceData.Instance.SupportFVDevice = true;
                                //isInterphoneType_HDL = true;
                                isInterphoneType_FREEVIEW = true;
                            }
                        }
                    }
                    //======================获取Sip账号并且初始化SDK可视对讲设备列表====================
                    //如果检测线程没启动,才继续下面操作 因为App有可能刚启动马上收到推送了,然后才执行到这里
                    if (HDLLinphone.Current.CheckIncomingCallThreadIsNull()) {
                        //当前住宅是HDL可视对讲类型的设备
                        if (isInterphoneType_HDL)
                        {
                            //HDLLinphone可视对讲,获取Sip账号并初始化SDK
                            HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
                            callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
                            callVideoInfo.InterphoneType = InterphoneType.HDL.ToString();
                            HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo);
                        }
                        else if (isInterphoneType_FREEVIEW)
                        {
                            //HDLLinphone可视对讲,获取Sip账号并初始化SDK
                            HDLCallVideoInfo callVideoInfo = new HDLCallVideoInfo();
                            callVideoInfo.HomeId = DB_ResidenceData.Instance.CurrentRegion.id;
                            callVideoInfo.InterphoneType = InterphoneType.FREEVIEW.ToString();
                            HDLLinphone.Current.GetHDLSipInfoAndInitSDK(callVideoInfo);
                        }
                        else
                        {
                            Utlis.WriteLine("当前住宅不支持HDL可视对讲,退出登录所有账号");
                            //当前住宅不支持HDL可视对讲
                            HDLLinphone.Current.LogoutAllAccount();
                        }
                    }
                    //======================登录全视通====================
                    if (isInterphoneType_FREEVIEW)
                    {
#if __IOS__
                        //登录全视通
                        Shared.IOS.HDLFVSDK.Video.Init("", DB_ResidenceData.Instance.CurrentRegion.id);
#endif
                    }
                    //======================安防====================
@@ -421,8 +425,6 @@
                    Application.RunOnMainThread(() =>
                    {
                        MainPage.Log($"结束读取云端数据线程");
                        endTime = DateTime.MinValue;
                        DownloadDataComplete = true;
                        if (waitPage != null)
                        {
                            waitPage.RemoveFromParent();
@@ -432,7 +434,13 @@
                    //不考虑网关情况,直接订阅
                    DAL.Mqtt.MqttClient.InitState();
                    FunctionList.List.Read3tyFunctionStatus();
                    try
                    {
                        FunctionList.List.Read3tyFunctionStatus();
                    }catch(Exception ex)
                    {
                        MainPage.Log("读取第三方设备状态失败:"+ex.Message);
                    }
                }
            });
            downloadDataThread.IsBackground = true;
@@ -444,9 +452,9 @@
            {
                try
                {
                    while (endTime > DateTime.Now)
                    while (endTime1 > DateTime.Now)
                    {
                        if (DownloadDataComplete && complateDevice && complateScene)
                        if ( complateDevice && complateScene)
                        {
                            break;
                        }
@@ -478,37 +486,6 @@
                }
            })
            { IsBackground = true }.Start();
            ////下载光伏数据
            //new System.Threading.Thread(() => {
            //    try
            //    {//00
            //        HttpServerRequest http = new HttpServerRequest();
            //        var packData = http.GetInverterList();
            //        if (packData != null)
            //        {
            //            if (packData.Code == StateCode.SUCCESS)
            //            {
            //                var inverterList = JsonConvert.DeserializeObject<List<InverterInfo>>(packData.Data.ToString());
            //                if (inverterList!= null)
            //                {
            //                    FunctionList.List.InverterList = inverterList;
            //                }
            //            }
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        MainPage.Log($"读取光伏数据异常:{ex.Message}");
            //    }
            //}) { IsBackground = true }.Start();
        }
        /// <summary>