wxr
2024-09-24 3aba1c7fea5f0adb1b169e8060ce956188e80a2b
HDL_ON/Common/ApiUtlis.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using HDL_ON;
using HDL_ON.DAL;
using System.Net.Http;
using System.Threading.Tasks;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.UI2.FuntionControlView.Video;
@@ -76,7 +76,7 @@
        /// <summary>
        /// token是否有效
        /// </summary>
        public bool tokenInvalid = false;
        public bool IsValidToken = false;
        public bool hadInternet = true;
        /// <summary>
@@ -104,12 +104,12 @@
            string code = StateCode.SUCCESS;
            Inverter.Ins.H5Page = null;//重置光伏页面
            var downloadDataThread = new System.Threading.Thread(() =>
            var downloadDataThread = new System.Threading.Thread(async() =>
            {
                try
                {
                    //增加3秒云服务器连接检测,连不上服务器的时候不刷新数据
                    hadInternet = true;
                    //hadInternet = true;
                    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);
@@ -163,6 +163,7 @@
                }
                finally
                {
                    MainPage.Log("服务器连接状态:" + hadInternet);
                    if (!hadInternet)
                    {
                        Application.RunOnMainThread(() =>
@@ -181,7 +182,7 @@
                if (code != StateCode.SUCCESS)
                {
                    DownloadDataComplete = true;
                    hadInternet = false;
                    IsValidToken= false;
                    try
                    {
                        var spatialInfoDataBytes = FileUtlis.Files.ReadFile("SpatialInfoData");
@@ -214,14 +215,8 @@
                        MainPage.Log("Error", $"{this.GetType()}:加载缓存设备数据异常:{ex.StackTrace}");
                    }
                    MainPage.Log($"刷新token失败");
                    return;
                }
                else
                {
                    hadInternet = true;
                }
                if (code != StateCode.SUCCESS)
                {
                    if (waitPage != null)
                    {
                        Application.RunOnMainThread(() =>
@@ -236,6 +231,10 @@
                        });
                    }
                    return;
                }
                else
                {
                    hadInternet = true;
                }
                MainPage.Log($"刷新token成功");
                //===================刷新住宅信息=======================
@@ -824,6 +823,24 @@
            var pack = Ins.HttpRequest.GetSecurityList();
        }
        //public async Task<bool> CanConnectToHost()
        //{
        //    try
        //    {
        //        using (HttpClient client = new HttpClient())
        //        {
        //            client.Timeout = TimeSpan.FromSeconds(3); // 超时时间
        //            HttpResponseMessage response = await client.GetAsync(HttpUtil.GlobalRequestHttpsHost);
        //            return response.IsSuccessStatusCode;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        MainPage.Log(ex.StackTrace);
        //        return false;
        //    }
        //}
    }
}