JLChen
2020-12-11 d616b67bd6ea95562af73a00bf0aab38eec935df
HDL_ON/UI/MainPage.cs
@@ -9,15 +9,32 @@
{
    public static class MainPage
    {
        /// <summary>
        /// BaseView
        /// </summary>
        public static FrameLayout BaseView { get; internal set; }
        /// <summary>
        /// BasePageView
        /// </summary>
        public static PageLayout BasePageView { get; set; }
        /// <summary>
        /// DisplayCompleted
        /// </summary>
        public static bool DisplayCompleted = false;
        public static UserInfo LoginUser;
        //public static UserInfo LoginUser;
        /// <summary>
        /// 版本号
        /// </summary>
        public static string VersionString = "1.0.0924";
        ///// <summary>
        ///// 客户端类型
        ///// </summary>
        //public static string ClientType = APIClientType.HDL_ON_PRO.ToString();
        /// <summary>
        ///
        /// </summary>
        public static Entity.CityInfo cityInfo = new Entity.CityInfo();
        /// <summary>
        /// 天气刷新action
@@ -32,12 +49,12 @@
        /// </summary>
        public static bool IsRemote = false;
        /// <summary>
        /// 公司代码
        /// 预留第三方定制标记
        /// 0:HDL
        /// </summary>
        public static int Company = 0;
        ///// <summary>
        ///// 公司代码
        ///// 预留第三方定制标记
        ///// 0:HDL
        ///// </summary>
        //public static int Company = 0;
        /// <summary>
        /// 是否全面屏手机
@@ -69,51 +86,37 @@
                BaseView = Application.MainPage;
                Application.MainPage.BackgroundColor = CSS_Color.MainBackgroundColor;
                //BusSocket.Start();
                //CommonPage.InitReceiveEvent();
                LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(System.Text.Encoding.UTF8.GetString(FileUtils.ReadFile("UserInfo_File")));
                //LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo>(System.Text.Encoding.UTF8.GetString(FileUtils.ReadFile("UserInfo_File")));
                //判断需不需要登录,有没有登录,或者登录是否过期,
                if (LoginUser == null || !LoginUser.IsLogin)
                if (UserInfo.Current == null || !UserInfo.Current.IsLogin)
                {
                    GoLoginPage(LoginUser);
                    GoLoginPage(UserInfo.Current);
                }
                else
                {
                //UdpSocket._BusSocket.Start();
                    //if (Entity.DB_ResidenceData.residenceData.GatewayType == 1)
                    //{
                    //    BusSocket.Start();
                    //    CommonPage.InitReceiveEvent();
                    //    Control.ReadGatewayIPAddress();
                    //}
                    //else
                    //{
                    //    BusSocket.Start();
                    //    CommonPage.InitReceiveEvent();
                    //}
                    new System.Threading.Thread(() =>
                    {
                        var pm = new DAL.Server.HttpServerRequest();
                        pm.RefreshToken();//刷新Token
                        pm.GetHomePager();//刷新住宅信息
                    })
                    { IsBackground = true }.Start();
                    new System.Threading.Thread(() =>
                    {
                        var pm =new DAL.Server.HttpServerRequest();
                        pm.GetUserInfo();//刷新个人信息
                    })
                    { IsBackground = true }.Start();
                    new System.Threading.Thread(() =>
                    {
                        var pm = new DAL.Server.HttpServerRequest();
                        pm.GetHomePager();//刷新住宅信息
                    })
                    { IsBackground = true }.Start();
                    GoUserPage();
                    //启动密码验证
                    new AppUnlockPage().LoadPage();
                    //读取音乐信息
                    UI.Music.A31MusicModel.ReadMusicStates();
#if DEBUG
                    //new HDL_ON.DAL.Net.TcpListener().OpenServer(8586);
#endif
                    ///初始化app数据
                    InitializationData();
                }
            }
            catch (Exception ex)
            {
@@ -130,7 +133,7 @@
        /// <summary>
        /// 进入登录界面
        /// </summary>
        public static void GoLoginPage(UserInfo userInfo =null)
        public static void GoLoginPage(UserInfo userInfo = null)
        {
            BaseView.RemoveAll();
            BaseView.BackgroundColor = CSS_Color.BackgroundColor;
@@ -176,6 +179,46 @@
        }
        /// <summary>
        /// 初始化app所需要的数据
        /// </summary>
        public static void InitializationData()
        {
            new System.Threading.Thread(() =>
            {
                while (true)
                {
                    if (Entity.DB_ResidenceData.residenceData == null ||
                    Entity.DB_ResidenceData.residenceData.HomeGateway == null)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    else
                    {
                        break;
                    }
                }
                #region 读取云端数据--
                //todo数据覆盖处理
                //读取云端房间、楼层数据
                Entity.SpatialInfo.CurrentSpatial.DownloadRoomList();
                //读取云端设备数据
                Entity.FunctionList.List.DownloadFunctionList();
                //读取云端场景数据
                Entity.FunctionList.List.DownloadSceneList();
                #endregion
            })
            { IsBackground = true }.Start();
            #region 读取本地数据
            //读取音乐信息
            UI.Music.A31MusicModel.ReadMusicStates();
            //搜索网关
            DriverLayer.Control.Ins.SearchLoaclGateway();
            #endregion
        }
        /// <summary>
        /// 自定义日志输出
        /// </summary>
        public static void Log(string msg)
@@ -185,5 +228,31 @@
#endif
        }
        /// <summary>
        /// 生成13位时间戳
        /// </summary>
        /// <param name="value">时间</param>
        /// <returns></returns>
        public static long GetTimestamp13bit(DateTime value)
        {
            return new DateTimeOffset(value).ToUnixTimeSeconds();
        }
        /// <summary>
        /// 获取时间
        /// </summary>
        /// <param name="timestamp"></param>
        /// <returns></returns>
        public static DateTime GetDateTime (long timestamp)
        {
            long begtime = timestamp * 10000000;
            DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0);
            long tricks_1970 = dt_1970.Ticks;//1970年1月1日刻度
            long time_tricks = tricks_1970 + begtime;//日志日期刻度
            DateTime dt = new DateTime(time_tricks);//转化为DateTime
            return dt;
        }
    }
}