| | |
| | | /// <param name="pra">请求的参数</param>
|
| | | public static bool CheckNotEorrorMsg(ResponsePack revertObj, string RequestName, List<string> listNotShowError = null, object pra = null)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
|
| | | {
|
| | | //不检测
|
| | | return true;
|
| | | }
|
| | | if (revertObj == null)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | |
| | | var formTemp = UserCenterResourse.DicActionForm[formName];
|
| | | formTemp.CloseForm();
|
| | | UserCenterResourse.DicActionForm.Remove(formName);
|
| | | formTemp = null;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | catch (Exception ex)
|
| | | {
|
| | | //出现未知错误,数据丢失
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
|
| | | alert.Show();
|
| | |
|
| | | //Log出力
|
| | |
| | | catch (Exception ex)
|
| | | {
|
| | | //出现未知错误,数据丢失
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
|
| | | var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
|
| | | alert.Show();
|
| | |
|
| | | //Log出力
|
| | |
| | | //移除ID
|
| | | UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
|
| | | //移除画面
|
| | | var formTemp = UserCenterResourse.DicActionForm[formName];
|
| | | UserCenterResourse.DicActionForm.Remove(formName);
|
| | | formTemp = null;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// </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(false);
|
| | |
|
| | | //刷新住宅对象
|
| | | RefreshHomeObject();
|
| | | //刷新本地网关文件
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //刷新本地设备
|
| | |
| | | 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
|
| | |
| | | //关闭所有接收
|
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent();
|
| | | //清除升级列表
|
| | | FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
|
| | | FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
|
| | | FirmwareUpdateResourse.dicUpdateList.Clear();
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | |
| | | }
|
| | | catch { }
|
| | |
|
| | | if (noticeDb == true)
|
| | | {
|
| | | //通知云端,已经退出登陆
|
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
|
| | | }
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //关闭所有打开了的界面
|
| | |
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin);
|
| | | formLogin.Show(account);
|
| | | });
|
| | |
|
| | | if (noticeDb == true)
|
| | | {
|
| | | //通知云端,已经退出登陆
|
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 关闭所有打开了的界面
|
| | | /// </summary>
|
| | | public static void CloseAllOpenForm()
|
| | | /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param>
|
| | | public static void CloseAllOpenForm(string tagetFrom = "")
|
| | | {
|
| | | while (UserView.HomePage.Instance.ChildrenCount > 0)
|
| | | {
|
| | | var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
|
| | | if (view is CommonFormBase)
|
| | | {
|
| | | if (((CommonFormBase)view).FormID == tagetFrom)
|
| | | {
|
| | | //只关闭到指定目标界面
|
| | | return;
|
| | | }
|
| | | ((CommonFormBase)view).CloseForm();
|
| | | }
|
| | | else if (view is UserView.UserPage)
|
| | | {
|
| | | break;
|
| | | return;
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | /// <summary>
|
| | | /// 异步方法执行(仅限切换住宅时调用),刷新个人中心的内存及线程
|
| | | /// </summary>
|
| | | public async static Task<bool> InitUserCenterMenmoryAndThread()
|
| | | /// <param name="ShowPrompted">新追加变量:是否显示提示自动备份的界面</param>
|
| | | /// <returns></returns>
|
| | | public async static Task<bool> InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
|
| | | {
|
| | | //APP缓存加载开始
|
| | | UserCenterResourse.Option.AppCanSignout = false;
|
| | | //还原远程连接变量
|
| | | ZigBee.Device.ZbGateway.AllowRemoteCtrl = true;
|
| | |
|
| | | //只有在住宅ID不一样的时候才做这个操作
|
| | | if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
|
| | |
| | | try
|
| | | {
|
| | | //断开远程Mqtt连接
|
| | | ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | }
|
| | | catch { }
|
| | |
|
| | | //消息记录重新读取及检测
|
| | | ControlCommonResourse.ReadMessageAgain = true;
|
| | | ControlCommonResourse.HadNewMessage = false;
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | for (int i = 0; i < ControlCommonResourse.listMessageManaContr.Count; i++)
|
| | | {
|
| | | //显示角标特效
|
| | | ControlCommonResourse.listMessageManaContr[i].IsSelected = false;
|
| | | }
|
| | | });
|
| | |
|
| | | //加载账号配置信息
|
| | | var optionInfo = UserCenterResourse.Option.Load();
|
| | | UserCenterResourse.Option = optionInfo;
|
| | |
| | | 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();
|
| | | //读取隐匿配置
|
| | | await HdlBackupLogic.Current.LoadHideOption();
|
| | | }
|
| | |
|
| | | //初始化缓存成员的信息
|
| | | InitLocalMemberListInfo();
|
| | |
|
| | | //重新发送命令去绑定断网情况下备份的网关
|
| | | HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | |
|
| | | //预创建个人中心全部的文件夹
|
| | | CreatAllUserCenterDirectory();
|
| | |
| | | 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();
|
| | |
|
| | | //初始化住宅对象
|
| | | Common.Config.Instance.Home = House.GetHouseByHouseId(Common.Config.Instance.HomeId);
|
| | | if (hadNet == true)
|
| | | {
|
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | }
|
| | |
|
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
|
| | | Room.RefreshAllRoomByLocation();
|
| | |
| | | HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
|
| | |
|
| | | //0:已经同步过,不需要同步,这个时候需要提示备份
|
| | | if (result == 0)
|
| | | if (result == 0 && ShowPrompted == true)
|
| | | {
|
| | | //开启自动备份提示
|
| | | HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
|
| | | }
|
| | | //显示引导界面
|
| | | ShowGuideForm(result);
|
| | | }
|
| | | //APP缓存加载完成
|
| | | UserCenterResourse.Option.AppCanSignout = true;
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化缓存成员的信息_______________
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 引导界面___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 显示引导界面
|
| | | /// </summary>
|
| | | /// <param name="result">同步结果 -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据</param>
|
| | | private static void ShowGuideForm(int result)
|
| | | {
|
| | | var checkFile = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, DirNameResourse.GuideFile);
|
| | | if (System.IO.File.Exists(checkFile) == true)
|
| | | {
|
| | | //不需要显示
|
| | | return;
|
| | | }
|
| | | if (result == 2 && Config.Instance.Home.IsOthreShare == false)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new Guide.GuideHouseForm();
|
| | | form.ShowFrom();
|
| | | });
|
| | | }
|
| | |
|
| | | //创建一个空文件(标识已经完成引导)
|
| | | var file = System.IO.File.Create(checkFile);
|
| | | file.Close();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 16进制转化_________________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public static string EncryptPassword(string keys, string strPsw)
|
| | | {
|
| | | if (strPsw == string.Empty)
|
| | | try
|
| | | {
|
| | | return strPsw;
|
| | | if (strPsw == string.Empty)
|
| | | {
|
| | | return strPsw;
|
| | | }
|
| | | var des = new System.Security.Cryptography.DESCryptoServiceProvider();
|
| | | byte[] inputByteArray = Encoding.Default.GetBytes(strPsw);
|
| | | des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | var ms = new System.IO.MemoryStream();
|
| | | var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
|
| | | cs.Write(inputByteArray, 0, inputByteArray.Length);
|
| | | cs.FlushFinalBlock();
|
| | | StringBuilder ret = new StringBuilder();
|
| | | foreach (byte b in ms.ToArray())
|
| | | {
|
| | | ret.AppendFormat("{0:X2}", b);
|
| | | }
|
| | | return ret.ToString().ToLower();
|
| | | }
|
| | | var des = new System.Security.Cryptography.DESCryptoServiceProvider();
|
| | | byte[] inputByteArray = Encoding.Default.GetBytes(strPsw);
|
| | | des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | var ms = new System.IO.MemoryStream();
|
| | | var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
|
| | | cs.Write(inputByteArray, 0, inputByteArray.Length);
|
| | | cs.FlushFinalBlock();
|
| | | StringBuilder ret = new StringBuilder();
|
| | | foreach (byte b in ms.ToArray())
|
| | | {
|
| | | ret.AppendFormat("{0:X2}", b);
|
| | | }
|
| | | return ret.ToString();
|
| | | catch { return strPsw; }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <returns></returns>
|
| | | public static string DecryptPassword(string keys, string strPsw)
|
| | | {
|
| | | if (strPsw == string.Empty)
|
| | | try
|
| | | {
|
| | | return strPsw;
|
| | | if (strPsw == string.Empty)
|
| | | {
|
| | | return strPsw;
|
| | | }
|
| | | var des = new System.Security.Cryptography.DESCryptoServiceProvider();
|
| | |
|
| | | byte[] inputByteArray = new byte[strPsw.Length / 2];
|
| | | for (int x = 0; x < strPsw.Length / 2; x++)
|
| | | {
|
| | | int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
|
| | | inputByteArray[x] = (byte)i;
|
| | | }
|
| | |
|
| | | des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | var ms = new System.IO.MemoryStream();
|
| | | var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
|
| | | cs.Write(inputByteArray, 0, inputByteArray.Length);
|
| | | cs.FlushFinalBlock();
|
| | |
|
| | | StringBuilder ret = new StringBuilder();
|
| | |
|
| | | return System.Text.Encoding.Default.GetString(ms.ToArray());
|
| | | }
|
| | | var des = new System.Security.Cryptography.DESCryptoServiceProvider();
|
| | |
|
| | | byte[] inputByteArray = new byte[strPsw.Length / 2];
|
| | | for (int x = 0; x < strPsw.Length / 2; x++)
|
| | | {
|
| | | int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
|
| | | inputByteArray[x] = (byte)i;
|
| | | }
|
| | |
|
| | | des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
|
| | | var ms = new System.IO.MemoryStream();
|
| | | var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
|
| | | cs.Write(inputByteArray, 0, inputByteArray.Length);
|
| | | cs.FlushFinalBlock();
|
| | |
|
| | | StringBuilder ret = new StringBuilder();
|
| | |
|
| | | return System.Text.Encoding.Default.GetString(ms.ToArray());
|
| | | catch { return strPsw; }
|
| | | }
|
| | | #endregion
|
| | |
|
| | | #region ■ 时间转换___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 将utc时间类型的字符串,转换为本地时间
|
| | | /// </summary>
|
| | | /// <param name="timeText"></param>
|
| | | /// <returns></returns>
|
| | | public static DateTime ConvertUtcTimeToLocalTime(string timeText)
|
| | | {
|
| | | var utcTime = Convert.ToDateTime(timeText);
|
| | | return TimeZoneInfo.ConvertTimeFromUtc(utcTime, TimeZoneInfo.Local);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 文件保存和读取_____________________
|
| | |
|
| | | /// <summary>
|