WJC
2019-12-30 f1c3921b08bb22ac6f5db22d620e01d7e8e5c49f
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -285,7 +285,7 @@
                        //如果用户已经退出了登陆,则不处理
                        return;
                    }
                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode, pra);
                    string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj, pra);
                    if (msg != null)
                    {
                        var control = new ShowMsgControl(ShowMsgType.Tip, msg);
@@ -309,7 +309,7 @@
        /// </summary>
        /// <param name="checkAuthority">是否检测权限</param>
        /// <returns></returns>
        private static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
        public static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
        {
            if (checkAuthority == false)
            {
@@ -397,17 +397,21 @@
                        {
                            //设置当前激活的画面ID
                            UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
                            if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                            //追加条件一:关闭的界面为EditorCommonForm的时候才处理
                            if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                            {
                                try
                                {
                                    var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
                                    //触发界面再次激活的事件
                                    int value = Myform.FormActionAgainEvent();
                                    if (value == 1)
                                    if (Myform is EditorCommonForm)
                                    {
                                        //Log出力
                                        HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                        //触发界面再次激活的事件
                                        int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
                                        if (value == 1)
                                        {
                                            //Log出力
                                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                        }
                                    }
                                }
                                catch (Exception ex)
@@ -428,17 +432,21 @@
                            {
                                //设置当前激活的画面ID
                                UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
                                if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                                //追加条件一:关闭的界面为EditorCommonForm的时候才处理
                                if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
                                {
                                    try
                                    {
                                        var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
                                        //触发界面再次激活的事件
                                        int value = Myform.FormActionAgainEvent();
                                        if (value == 1)
                                        if (Myform is EditorCommonForm)
                                        {
                                            //Log出力
                                            HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                            //触发界面再次激活的事件
                                            int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
                                            if (value == 1)
                                            {
                                                //Log出力
                                                HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
                                            }
                                        }
                                    }
                                    catch (Exception ex)
@@ -502,18 +510,8 @@
        /// </summary>
        public static void RefreshAllMemory()
        {
            //备份的数据,有可能是主人自己上传的,如果管理员登陆时,他获取的备份数据有点特殊
            //比如下面这三个东西在主账号那里是不需要的
            bool isOthreShare = Config.Instance.Home.IsOthreShare;
            int accountType = Config.Instance.Home.AccountType;
            string mainMark = Config.Instance.Home.MainUserDistributedMark;
            //还原住宅对象
            Config.Instance.Home = House.GetHouseByHouseId(Config.Instance.Home.Id);
            Config.Instance.Home.IsOthreShare = isOthreShare;
            Config.Instance.Home.AccountType = accountType;
            Config.Instance.Home.MainUserDistributedMark = mainMark;
            Config.Instance.Home.Save();
            //刷新住宅对象
            RefreshHomeObject();
            //刷新本地网关文件
            HdlGatewayLogic.Current.ReFreshByLocal();
            //刷新本地设备
@@ -522,6 +520,28 @@
            HdlGatewayLogic.Current.SynchronizeDbGateway();
            //从本地重新加载全部的房间
            Common.Room.RefreshAllRoomByLocation();
        }
        /// <summary>
        /// 刷新住宅对象
        /// </summary>
        public static void RefreshHomeObject()
        {
            //备份的数据,有可能是主人自己上传的,如果管理员登陆时,他获取的备份数据有点特殊
            //比如下面这三个东西在主账号那里是不需要的
            bool isOthreShare = Config.Instance.Home.IsOthreShare;
            int accountType = Config.Instance.Home.AccountType;
            string mainMark = Config.Instance.Home.MainUserDistributedMark;
            double Longitude = Config.Instance.Home.Longitude;
            double Latitude = Config.Instance.Home.Latitude;
            //还原住宅对象
            Config.Instance.Home = House.GetHouseByHouseId(Config.Instance.Home.Id);
            Config.Instance.Home.IsOthreShare = isOthreShare;
            Config.Instance.Home.AccountType = accountType;
            Config.Instance.Home.MainUserDistributedMark = mainMark;
            Config.Instance.Home.Longitude = Longitude;
            Config.Instance.Home.Latitude = Latitude;
            Config.Instance.Home.Save(false);
        }
        #endregion
@@ -572,11 +592,6 @@
                //不能删除Config文件
                return true;
            }
            else if (fileName.StartsWith("DeviceUI_") == true)
            {
                //不能删除设备UI文件
                return true;
            }
            else if (fileName.StartsWith("House_") == true)
            {
                //不能删除住宅文件
@@ -598,7 +613,7 @@
        {
            UserCenterResourse.Option.OldAccountId = string.Empty;
            //关闭所有接收
            HdlDeviceAttributeLogic.Current.RemoveAllEvent();
            HdlGatewayReceiveLogic.Current.RemoveAllEvent();
            //清除升级列表
            FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
            FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
@@ -619,8 +634,8 @@
                HdlGatewayLogic.Current.ClearAllRealGateway();
                try
                {
                    ZigBee.Device.ZbGateway.RemoteMqttClient?.DisconnectAsync();
                    ZigBee.Device.ZbGateway.RemoteMqttClient = null;
                    //断开远程Mqtt连接
                    ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                }
                catch { }
@@ -645,29 +660,30 @@
        /// <summary>
        /// 关闭所有打开了的界面
        /// </summary>
        public static void CloseAllOpenForm()
        /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param>
        public static void CloseAllOpenForm(string tagetFrom = "")
        {
            var listForm = new List<CommonFormBase>();
            var listId = new List<string>();
            foreach (CommonFormBase form in UserCenterResourse.DicActionForm.Values)
            while (UserView.HomePage.Instance.ChildrenCount > 0)
            {
                if (form.FormID != "UserMainForm")
                var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
                if (view is CommonFormBase)
                {
                    listForm.Insert(0, form);
                    listId.Add(form.FormID);
                    if (((CommonFormBase)view).FormID == tagetFrom)
                    {
                        //只关闭到指定目标界面
                        return;
                    }
                    ((CommonFormBase)view).CloseForm();
                }
                else if (view is UserView.UserPage)
                {
                    return;
                }
                else
                {
                    view.RemoveFromParent();
                }
            }
            foreach (var id in listId)
            {
                UserCenterResourse.DicActionForm.Remove(id);
            }
            //关闭所有画面
            foreach (CommonFormBase form in listForm)
            {
                form.CloseForm();
            }
            listForm.Clear();
        }
        #endregion
@@ -789,13 +805,19 @@
            //APP缓存加载开始
            UserCenterResourse.Option.AppCanSignout = false;
            //强制指定不关闭进度条
            ProgressBar.SetCloseBarFlag(true);
            //只有在住宅ID不一样的时候才做这个操作
            if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
                || Common.Config.Instance.Account != UserCenterResourse.Option.OldAccountId)
            {
                try
                {
                    //断开远程Mqtt连接
                    ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
                }
                catch { }
                //消息记录重新读取及检测
                ControlCommonResourse.ReadMessageAgain = true;
                //加载账号配置信息
                var optionInfo = UserCenterResourse.Option.Load();
                UserCenterResourse.Option = optionInfo;
@@ -803,25 +825,24 @@
                UserCenterResourse.Option.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
                //初始化登陆账号的信息
                await InitUserAccoutInfo();
                //初始化管理员权限信息
                await InitAdminConnectMqttInfo(true);
                var hadNet = await InitUserAccoutInfo();
                //如果有网络的话
                if (hadNet == true)
                {
                    //重新发送命令去绑定断网情况下备份的网关
                    HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
                }
                //初始化缓存成员的信息
                InitLocalMemberListInfo();
                //重新发送命令去绑定断网情况下备份的网关
                HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
                //预创建个人中心全部的文件夹
                CreatAllUserCenterDirectory();
                //关闭所有接收
                HdlDeviceAttributeLogic.Current.RemoveAllEvent();
                HdlGatewayReceiveLogic.Current.RemoveAllEvent();
                //刷新安防上报信息
                HdlAlarmsLogic.Current.RefreshAlarmInfo();
                //添加保存安防设备报警的事件(不需要再执行任何操作,并且永久存在)
                HdlAlarmsLogic.Current.AddAlarmInfoEvent();
                //保存用户的登陆信息到本地
                SaveUserInformationToLocation();
@@ -830,15 +851,25 @@
                UserCenterResourse.Option.OldAccountId = Common.Config.Instance.Account;
                //同步数据(二次调用没关系)
                var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
                int result = -1;
                if (hadNet == true)
                {
                    result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
                }
                //初始化本地的网关信息
                HdlGatewayLogic.Current.ReFreshByLocal();
                //初始化本地的设备信息
                Common.LocalDevice.Current.ReFreshByLocal();
                //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
                HdlGatewayLogic.Current.SynchronizeDbGateway();
                if (hadNet == true)
                {
                    //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
                    HdlGatewayLogic.Current.SynchronizeDbGateway();
                }
                //初始化住宅对象
                Common.Config.Instance.Home = House.GetHouseByHouseId(Common.Config.Instance.HomeId);
                //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
                Room.RefreshAllRoomByLocation();
@@ -846,19 +877,13 @@
                //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用)
                HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
                //清空强制指定文本的附加信息
                ProgressBar.SetAppendText(string.Empty);
                //0:已经同步过,不需要同步,这个时候需要提示备份
                if (result == 0)
                {
                    //开启自动备份提示
                    //HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
                    HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
                }
            }
            //恢复可关闭进度条
            ProgressBar.SetCloseBarFlag(false);
            //APP缓存加载完成
            UserCenterResourse.Option.AppCanSignout = true;
@@ -938,7 +963,7 @@
                    newHouse.IsOthreShare = house.IsOthreShare;
                    newHouse.AccountType = house.AccountType;
                    newHouse.MainUserDistributedMark = house.MainUserDistributedMark;
                    newHouse.Save();
                    newHouse.Save(false);
                }
            }
            if (string.IsNullOrEmpty(userInfo.UserName) == true)
@@ -949,6 +974,18 @@
            UserCenterResourse.UserInfo = userInfo;
            UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
            if (UserCenterResourse.UserInfo.HeadImage != null)
            {
                //写入头像内容
                Shared.IO.FileUtils.WriteFileByBytes(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
            }
            UserCenterResourse.UserInfo.HeadImage = null;
            //手势密码
            UserCenterResourse.Option.GestureAuthentication = UserCenterResourse.UserInfo.GesturePwd == null ? string.Empty : UserCenterResourse.UserInfo.GesturePwd;
            UserCenterResourse.UserInfo.GesturePwd = null;
            //密码验证
            UserCenterResourse.Option.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd;
            UserCenterResourse.UserInfo.StringPwd = null;
            //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
            await InitAdminConnectMainInfo();
@@ -987,13 +1024,12 @@
            {
                return;
            }
            string nowFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
            if (System.IO.File.Exists(nowFile) == true)
            if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
            {
                return;
            }
            //复制过去
            System.IO.File.Copy(defultFile, nowFile);
            System.IO.File.Copy(defultFile, UserCenterResourse.UserInfo.UserIconFile);
        }
        #endregion
@@ -1011,9 +1047,9 @@
            Config.Instance.AdminRequestBaseUrl = string.Empty;
            Config.Instance.AdminRequestToken = string.Empty;
            if (UserCenterResourse.UserInfo.AuthorityNo != 2)
            if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                //拥有管理员权限的成员才能这样搞,  这里必须是2
                //时代变了,这里管理员和成员都能调用
                return true;
            }
            var pra = new
@@ -1036,44 +1072,6 @@
            var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(result);
            Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
            Config.Instance.AdminRequestToken = info.RequestToken;
            return true;
        }
        /// <summary>
        /// 初始化管理员权限的远程连接信息
        /// </summary>
        /// <param name="stopRemote">是否中断远程</param>
        /// <returns></returns>
        public static async Task<bool> InitAdminConnectMqttInfo(bool stopRemote = false)
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                //只有成员分身才能调用这个函数
                return true;
            }
            var praMqtt = new
            {
                CommonPage.RequestVersion,
                LoginAccessToken = Config.Instance.Token,
                Config.Instance.Home.MainUserDistributedMark,
                HomeId = Config.Instance.Home.Id
            };
            var listNotShow = new List<string>() { "NotSetAgain" };
            var result2 = await GetResponseDataByRequestHttps("App/GetConnectMainUserMqttInfo", false, praMqtt, listNotShow);
            if (string.IsNullOrEmpty(result2) == true)
            {
                return false;
            }
            //远程Mqtt
            var info2 = JsonConvert.DeserializeObject<MemberAdministratorMqttResult>(result2);
            Config.Instance.AdminConnectZigbeeMqttBrokerPwd = info2.ConnectZigbeeMqttBrokerPwd;
            Config.Instance.AdminConnectZigbeeMqttClientId = info2.ConnectZigbeeMqttClientId;
            Config.Instance.AdminMqttKey = info2.MqttKey;
            Config.Instance.AdminZigbeeMqttBrokerLoadSubDomain = info2.ZigbeeMqttBrokerLoadSubDomain;
            Config.Instance.AdminConnectZigbeeMqttBrokerName = info2.ConnectZigbeeMqttBrokerName;
            return true;
        }
@@ -1153,7 +1151,7 @@
            Global.CreateEmptyDirectory(directory);
            //用户图片目录路径【文件夹】
            if (!System.IO.Directory.Exists(UserCenterResourse.Option.UserPictruePath))
            if (UserCenterResourse.Option.UserPictruePath != string.Empty && !System.IO.Directory.Exists(UserCenterResourse.Option.UserPictruePath))
            {
                System.IO.Directory.CreateDirectory(UserCenterResourse.Option.UserPictruePath);
            }