old mode 100755
new mode 100644
| | |
| | | using System;
|
| | | using Shared.Common;
|
| | | using Newtonsoft.Json;
|
| | | using Shared.Common.ResponseEntity;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | |
|
| | | namespace Shared.Phone.UserCenter
|
| | | {
|
| | | /// <summary>
|
| | | /// 个人中心逻辑类
|
| | | /// </summary>
|
| | | public class UserCenterLogic
|
| | | {
|
| | | #region ■ 云端接口访问_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 访问指定接口,返回是否成功
|
| | | /// </summary>
|
| | | /// <returns>是否成功</returns>
|
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
|
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
|
| | | public static bool GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
|
| | | {
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | if (setAgain == false)
|
| | | {
|
| | | //当前无法访问网络
|
| | | ShowNotNetMsg(RequestName, listNotShowError);
|
| | | return false;
|
| | | }
|
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | }
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | //检测是否存在错误信息
|
| | | return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 访问指定接口,返回状态码(出现异常时,返回 Error)
|
| | | /// </summary>
|
| | | /// <returns>接口的状态码(出现异常时,返回 Error)</returns>
|
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
|
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
|
| | | /// </param>
|
| | | public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
|
| | | {
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | if (setAgain == false)
|
| | | {
|
| | | //当前无法访问网络
|
| | | ShowNotNetMsg(RequestName, listNotShowError);
|
| | | return "Error";
|
| | | }
|
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | return "Error";
|
| | | }
|
| | | }
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | if (revertObj == null)
|
| | | {
|
| | | return "Error";
|
| | | }
|
| | | return revertObj.StateCode;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 访问指定接口,并返回接口把对象已经序列化了的字符串,存在错误信息时,返回null
|
| | | /// </summary>
|
| | | /// <returns>返回:接口把对象已经序列化了的字符串,存在错误信息时,返回null</returns>
|
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
|
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
|
| | | /// </param>
|
| | | public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
|
| | | {
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | if (setAgain == false)
|
| | | {
|
| | | //当前无法访问网络
|
| | | ShowNotNetMsg(RequestName, listNotShowError);
|
| | | return null;
|
| | | }
|
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | }
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | //检测错误
|
| | | bool notError = CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
|
| | | if (notError == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | if (revertObj == null || revertObj.ResponseData == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return revertObj.ResponseData.ToString();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 访问指定接口,并直接返回接口返回的比特,存在错误信息时,返回null
|
| | | /// </summary>
|
| | | /// <returns>返回:并直接返回接口返回的比特,存在错误信息时,返回null</returns>
|
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
|
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param>
|
| | | public static byte[] GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true)
|
| | | {
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var revertObj = GettByteResponsePack(RequestName, connectMode, obj);
|
| | |
|
| | | if (revertObj == null)
|
| | | {
|
| | | if (setAgain == false)
|
| | | {
|
| | | //当前无法访问网络
|
| | | ShowNotNetMsg(RequestName, listNotShowError);
|
| | | return null;
|
| | | }
|
| | | revertObj = ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | if (revertObj == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | }
|
| | | if (revertObj != null && revertObj.Length > 0)
|
| | | {
|
| | | if (revertObj[0] == '{' && revertObj[revertObj.Length - 1] == '}')
|
| | | {
|
| | | string data2 = System.Text.Encoding.UTF8.GetString(revertObj);
|
| | | var data = JsonConvert.DeserializeObject<ResponsePack>(data2);
|
| | | if (data != null && string.IsNullOrEmpty(data.StateCode) == false)
|
| | | {
|
| | | bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError, obj);
|
| | | if (notError == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return revertObj;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 私有类型:从新发送(懂的人自然懂,很难解释清楚)
|
| | | /// </summary>
|
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <returns></returns>
|
| | | private static byte[] ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
|
| | | {
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | |
|
| | | byte[] responsePack = null;
|
| | | int count = 0;
|
| | | while (true)
|
| | | {
|
| | | System.Threading.Thread.Sleep(1000);
|
| | | //调用接口
|
| | | responsePack = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (responsePack != null)
|
| | | {
|
| | | break;
|
| | | }
|
| | | count++;
|
| | | if (count == 3)
|
| | | {
|
| | | //显示没有网络的Msg
|
| | | ShowNotNetMsg(RequestName, null);
|
| | | break;
|
| | | }
|
| | | }
|
| | | return responsePack;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取从接口那里取到的内容
|
| | | /// </summary>
|
| | | /// <returns>获取从接口那里取到的文本内容</returns>
|
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="connectMode">接口的连接模式</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | private static byte[] GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
|
| | | {
|
| | | try
|
| | | {
|
| | | //序列化对象
|
| | | var requestJson = JsonConvert.SerializeObject(obj);
|
| | | //访问接口
|
| | | byte[] result = null;
|
| | | if (connectMode == HttpConnectMode.Normal)
|
| | | {
|
| | | //普通访问
|
| | | result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
|
| | | }
|
| | | else if (connectMode == HttpConnectMode.Admin)
|
| | | {
|
| | | //以管理员的身份访问,自身是成员
|
| | | result = CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson));
|
| | | }
|
| | | return result;
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | Console.WriteLine(ex.Message);
|
| | | return null;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测是否存在错误信息,并显示错误
|
| | | /// </summary>
|
| | | /// <returns>是否存在错误信息</returns>
|
| | | /// <param name="revertObj">从接口接收到的数据</param>
|
| | | /// <param name="RequestName">请求接口</param>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别)</param>
|
| | | /// <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)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //网络不稳定,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | return false;
|
| | | }
|
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS")
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains(revertObj.StateCode) == true)
|
| | | {
|
| | | //不显示错误,然后返回true
|
| | | return true;
|
| | | }
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
|
| | | {
|
| | | //如果用户已经退出了登陆,则不处理
|
| | | return;
|
| | | }
|
| | | string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj, pra);
|
| | | if (msg != null)
|
| | | {
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | |
|
| | | //无效登录Token
|
| | | if (revertObj.StateCode == "NoLogin")
|
| | | {
|
| | | ReLoginAgain(Config.Instance.Account, false);
|
| | | }
|
| | | }
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取接口的连接模式
|
| | | /// </summary>
|
| | | /// <param name="checkAuthority">是否检测权限</param>
|
| | | /// <returns></returns>
|
| | | public static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
|
| | | {
|
| | | if (checkAuthority == false)
|
| | | {
|
| | | return HttpConnectMode.Normal;
|
| | | }
|
| | | if (Config.Instance.Home.IsOthreShare == true)
|
| | | {
|
| | | return HttpConnectMode.Admin;
|
| | | }
|
| | | return HttpConnectMode.Normal;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 显示没有网络的Msg
|
| | | /// </summary>
|
| | | private static void ShowNotNetMsg(string RequestName, List<string> listNotShowError)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
|
| | | {
|
| | | //不检测
|
| | | return;
|
| | | }
|
| | | //HdlLogLogic.Current.WriteLog(-1, "当前无网络连接:" + RequestName);
|
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | // 当前无网络连接,请确认网络
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 添加界面相关_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 检测能否添加画面
|
| | | /// </summary>
|
| | | /// <returns>true:可以追加 false:不可追加</returns>
|
| | | /// <param name="form">Form</param>
|
| | | public static bool CheckCanAddForm(CommonFormBase form)
|
| | | {
|
| | | //获取画面英文名字
|
| | | string formId = GetFormID(form);
|
| | |
|
| | | //二重追加不可
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | //暂时这样弄看看,如果重复,则关闭掉原来的界面
|
| | | var formTemp = UserCenterResourse.DicActionForm[formId];
|
| | | formTemp.CloseForm();
|
| | | UserCenterResourse.DicActionForm.Remove(formId);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 把打开的画面添加到内存中
|
| | | /// </summary>
|
| | | /// <param name="form">Form.</param>
|
| | | public static void AddActionForm(CommonFormBase form)
|
| | | {
|
| | | //获取画面英文名字
|
| | | string formId = GetFormID(form);
|
| | |
|
| | | //二重追加不可
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
|
| | | {
|
| | | form.FormID = formId;
|
| | | //内存添加
|
| | | UserCenterResourse.DicActionForm[formId] = form;
|
| | | //添加画面时,它自身就是激活的界面
|
| | | UserCenterResourse.NowActionFormID = form.FormID;
|
| | |
|
| | | UserCenterResourse.listActionFormId.Add(form.FormID);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从列表中移除画面
|
| | | /// </summary>
|
| | | /// <param name="i_closeForm">关闭的界面</param>
|
| | | public static void RemoveActionForm(CommonFormBase i_closeForm)
|
| | | {
|
| | | //获取画面ID
|
| | | string formId = GetFormID(i_closeForm);
|
| | |
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == true)
|
| | | {
|
| | | //移除ID
|
| | | UserCenterResourse.listActionFormId.Remove(formId);
|
| | | //移除画面
|
| | | UserCenterResourse.DicActionForm.Remove(formId);
|
| | | //清空
|
| | | UserCenterResourse.NowActionFormID = string.Empty;
|
| | |
|
| | | var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
|
| | | if (actionForm == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果关闭的界面是DialogCommonForm类型,则不需要触发激活函数
|
| | | if (i_closeForm is DialogCommonForm)
|
| | | {
|
| | | if (actionForm is EditorCommonForm)
|
| | | {
|
| | | UserCenterResourse.NowActionFormID = GetFormID((EditorCommonForm)actionForm);
|
| | | }
|
| | | return;
|
| | | }
|
| | | //关闭的界面为EditorCommonForm的时候
|
| | | else if ((i_closeForm is EditorCommonForm) && (actionForm is EditorCommonForm))
|
| | | {
|
| | | //接下来激活的界面id
|
| | | UserCenterResourse.NowActionFormID = GetFormID((CommonFormBase)actionForm);
|
| | | try
|
| | | {
|
| | | var Myform = actionForm as EditorCommonForm;
|
| | | //重置左滑使能
|
| | | Myform.ScrollEnabled = Myform.ScrollEnabled;
|
| | | //触发界面再次激活的事件
|
| | | int value = Myform.FormActionAgainEvent();
|
| | | if (value == 1)
|
| | | {
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
|
| | | }
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(ex, "界面重新激活异常 " + UserCenterResourse.NowActionFormID);
|
| | | }
|
| | | }
|
| | | else if (actionForm is UserView.UserPage)
|
| | | {
|
| | | //清空
|
| | | UserCenterResourse.NowActionFormID = string.Empty;
|
| | | //这里它已经退到主页了
|
| | | var nowForm = UserView.UserPage.Instance.GetNowActionForm();
|
| | | nowForm?.FormActionAgainEvent();
|
| | | }
|
| | | else
|
| | | {
|
| | | //清空
|
| | | UserCenterResourse.NowActionFormID = string.Empty;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取画面ID
|
| | | /// </summary>
|
| | | /// <returns>The form name.</returns>
|
| | | /// <param name="form">Form.</param>
|
| | | private static string GetFormID(CommonFormBase form)
|
| | | {
|
| | | if (form.FormID != string.Empty)
|
| | | {
|
| | | return form.FormID;
|
| | | }
|
| | | //将命名空间去掉
|
| | | string[] Arry = form.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
|
| | | string formName = Arry[Arry.Length - 1].Trim();
|
| | | return formName;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取当前正在激活的画面
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static CommonFormBase GetNowActionForm()
|
| | | {
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
|
| | | {
|
| | | return UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 刷新本地缓存_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 刷新本地所有缓存(目前此方法只提供给恢复备份数据使用)
|
| | | /// </summary>
|
| | | public static void RefreshAllMemory()
|
| | | {
|
| | | //刷新住宅对象
|
| | | RefreshHomeObject();
|
| | | //根据模板文件,恢复数据
|
| | | TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile();
|
| | | //强制生成设备和网关文件
|
| | | TemplateData.TemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce();
|
| | | //刷新本地网关文件
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //刷新本地设备
|
| | | Common.LocalDevice.Current.ReFreshByLocal();
|
| | | //需优先于刷新房间,同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | //从本地重新加载全部的房间
|
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation();
|
| | | //断开远程Mqtt连接,重新连接
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
|
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 刷新住宅对象
|
| | | /// </summary>
|
| | | public static void RefreshHomeObject()
|
| | | {
|
| | | var home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id);
|
| | |
|
| | | //刷新楼层
|
| | | Config.Instance.Home.FloorDics = home.FloorDics;
|
| | | Config.Instance.Home.CurrentFloorId = string.Empty;
|
| | | if (Config.Instance.Home.TemplateMode == -1)
|
| | | {
|
| | | Config.Instance.Home.TemplateMode = home.TemplateMode;
|
| | | if (Config.Instance.Home.TemplateMode == -1)
|
| | | {
|
| | | //默认初始值
|
| | | Config.Instance.Home.TemplateMode = 1;
|
| | | }
|
| | | }
|
| | |
|
| | | Config.Instance.Home.Save(false);
|
| | |
|
| | | //主页需要重新刷新
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 重新登录___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 重新登录
|
| | | /// </summary>
|
| | | /// <param name="account">账号</param>
|
| | | /// <param name="noticeDb">是否通知云端</param>
|
| | | public static void ReLoginAgain(string account = "", bool noticeDb = true)
|
| | | {
|
| | | if (Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //如果是虚拟住宅
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //设定一个时间
|
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
|
| | | Config.Instance.Save();
|
| | | //清空当前住宅id
|
| | | Config.Instance.HomeId = string.Empty;
|
| | | //收起左菜单
|
| | | CommonPage.Instance.CloseLeftMenu();
|
| | | //关闭全部弹窗
|
| | | ShowMsgControl.CloseAllMsgDialog();
|
| | | //关闭所有打开了的界面
|
| | | CloseAllOpenForm(null, false);
|
| | |
|
| | | //显示登陆画面
|
| | | var formLogin = new Login.AccountLoginForm();
|
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin);
|
| | | formLogin.ShowForm(account);
|
| | | });
|
| | | return;
|
| | | }
|
| | | UserCenterResourse.AccountOption.OldAccountId = string.Empty;
|
| | | //关闭所有接收
|
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent();
|
| | | //清除升级列表
|
| | | FirmwareUpdateResourse.dicUpdateList.Clear();
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //检测APP是否能够退出
|
| | | while (UserCenterResourse.AccountOption.AppCanSignout == false)
|
| | | {
|
| | | System.Threading.Thread.Sleep(500);
|
| | | }
|
| | | //设定一个时间
|
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
|
| | | Config.Instance.Save();
|
| | |
|
| | | //清空当前住宅id
|
| | | Config.Instance.HomeId = string.Empty;
|
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(false);
|
| | |
|
| | | //断开远程Mqtt连接
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //收起左菜单
|
| | | CommonPage.Instance.CloseLeftMenu();
|
| | | //关闭所有打开了的界面
|
| | | CloseAllOpenForm(null, false);
|
| | |
|
| | | //显示登陆画面
|
| | | var formLogin = new Login.AccountLoginForm();
|
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin);
|
| | | formLogin.ShowForm(account);
|
| | | });
|
| | |
|
| | | if (noticeDb == true)
|
| | | {
|
| | | //通知云端,已经退出登陆
|
| | | var result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 关闭所有打开了的界面
|
| | | /// </summary>
|
| | | /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param>
|
| | | /// <param name="refreshMainPage">当关闭的界面达到主页时,是否刷新主页</param>
|
| | | public static void CloseAllOpenForm(string tagetFrom = null, bool refreshMainPage = true)
|
| | | {
|
| | | while (UserView.HomePage.Instance.ChildrenCount > 0)
|
| | | {
|
| | | var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
|
| | | //(因底层控件修改了, 父控件移除时, 不触发子控件的移除事件)
|
| | | if (view is ViewGroup)
|
| | | {
|
| | | //关闭加载在ViewGroup里面的自定义界面Form
|
| | | CloseViewGroupChildren((ViewGroup)view);
|
| | | }
|
| | |
|
| | | if (view is CommonFormBase)
|
| | | {
|
| | | if (((CommonFormBase)view).FormID == tagetFrom)
|
| | | {
|
| | | //只关闭到指定目标界面
|
| | | return;
|
| | | }
|
| | | ((CommonFormBase)view).CloseForm();
|
| | | }
|
| | | else if (view is UserView.UserPage)
|
| | | {
|
| | | //刷新主页
|
| | | if (refreshMainPage == true)
|
| | | {
|
| | | UserView.UserPage.Instance.ReFreshControl();
|
| | | }
|
| | | return;
|
| | | }
|
| | | else
|
| | | {
|
| | | view.RemoveFromParent();
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 关闭加载在ViewGroup里面的自定义界面Form(因底层控件修改了,父控件移除时,不触发子控件的移除事件)
|
| | | /// </summary>
|
| | | /// <param name="group"></param>
|
| | | private static void CloseViewGroupChildren(ViewGroup group)
|
| | | {
|
| | | for (int i = 0; i < group.ChildrenCount; i++)
|
| | | {
|
| | | var view = group.GetChildren(i);
|
| | | if (view is CommonFormBase)
|
| | | {
|
| | | ((CommonFormBase)view).CloseForm();
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 拼接信息___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 拼接网关回复超时的信息
|
| | | /// </summary>
|
| | | /// <param name="errorMsg">错误信息</param>
|
| | | /// <param name="resultData">网关返回的resultData,里面有【errorMessageBase】这个东西的那种对象</param>
|
| | | /// <param name="strResultData">网关返回的resultData,里面的【errorMessageBase】的值,设定有此值时,resultData无效</param>
|
| | | /// <param name="addBrackets">是否添加括号</param>
|
| | | /// <returns></returns>
|
| | | public static string CombineGatewayTimeOutMsg(string errorMsg, object resultData, string strResultData = null, bool addBrackets = true)
|
| | | {
|
| | | if (resultData == null && strResultData == null)
|
| | | {
|
| | | return errorMsg;
|
| | | }
|
| | |
|
| | | string errorMsgBase = strResultData;
|
| | | if (errorMsgBase == null)
|
| | | {
|
| | | if (resultData is ReceiptGatewayResult)
|
| | | {
|
| | | errorMsgBase = string.Empty;
|
| | | if (((ReceiptGatewayResult)resultData).ErrorMsgDiv == 0)
|
| | | {
|
| | | errorMsgBase = "回复超时";
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | Type myType = resultData.GetType();
|
| | | object errorObj = myType.InvokeMember("errorMessageBase", System.Reflection.BindingFlags.GetField, null, resultData, null);
|
| | | if (errorObj == null)
|
| | | {
|
| | | return errorMsg;
|
| | | }
|
| | | errorMsgBase = errorObj.ToString();
|
| | | }
|
| | | }
|
| | |
|
| | | if (errorMsgBase.Contains("回复超时") == false)
|
| | | {
|
| | | //只有回复超时的时候才会加上
|
| | | return errorMsg;
|
| | | }
|
| | | errorMsg += "\r\n";
|
| | | if (addBrackets == true)
|
| | | {
|
| | | //(网关回复超时,请稍后再试)
|
| | | return errorMsg + "(" + Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut) + ")";
|
| | | }
|
| | | else
|
| | | {
|
| | | //网关回复超时,请稍后再试
|
| | | return errorMsg + Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 刷新个人中心的内存及线程___________
|
| | |
|
| | | /// <summary>
|
| | | /// 异步方法执行(仅限切换住宅时调用),刷新个人中心的内存及线程
|
| | | /// </summary>
|
| | | /// <param name="ShowPrompted">新追加变量:是否显示提示自动备份的界面</param>
|
| | | /// <returns></returns>
|
| | | public static bool InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
|
| | | {
|
| | | //调用这个方法,都需要重新刷新主页
|
| | | UserView.UserPage.Instance.RefreshAllForm = true;
|
| | |
|
| | | //添加网络状态监听
|
| | | HdlWifiLogic.Current.StartListenNetWork();
|
| | |
|
| | | //如果是虚拟住宅
|
| | | if (Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //初始化虚拟住宅的个人中心的数据(切换住宅使用)
|
| | | InitUserCenterMenmoryByVirtualHome();
|
| | | return true;
|
| | | }
|
| | |
|
| | | //APP缓存加载开始
|
| | | UserCenterResourse.AccountOption.AppCanSignout = false;
|
| | | //还原远程连接权限变量
|
| | | ZigBee.Device.ZbGateway.AllowRemoteCtrl = true;
|
| | |
|
| | | //只有在住宅ID不一样的时候才做这个操作
|
| | | if (Common.Config.Instance.HomeId != UserCenterResourse.AccountOption.OldHomeStringId
|
| | | || Common.Config.Instance.Account != UserCenterResourse.AccountOption.OldAccountId)
|
| | | {
|
| | | //借用一下这个变量(检测能否广播到网关)
|
| | | UserCenterResourse.DicReceiveGatewayTest = new Dictionary<string, ZigBee.Device.ZbGateway>();
|
| | | UserCenterResourse.HideOption.CheckCanReceiveGateway = 1;
|
| | |
|
| | | //清空所有成员缓存
|
| | | ClearAllMemberMemory();
|
| | |
|
| | | //加载账号配置信息
|
| | | var optionInfo = UserCenterResourse.AccountOption.Load();
|
| | | UserCenterResourse.AccountOption = optionInfo;
|
| | | //变更根用户图片目录路径
|
| | | UserCenterResourse.AccountOption.UserPictruePath = DirNameResourse.UserPictrueDirectory;
|
| | |
|
| | | //加载住宅配置信息
|
| | | UserCenterResourse.ResidenceOption = UserCenterResourse.ResidenceOption.Load();
|
| | |
|
| | | //预创建个人中心全部的文件夹
|
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory();
|
| | |
|
| | | //初始化登陆账号的信息
|
| | | var hadNet = InitUserAccoutInfo(true);
|
| | | //如果有网络的话
|
| | | if (hadNet == 1)
|
| | | {
|
| | | //重新发送命令去绑定断网情况下备份的网关
|
| | | HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | | //读取隐匿配置
|
| | | HdlBackupLogic.Current.LoadHideOption();
|
| | | //调试:强制开启后台调试App功能
|
| | | if (UserCenterResourse.HideOption.StartDebugApp == 1)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | var form = new HideOption.HideOptionMainForm();
|
| | | form.AddForm();
|
| | | });
|
| | | ProgressBar.Close(true);
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | //关闭所有接收
|
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent();
|
| | | //刷新安防上报信息
|
| | | HdlAlarmsLogic.Current.RefreshAlarmInfo();
|
| | |
|
| | | //保存用户的登陆信息到本地
|
| | | SaveUserInformationToLocation();
|
| | |
|
| | | UserCenterResourse.AccountOption.OldHomeStringId = Common.Config.Instance.HomeId;
|
| | | UserCenterResourse.AccountOption.OldAccountId = Common.Config.Instance.Account;
|
| | |
|
| | | //同步数据(二次调用没关系)
|
| | | int result = -1;
|
| | | if (hadNet == 1)
|
| | | {
|
| | | result = HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
|
| | | }
|
| | |
|
| | | //初始化本地的网关信息
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //初始化本地的设备信息
|
| | | LocalDevice.Current.ReFreshByLocal();
|
| | |
|
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
|
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation();
|
| | |
|
| | | if (hadNet == 1)
|
| | | {
|
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | }
|
| | |
|
| | | //断开远程Mqtt连接,重新连接
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
|
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用)
|
| | | HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
|
| | |
|
| | | //加载模板缓存
|
| | | //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData();
|
| | |
|
| | | //0:已经同步过,不需要同步,这个时候需要提示备份
|
| | | if (result == 0 && ShowPrompted == true)
|
| | | {
|
| | | //开启自动备份
|
| | | HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
|
| | | }
|
| | | //显示引导界面
|
| | | ShowGuideForm(result);
|
| | |
|
| | | //关闭debug广播
|
| | | UserCenterResourse.HideOption.CheckCanReceiveGateway = 0;
|
| | | System.Threading.Thread.Sleep(30);
|
| | | if (hadNet == 1)
|
| | | {
|
| | | //住宅切换时,检测网关连接情况
|
| | | CheckGatewayConnection();
|
| | |
|
| | | }
|
| | | UserCenterResourse.DicReceiveGatewayTest = null;
|
| | | }
|
| | | //APP缓存加载完成
|
| | | UserCenterResourse.AccountOption.AppCanSignout = true;
|
| | | if (Shared.Phone.Device.Logic.Send.If_Exist == "1")
|
| | | {
|
| | | //以本地状态为主打开GPS服务
|
| | | Application.StartGPSLocationService();
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化虚拟住宅的个人中心的数据(切换住宅使用)
|
| | | /// </summary>
|
| | | private static void InitUserCenterMenmoryByVirtualHome()
|
| | | {
|
| | | UserCenterResourse.AccountOption.OldHomeStringId = Common.Config.Instance.Home.Id;
|
| | | //清空所有成员缓存
|
| | | ClearAllMemberMemory();
|
| | | //预创建个人中心全部的文件夹
|
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory();
|
| | | //关闭所有接收
|
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent();
|
| | | //初始化本地的网关信息
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //初始化本地的设备信息
|
| | | Common.LocalDevice.Current.ReFreshByLocal();
|
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
|
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation();
|
| | | //刷新左边刷新房间视图列表
|
| | | HdlRoomLogic.Current.RefreshRoomListView();
|
| | | //加载模板缓存
|
| | | //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 清空所有成员缓存
|
| | | /// </summary>
|
| | | private static void ClearAllMemberMemory()
|
| | | {
|
| | | //消息记录重新读取及检测
|
| | | ControlCommonResourse.ReadMessageAgain = true;
|
| | | ControlCommonResourse.HadNewMessage = false;
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | for (int i = 0; i < ControlCommonResourse.listMessageManaContr.Count; i++)
|
| | | {
|
| | | //显示角标特效
|
| | | ControlCommonResourse.listMessageManaContr[i].IsSelected = false;
|
| | | }
|
| | | });
|
| | |
|
| | | //切换住宅清除之前逻辑缓存数据;
|
| | | Common.Logic.LogicList.Clear();
|
| | | Common.Logic.LockLogicList.Clear();
|
| | | Common.Logic.SoneLogicList.Clear();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 住宅切换时,检测网关连接情况
|
| | | /// </summary>
|
| | | private static void CheckGatewayConnection()
|
| | | {
|
| | | try
|
| | | {
|
| | | bool canReceiveGw = false;
|
| | | foreach (var gateway in UserCenterResourse.DicReceiveGatewayTest.Values)
|
| | | {
|
| | | if (gateway.HomeId == Config.Instance.Home.Id)
|
| | | {
|
| | | //能够搜索得到网关
|
| | | canReceiveGw = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | UserCenterResourse.DicReceiveGatewayTest = null;
|
| | | //设置远程连接的初始值
|
| | | ZigBee.Device.ZbGateway.IsRemote = canReceiveGw == false;
|
| | | if (canReceiveGw == false)
|
| | | {
|
| | | //如果是远程的话,追加等待时间
|
| | | System.Threading.Thread.Sleep(1500);
|
| | | }
|
| | | }
|
| | | catch { }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化登陆账号的信息_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化登陆账号的信息 -1:无网 1:正常 2:其他错误
|
| | | /// </summary>
|
| | | /// <param name="reLoad">是否从新从本地加载(重新初始化登陆账号的信息,不需要重新加载)</param>
|
| | | /// <returns></returns>
|
| | | private static int InitUserAccoutInfo(bool reLoad)
|
| | | {
|
| | | //初始化个人信息的标识
|
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = false;
|
| | | if (reLoad == true)
|
| | | {
|
| | | //获取本地记录的用户信息
|
| | | UserCenterResourse.UserInfo = GetUserInformationFromLocation();
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, "Admin.png");
|
| | | }
|
| | | if (HdlWifiLogic.Current.CanAccessHttp == false)
|
| | | {
|
| | | //无法连接外网
|
| | | return -1;
|
| | | }
|
| | |
|
| | | //获取登录账号的信息
|
| | | var pra = new AccountInfoPra();
|
| | | //序列化对象
|
| | | var requestJson = JsonConvert.SerializeObject(pra);
|
| | | //访问接口
|
| | | byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson), "POST", 4);
|
| | | if (byteData == null)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | | //检测错误
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS")
|
| | | {
|
| | | return 2;
|
| | | }
|
| | |
|
| | | var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(revertObj.ResponseData.ToString());
|
| | | userInfo.Account = Common.Config.Instance.Account;
|
| | | if (string.IsNullOrEmpty(userInfo.UserName) == true)
|
| | | {
|
| | | //没有昵称的时候,把账号作为昵称
|
| | | userInfo.UserName = Common.Config.Instance.Account;
|
| | | }
|
| | |
|
| | | if (Common.Config.Instance.Home.IsOthreShare == false)
|
| | | {
|
| | | //身份:管理员
|
| | | userInfo.AuthorityNo = 1;
|
| | | userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.Administrator);
|
| | | }
|
| | | else if (Common.Config.Instance.Home.AccountType == 1)
|
| | | {
|
| | | //身份:成员(拥有管理员权限)
|
| | | userInfo.AuthorityNo = 2;
|
| | | userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMemberHadActionAuthority);
|
| | | }
|
| | | else
|
| | | {
|
| | | //身份:成员
|
| | | userInfo.AuthorityNo = 3;
|
| | | userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMember);
|
| | | }
|
| | |
|
| | | //UserInfo.AuthorityNo==0代表本地还没有生成文件,这个时候不需要处理
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo
|
| | | && UserCenterResourse.UserInfo.AuthorityNo != 0)
|
| | | {
|
| | | //如果登陆的账号的权限和上一次的不一样,则删除本地这个住宅全部的文件,从头再来
|
| | | string dirPath = Config.Instance.FullPath;
|
| | | if (System.IO.Directory.Exists(dirPath) == true)
|
| | | {
|
| | | try
|
| | | {
|
| | | //同步数据的判断文件(以防万一删除整个文件夹失败的时候,这个文件被删的话,应该没什么大问题)
|
| | | string SynchronizeFile = DirNameResourse.AutoDownLoadBackupCheckFile;
|
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
|
| | | HdlFileLogic.Current.DeleteFile(SynchronizeFile);
|
| | | HdlFileLogic.Current.DeleteDirectory(dirPath);
|
| | | }
|
| | | catch { }
|
| | | //创建住宅文件夹
|
| | | Global.CreateHomeDirectory(Config.Instance.HomeId);
|
| | | //预创建个人中心全部的文件夹
|
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory();
|
| | | }
|
| | | }
|
| | | if (string.IsNullOrEmpty(userInfo.UserName) == true)
|
| | | {
|
| | | //没有昵称的话,把账号丢过去
|
| | | userInfo.UserName = userInfo.Account;
|
| | | }
|
| | |
|
| | | UserCenterResourse.UserInfo = userInfo;
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, "Admin.png");
|
| | | if (UserCenterResourse.UserInfo.HeadImage != null)
|
| | | {
|
| | | //写入头像内容
|
| | | HdlFileLogic.Current.SaveByteToFile(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
|
| | | }
|
| | | UserCenterResourse.UserInfo.HeadImage = null;
|
| | | //手势密码
|
| | | UserCenterResourse.AccountOption.GestureAuthentication = UserCenterResourse.UserInfo.GesturePwd == null ? string.Empty : UserCenterResourse.UserInfo.GesturePwd;
|
| | | UserCenterResourse.UserInfo.GesturePwd = null;
|
| | | //密码验证
|
| | | UserCenterResourse.AccountOption.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd;
|
| | | UserCenterResourse.UserInfo.StringPwd = null;
|
| | | //保存缓存
|
| | | UserCenterResourse.AccountOption.Save();
|
| | |
|
| | | //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
|
| | | var flage = InitAdminConnectMainInfo();
|
| | | //初始化个人信息的标识
|
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = flage == 1;
|
| | |
|
| | | return flage;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 从本地获取用户的登陆信息
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private static UserInformation GetUserInformationFromLocation()
|
| | | {
|
| | | var value = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.UserInfoFile);
|
| | | if (value == null)
|
| | | {
|
| | | return new UserInformation();
|
| | | }
|
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
|
| | | return info;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 重新初始化登陆账号的信息(旨在对应那一瞬间,网络不好,导致误判的情况)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static bool ReInitUserAccoutInfo()
|
| | | {
|
| | | //重新初始化账号信息
|
| | | var result = InitUserAccoutInfo(false);
|
| | | if (result == 1)
|
| | | {
|
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | //初始化个人信息的标识
|
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = true;
|
| | |
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存用户的登陆信息到本地
|
| | | /// </summary>
|
| | | private static void SaveUserInformationToLocation()
|
| | | {
|
| | | //写入内容
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.UserInfoFile, UserCenterResourse.UserInfo);
|
| | |
|
| | | //搞一下主人的默认头像
|
| | | string defultFile = IO.FileUtils.GetImageFilePath("Center/Admin.png");
|
| | | if (defultFile == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //复制过去
|
| | | System.IO.File.Copy(defultFile, UserCenterResourse.UserInfo.UserIconFile);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化管理员权限远程连接___________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化管理员权限远程连接主人的信息 -1:无网 1:正常 2:其他错误
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private static int InitAdminConnectMainInfo()
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
|
| | | {
|
| | | //时代变了,这里管理员和成员都能调用
|
| | | return 1;
|
| | | }
|
| | | var pra = new
|
| | | {
|
| | | CommonPage.RequestVersion,
|
| | | LoginAccessToken = Config.Instance.Token,
|
| | | MainAccountId = Config.Instance.Home.MainUserDistributedMark,
|
| | | SharedHid = Config.Instance.Home.Id
|
| | | };
|
| | |
|
| | | //序列化对象
|
| | | var requestJson = JsonConvert.SerializeObject(pra);
|
| | | //访问接口
|
| | | byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("App/GetSharedHomeApiControl", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (byteData == null)
|
| | | {
|
| | | return -1;
|
| | | }
|
| | | //检测错误
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS")
|
| | | {
|
| | | return 2;
|
| | | }
|
| | |
|
| | | //分享链接
|
| | | var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(revertObj.ResponseData.ToString());
|
| | | Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
|
| | | Config.Instance.AdminRequestToken = info.RequestToken;
|
| | |
|
| | | return 1;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 获取控制主人账号的Token____________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取控制主人账号的Token
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static string GetConnectMainToken()
|
| | | {
|
| | | //启用管理员权限
|
| | | if (Config.Instance.Home.IsOthreShare == true)
|
| | | {
|
| | | return Config.Instance.AdminRequestToken;
|
| | | }
|
| | | return Config.Instance.Token;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 引导界面___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 显示引导界面
|
| | | /// </summary>
|
| | | /// <param name="result">同步结果 -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据</param>
|
| | | private static void ShowGuideForm(int result)
|
| | | {
|
| | | var checkFile = 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>
|
| | | /// 将16进制的文本翻译为正常文本
|
| | | /// </summary>
|
| | | /// <param name="hexText">16进制的文本</param>
|
| | | /// <param name="count">以多少个字节为一组</param>
|
| | | /// <returns></returns>
|
| | | public static string TranslateHexadecimalIntoText(string hexText, int count = 2)
|
| | | {
|
| | | string textValue = string.Empty;
|
| | | while (hexText.Length > 0)
|
| | | {
|
| | | string temp = hexText.Substring(0, count);
|
| | | hexText = hexText.Substring(count);
|
| | | int value = Convert.ToInt32(temp, 16);
|
| | | textValue += ((char)value).ToString();
|
| | | }
|
| | | return textValue;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将文本翻译为16进制的文本
|
| | | /// </summary>
|
| | | /// <param name="text">指定文本</param>
|
| | | /// <returns></returns>
|
| | | public static string TranslateTextIntoHexadecimal(string text)
|
| | | {
|
| | | string textValue = string.Empty;
|
| | | foreach (char c in text)
|
| | | {
|
| | | int value = Convert.ToInt32(c);
|
| | | textValue += Convert.ToString(value, 16);
|
| | | }
|
| | | return textValue;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 加密和解密_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 加密密码
|
| | | /// </summary>
|
| | | /// <param name="keys"></param>
|
| | | /// <param name="strPsw"></param>
|
| | | /// <returns></returns>
|
| | | public static string EncryptPassword(string keys, string strPsw)
|
| | | {
|
| | | try
|
| | | {
|
| | | if (string.IsNullOrEmpty(strPsw) == true)
|
| | | {
|
| | | 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();
|
| | | }
|
| | | catch { return strPsw; }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 解密密码
|
| | | /// </summary>
|
| | | /// <param name="strPsw"></param>
|
| | | /// <returns></returns>
|
| | | public static string DecryptPassword(string keys, string strPsw)
|
| | | {
|
| | | try
|
| | | {
|
| | | 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());
|
| | | }
|
| | | 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
|
| | | }
|
| | | }
|
| | | using System; |
| | | using Shared.Common; |
| | | using Newtonsoft.Json; |
| | | using Shared.Common.ResponseEntity; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using Shared.IOS.HDLFVSDK; |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// 个人中心逻辑类 |
| | | /// </summary> |
| | | public class UserCenterLogic |
| | | { |
| | | #region ■ 云端接口访问_______________________ |
| | | |
| | | /// <summary> |
| | | /// 访问指定接口,返回是否成功 |
| | | /// </summary> |
| | | /// <returns>是否成功</returns> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param> |
| | | /// <param name="obj">一个类</param> |
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param> |
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param> |
| | | public static bool GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true) |
| | | { |
| | | //获取接口的连接模式 |
| | | var connectMode = GetHttpConnectMode(checkAuthority); |
| | | //获取从接口那里取到的比特数据 |
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj); |
| | | if (byteData == null) |
| | | { |
| | | if (setAgain == false) |
| | | { |
| | | //当前无法访问网络 |
| | | ShowNotNetMsg(RequestName, listNotShowError); |
| | | return false; |
| | | } |
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj); |
| | | if (byteData == null) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData)); |
| | | //检测是否存在错误信息 |
| | | return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 访问指定接口,返回状态码(出现异常时,返回 Error) |
| | | /// </summary> |
| | | /// <returns>接口的状态码(出现异常时,返回 Error)</returns> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param> |
| | | /// <param name="obj">一个类</param> |
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param> |
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param> |
| | | /// </param> |
| | | public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true) |
| | | { |
| | | //获取接口的连接模式 |
| | | var connectMode = GetHttpConnectMode(checkAuthority); |
| | | //获取从接口那里取到的比特数据 |
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj); |
| | | if (byteData == null) |
| | | { |
| | | if (setAgain == false) |
| | | { |
| | | //当前无法访问网络 |
| | | ShowNotNetMsg(RequestName, listNotShowError); |
| | | return "Error"; |
| | | } |
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj); |
| | | if (byteData == null) |
| | | { |
| | | return "Error"; |
| | | } |
| | | } |
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData)); |
| | | if (revertObj == null) |
| | | { |
| | | return "Error"; |
| | | } |
| | | return revertObj.StateCode; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 访问指定接口,并返回接口把对象已经序列化了的字符串,存在错误信息时,返回null |
| | | /// </summary> |
| | | /// <returns>返回:接口把对象已经序列化了的字符串,存在错误信息时,返回null</returns> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param> |
| | | /// <param name="obj">一个类</param> |
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param> |
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param> |
| | | /// </param> |
| | | public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true) |
| | | { |
| | | //获取接口的连接模式 |
| | | var connectMode = GetHttpConnectMode(checkAuthority); |
| | | //获取从接口那里取到的比特数据 |
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj); |
| | | if (byteData == null) |
| | | { |
| | | if (setAgain == false) |
| | | { |
| | | //当前无法访问网络 |
| | | ShowNotNetMsg(RequestName, listNotShowError); |
| | | return null; |
| | | } |
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj); |
| | | if (byteData == null) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData)); |
| | | //检测错误 |
| | | bool notError = CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj); |
| | | if (notError == false) |
| | | { |
| | | return null; |
| | | } |
| | | if (revertObj == null || revertObj.ResponseData == null) |
| | | { |
| | | return null; |
| | | } |
| | | return revertObj.ResponseData.ToString(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 访问指定接口,并直接返回接口返回的比特,存在错误信息时,返回null |
| | | /// </summary> |
| | | /// <returns>返回:并直接返回接口返回的比特,存在错误信息时,返回null</returns> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param> |
| | | /// <param name="obj">一个类</param> |
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param> |
| | | /// <param name="setAgain">当发送失败时,是否重发,默认重发</param> |
| | | public static byte[] GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = true) |
| | | { |
| | | //获取接口的连接模式 |
| | | var connectMode = GetHttpConnectMode(checkAuthority); |
| | | //获取从接口那里取到的比特数据 |
| | | var revertObj = GettByteResponsePack(RequestName, connectMode, obj); |
| | | |
| | | if (revertObj == null) |
| | | { |
| | | if (setAgain == false) |
| | | { |
| | | //当前无法访问网络 |
| | | ShowNotNetMsg(RequestName, listNotShowError); |
| | | return null; |
| | | } |
| | | revertObj = ResetByteRequestHttps(RequestName, checkAuthority, obj); |
| | | if (revertObj == null) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | if (revertObj != null && revertObj.Length > 0) |
| | | { |
| | | if (revertObj[0] == '{' && revertObj[revertObj.Length - 1] == '}') |
| | | { |
| | | string data2 = System.Text.Encoding.UTF8.GetString(revertObj); |
| | | var data = JsonConvert.DeserializeObject<ResponsePack>(data2); |
| | | if (data != null && string.IsNullOrEmpty(data.StateCode) == false) |
| | | { |
| | | bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError, obj); |
| | | if (notError == false) |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return revertObj; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 私有类型:从新发送(懂的人自然懂,很难解释清楚) |
| | | /// </summary> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param> |
| | | /// <param name="obj">一个类</param> |
| | | /// <returns></returns> |
| | | private static byte[] ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj) |
| | | { |
| | | //获取接口的连接模式 |
| | | var connectMode = GetHttpConnectMode(checkAuthority); |
| | | |
| | | byte[] responsePack = null; |
| | | int count = 0; |
| | | while (true) |
| | | { |
| | | System.Threading.Thread.Sleep(1000); |
| | | //调用接口 |
| | | responsePack = GettByteResponsePack(RequestName, connectMode, obj); |
| | | if (responsePack != null) |
| | | { |
| | | break; |
| | | } |
| | | count++; |
| | | if (count == 3) |
| | | { |
| | | //显示没有网络的Msg |
| | | ShowNotNetMsg(RequestName, null); |
| | | break; |
| | | } |
| | | } |
| | | return responsePack; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取从接口那里取到的内容 |
| | | /// </summary> |
| | | /// <returns>获取从接口那里取到的文本内容</returns> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="connectMode">接口的连接模式</param> |
| | | /// <param name="obj">一个类</param> |
| | | private static byte[] GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj) |
| | | { |
| | | try |
| | | { |
| | | //序列化对象 |
| | | var requestJson = JsonConvert.SerializeObject(obj); |
| | | //访问接口 |
| | | byte[] result = null; |
| | | if (connectMode == HttpConnectMode.Normal) |
| | | { |
| | | //普通访问 |
| | | result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson)); |
| | | } |
| | | else if (connectMode == HttpConnectMode.Admin) |
| | | { |
| | | //以管理员的身份访问,自身是成员 |
| | | result = CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson)); |
| | | } |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测是否存在错误信息,并显示错误 |
| | | /// </summary> |
| | | /// <returns>是否存在错误信息</returns> |
| | | /// <param name="revertObj">从接口接收到的数据</param> |
| | | /// <param name="RequestName">请求接口</param> |
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别)</param> |
| | | /// <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) |
| | | { |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | //网络不稳定,请稍后再试 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain); |
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg); |
| | | control.Show(); |
| | | }, ShowErrorMode.NO); |
| | | |
| | | return false; |
| | | } |
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS") |
| | | { |
| | | if (listNotShowError != null && listNotShowError.Contains(revertObj.StateCode) == true) |
| | | { |
| | | //不显示错误,然后返回true |
| | | return true; |
| | | } |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | if (HdlCheckLogic.Current.IsAccountLoginOut() == true) |
| | | { |
| | | //如果用户已经退出了登陆,则不处理 |
| | | return; |
| | | } |
| | | string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj, pra); |
| | | if (msg != null) |
| | | { |
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg); |
| | | control.Show(); |
| | | |
| | | //无效登录Token |
| | | if (revertObj.StateCode == "NoLogin") |
| | | { |
| | | ReLoginAgain(Config.Instance.Account, false); |
| | | } |
| | | } |
| | | }, ShowErrorMode.NO); |
| | | |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取接口的连接模式 |
| | | /// </summary> |
| | | /// <param name="checkAuthority">是否检测权限</param> |
| | | /// <returns></returns> |
| | | public static HttpConnectMode GetHttpConnectMode(bool checkAuthority) |
| | | { |
| | | if (checkAuthority == false) |
| | | { |
| | | return HttpConnectMode.Normal; |
| | | } |
| | | if (Config.Instance.Home.IsOthreShare == true) |
| | | { |
| | | return HttpConnectMode.Admin; |
| | | } |
| | | return HttpConnectMode.Normal; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 显示没有网络的Msg |
| | | /// </summary> |
| | | private static void ShowNotNetMsg(string RequestName, List<string> listNotShowError) |
| | | { |
| | | if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true) |
| | | { |
| | | //不检测 |
| | | return; |
| | | } |
| | | //HdlLogLogic.Current.WriteLog(-1, "当前无网络连接:" + RequestName); |
| | | |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | // 当前无网络连接,请确认网络 |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork); |
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg); |
| | | control.Show(); |
| | | }, ShowErrorMode.NO); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 添加界面相关_______________________ |
| | | |
| | | /// <summary> |
| | | /// 检测能否添加画面 |
| | | /// </summary> |
| | | /// <returns>true:可以追加 false:不可追加</returns> |
| | | /// <param name="form">Form</param> |
| | | public static bool CheckCanAddForm(CommonFormBase form) |
| | | { |
| | | //获取画面英文名字 |
| | | string formId = GetFormID(form); |
| | | |
| | | //二重追加不可 |
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false) |
| | | { |
| | | return true; |
| | | } |
| | | //暂时这样弄看看,如果重复,则关闭掉原来的界面 |
| | | var formTemp = UserCenterResourse.DicActionForm[formId]; |
| | | formTemp.CloseForm(); |
| | | UserCenterResourse.DicActionForm.Remove(formId); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 把打开的画面添加到内存中 |
| | | /// </summary> |
| | | /// <param name="form">Form.</param> |
| | | public static void AddActionForm(CommonFormBase form) |
| | | { |
| | | //获取画面英文名字 |
| | | string formId = GetFormID(form); |
| | | |
| | | //二重追加不可 |
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false) |
| | | { |
| | | form.FormID = formId; |
| | | //内存添加 |
| | | UserCenterResourse.DicActionForm[formId] = form; |
| | | //添加画面时,它自身就是激活的界面 |
| | | UserCenterResourse.NowActionFormID = form.FormID; |
| | | |
| | | UserCenterResourse.listActionFormId.Add(form.FormID); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从列表中移除画面 |
| | | /// </summary> |
| | | /// <param name="i_closeForm">关闭的界面</param> |
| | | public static void RemoveActionForm(CommonFormBase i_closeForm) |
| | | { |
| | | //获取画面ID |
| | | string formId = GetFormID(i_closeForm); |
| | | |
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == true) |
| | | { |
| | | //移除ID |
| | | UserCenterResourse.listActionFormId.Remove(formId); |
| | | //移除画面 |
| | | UserCenterResourse.DicActionForm.Remove(formId); |
| | | //清空 |
| | | UserCenterResourse.NowActionFormID = string.Empty; |
| | | |
| | | var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1); |
| | | if (actionForm == null) |
| | | { |
| | | return; |
| | | } |
| | | //如果关闭的界面是DialogCommonForm类型,则不需要触发激活函数 |
| | | if (i_closeForm is DialogCommonForm) |
| | | { |
| | | if (actionForm is EditorCommonForm) |
| | | { |
| | | UserCenterResourse.NowActionFormID = GetFormID((EditorCommonForm)actionForm); |
| | | } |
| | | return; |
| | | } |
| | | //关闭的界面为EditorCommonForm的时候 |
| | | else if ((i_closeForm is EditorCommonForm) && (actionForm is EditorCommonForm)) |
| | | { |
| | | //接下来激活的界面id |
| | | UserCenterResourse.NowActionFormID = GetFormID((CommonFormBase)actionForm); |
| | | try |
| | | { |
| | | var Myform = actionForm as EditorCommonForm; |
| | | //重置左滑使能 |
| | | Myform.ScrollEnabled = Myform.ScrollEnabled; |
| | | //触发界面再次激活的事件 |
| | | int value = Myform.FormActionAgainEvent(); |
| | | if (value == 1) |
| | | { |
| | | //Log出力 |
| | | HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //Log出力 |
| | | HdlLogLogic.Current.WriteLog(ex, "界面重新激活异常 " + UserCenterResourse.NowActionFormID); |
| | | } |
| | | } |
| | | else if (actionForm is UserView.UserPage) |
| | | { |
| | | //清空 |
| | | UserCenterResourse.NowActionFormID = string.Empty; |
| | | //这里它已经退到主页了 |
| | | var nowForm = UserView.UserPage.Instance.GetNowActionForm(); |
| | | nowForm?.FormActionAgainEvent(); |
| | | } |
| | | else |
| | | { |
| | | //清空 |
| | | UserCenterResourse.NowActionFormID = string.Empty; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取画面ID |
| | | /// </summary> |
| | | /// <returns>The form name.</returns> |
| | | /// <param name="form">Form.</param> |
| | | private static string GetFormID(CommonFormBase form) |
| | | { |
| | | if (form.FormID != string.Empty) |
| | | { |
| | | return form.FormID; |
| | | } |
| | | //将命名空间去掉 |
| | | string[] Arry = form.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); |
| | | string formName = Arry[Arry.Length - 1].Trim(); |
| | | return formName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取当前正在激活的画面 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static CommonFormBase GetNowActionForm() |
| | | { |
| | | if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true) |
| | | { |
| | | return UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID]; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 刷新本地缓存_______________________ |
| | | |
| | | /// <summary> |
| | | /// 刷新本地所有缓存(目前此方法只提供给恢复备份数据使用) |
| | | /// </summary> |
| | | public static void RefreshAllMemory() |
| | | { |
| | | //刷新住宅对象 |
| | | RefreshHomeObject(); |
| | | //根据模板文件,恢复数据 |
| | | TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile(); |
| | | //强制生成设备和网关文件 |
| | | TemplateData.TemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce(); |
| | | //刷新本地网关文件 |
| | | HdlGatewayLogic.Current.ReFreshByLocal(); |
| | | //刷新本地设备 |
| | | Common.LocalDevice.Current.ReFreshByLocal(); |
| | | //需优先于刷新房间,同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除 |
| | | HdlGatewayLogic.Current.SynchronizeDbGateway(); |
| | | //从本地重新加载全部的房间 |
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation(); |
| | | //断开远程Mqtt连接,重新连接 |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true); |
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce(); |
| | | }, ShowErrorMode.NO); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 刷新住宅对象 |
| | | /// </summary> |
| | | public static void RefreshHomeObject() |
| | | { |
| | | var home = HdlResidenceLogic.Current.GetHouseByHouseId(Config.Instance.Home.Id); |
| | | |
| | | //刷新楼层 |
| | | Config.Instance.Home.FloorDics = home.FloorDics; |
| | | Config.Instance.Home.CurrentFloorId = string.Empty; |
| | | if (Config.Instance.Home.TemplateMode == -1) |
| | | { |
| | | Config.Instance.Home.TemplateMode = home.TemplateMode; |
| | | if (Config.Instance.Home.TemplateMode == -1) |
| | | { |
| | | //默认初始值 |
| | | Config.Instance.Home.TemplateMode = 1; |
| | | } |
| | | } |
| | | |
| | | Config.Instance.Home.Save(false); |
| | | |
| | | //主页需要重新刷新 |
| | | UserView.UserPage.Instance.RefreshAllForm = true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 重新登录___________________________ |
| | | |
| | | /// <summary> |
| | | /// 重新登录 |
| | | /// </summary> |
| | | /// <param name="account">账号</param> |
| | | /// <param name="noticeDb">是否通知云端</param> |
| | | public static void ReLoginAgain(string account = "", bool noticeDb = true) |
| | | { |
| | | #if iOS |
| | | //退出全视通登录 |
| | | Shared.IOS.HDLFVSDK.Video.Logout(); |
| | | #endif |
| | | if (Config.Instance.Home.IsVirtually == true) |
| | | { |
| | | //如果是虚拟住宅 |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | //设定一个时间 |
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1); |
| | | Config.Instance.Save(); |
| | | //清空当前住宅id |
| | | Config.Instance.HomeId = string.Empty; |
| | | //收起左菜单 |
| | | CommonPage.Instance.CloseLeftMenu(); |
| | | //关闭全部弹窗 |
| | | ShowMsgControl.CloseAllMsgDialog(); |
| | | //关闭所有打开了的界面 |
| | | CloseAllOpenForm(null, false); |
| | | |
| | | //显示登陆画面 |
| | | var formLogin = new Login.AccountLoginForm(); |
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin); |
| | | formLogin.ShowForm(account); |
| | | }); |
| | | return; |
| | | } |
| | | UserCenterResourse.AccountOption.OldAccountId = string.Empty; |
| | | //关闭所有接收 |
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent(); |
| | | //清除升级列表 |
| | | FirmwareUpdateResourse.dicUpdateList.Clear(); |
| | | |
| | | HdlThreadLogic.Current.RunThread(() => |
| | | { |
| | | //检测APP是否能够退出 |
| | | while (UserCenterResourse.AccountOption.AppCanSignout == false) |
| | | { |
| | | System.Threading.Thread.Sleep(500); |
| | | } |
| | | //设定一个时间 |
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1); |
| | | Config.Instance.Save(); |
| | | |
| | | //清空当前住宅id |
| | | Config.Instance.HomeId = string.Empty; |
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(false); |
| | | |
| | | //断开远程Mqtt连接 |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce(); |
| | | }, ShowErrorMode.NO); |
| | | |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | //收起左菜单 |
| | | CommonPage.Instance.CloseLeftMenu(); |
| | | //关闭所有打开了的界面 |
| | | CloseAllOpenForm(null, false); |
| | | |
| | | //显示登陆画面 |
| | | var formLogin = new Login.AccountLoginForm(); |
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin); |
| | | formLogin.ShowForm(account); |
| | | }); |
| | | |
| | | if (noticeDb == true) |
| | | { |
| | | //通知云端,已经退出登陆 |
| | | var result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭所有打开了的界面 |
| | | /// </summary> |
| | | /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param> |
| | | /// <param name="refreshMainPage">当关闭的界面达到主页时,是否刷新主页</param> |
| | | public static void CloseAllOpenForm(string tagetFrom = null, bool refreshMainPage = true) |
| | | { |
| | | while (UserView.HomePage.Instance.ChildrenCount > 0) |
| | | { |
| | | var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1); |
| | | //(因底层控件修改了, 父控件移除时, 不触发子控件的移除事件) |
| | | if (view is ViewGroup) |
| | | { |
| | | //关闭加载在ViewGroup里面的自定义界面Form |
| | | CloseViewGroupChildren((ViewGroup)view); |
| | | } |
| | | |
| | | if (view is CommonFormBase) |
| | | { |
| | | if (((CommonFormBase)view).FormID == tagetFrom) |
| | | { |
| | | //只关闭到指定目标界面 |
| | | return; |
| | | } |
| | | ((CommonFormBase)view).CloseForm(); |
| | | } |
| | | else if (view is UserView.UserPage) |
| | | { |
| | | //刷新主页 |
| | | if (refreshMainPage == true) |
| | | { |
| | | UserView.UserPage.Instance.ReFreshControl(); |
| | | } |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | view.RemoveFromParent(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 关闭加载在ViewGroup里面的自定义界面Form(因底层控件修改了,父控件移除时,不触发子控件的移除事件) |
| | | /// </summary> |
| | | /// <param name="group"></param> |
| | | private static void CloseViewGroupChildren(ViewGroup group) |
| | | { |
| | | for (int i = 0; i < group.ChildrenCount; i++) |
| | | { |
| | | var view = group.GetChildren(i); |
| | | if (view is CommonFormBase) |
| | | { |
| | | ((CommonFormBase)view).CloseForm(); |
| | | i--; |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 拼接信息___________________________ |
| | | |
| | | /// <summary> |
| | | /// 拼接网关回复超时的信息 |
| | | /// </summary> |
| | | /// <param name="errorMsg">错误信息</param> |
| | | /// <param name="resultData">网关返回的resultData,里面有【errorMessageBase】这个东西的那种对象</param> |
| | | /// <param name="strResultData">网关返回的resultData,里面的【errorMessageBase】的值,设定有此值时,resultData无效</param> |
| | | /// <param name="addBrackets">是否添加括号</param> |
| | | /// <returns></returns> |
| | | public static string CombineGatewayTimeOutMsg(string errorMsg, object resultData, string strResultData = null, bool addBrackets = true) |
| | | { |
| | | if (resultData == null && strResultData == null) |
| | | { |
| | | return errorMsg; |
| | | } |
| | | |
| | | string errorMsgBase = strResultData; |
| | | if (errorMsgBase == null) |
| | | { |
| | | if (resultData is ReceiptGatewayResult) |
| | | { |
| | | errorMsgBase = string.Empty; |
| | | if (((ReceiptGatewayResult)resultData).ErrorMsgDiv == 0) |
| | | { |
| | | errorMsgBase = "回复超时"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Type myType = resultData.GetType(); |
| | | object errorObj = myType.InvokeMember("errorMessageBase", System.Reflection.BindingFlags.GetField, null, resultData, null); |
| | | if (errorObj == null) |
| | | { |
| | | return errorMsg; |
| | | } |
| | | errorMsgBase = errorObj.ToString(); |
| | | } |
| | | } |
| | | |
| | | if (errorMsgBase.Contains("回复超时") == false) |
| | | { |
| | | //只有回复超时的时候才会加上 |
| | | return errorMsg; |
| | | } |
| | | errorMsg += "\r\n"; |
| | | if (addBrackets == true) |
| | | { |
| | | //(网关回复超时,请稍后再试) |
| | | return errorMsg + "(" + Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut) + ")"; |
| | | } |
| | | else |
| | | { |
| | | //网关回复超时,请稍后再试 |
| | | return errorMsg + Language.StringByID(R.MyInternationalizationString.uGatewayResponseTimeOut); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 刷新个人中心的内存及线程___________ |
| | | |
| | | /// <summary> |
| | | /// 异步方法执行(仅限切换住宅时调用),刷新个人中心的内存及线程 |
| | | /// </summary> |
| | | /// <param name="ShowPrompted">新追加变量:是否显示提示自动备份的界面</param> |
| | | /// <returns></returns> |
| | | public static bool InitUserCenterMenmoryAndThread(bool ShowPrompted = true) |
| | | { |
| | | //调用这个方法,都需要重新刷新主页 |
| | | UserView.UserPage.Instance.RefreshAllForm = true; |
| | | |
| | | //添加网络状态监听 |
| | | HdlWifiLogic.Current.StartListenNetWork(); |
| | | |
| | | //如果是虚拟住宅 |
| | | if (Config.Instance.Home.IsVirtually == true) |
| | | { |
| | | //初始化虚拟住宅的个人中心的数据(切换住宅使用) |
| | | InitUserCenterMenmoryByVirtualHome(); |
| | | return true; |
| | | } |
| | | |
| | | //APP缓存加载开始 |
| | | UserCenterResourse.AccountOption.AppCanSignout = false; |
| | | //还原远程连接权限变量 |
| | | ZigBee.Device.ZbGateway.AllowRemoteCtrl = true; |
| | | |
| | | //只有在住宅ID不一样的时候才做这个操作 |
| | | if (Common.Config.Instance.HomeId != UserCenterResourse.AccountOption.OldHomeStringId |
| | | || Common.Config.Instance.Account != UserCenterResourse.AccountOption.OldAccountId) |
| | | { |
| | | //借用一下这个变量(检测能否广播到网关) |
| | | UserCenterResourse.DicReceiveGatewayTest = new Dictionary<string, ZigBee.Device.ZbGateway>(); |
| | | UserCenterResourse.HideOption.CheckCanReceiveGateway = 1; |
| | | |
| | | //清空所有成员缓存 |
| | | ClearAllMemberMemory(); |
| | | |
| | | //加载账号配置信息 |
| | | var optionInfo = UserCenterResourse.AccountOption.Load(); |
| | | UserCenterResourse.AccountOption = optionInfo; |
| | | //变更根用户图片目录路径 |
| | | UserCenterResourse.AccountOption.UserPictruePath = DirNameResourse.UserPictrueDirectory; |
| | | |
| | | //加载住宅配置信息 |
| | | UserCenterResourse.ResidenceOption = UserCenterResourse.ResidenceOption.Load(); |
| | | |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | |
| | | //初始化登陆账号的信息 |
| | | var hadNet = InitUserAccoutInfo(true); |
| | | //如果有网络的话 |
| | | if (hadNet == 1) |
| | | { |
| | | //读取隐匿配置 |
| | | //HdlBackupLogic.Current.LoadHideOption(); |
| | | //调试:强制开启后台调试App功能 |
| | | if (UserCenterResourse.HideOption.StartDebugApp == 1) |
| | | { |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | var form = new HideOption.HideOptionMainForm(); |
| | | form.AddForm(); |
| | | }); |
| | | ProgressBar.Close(true); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | //关闭所有接收 |
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent(); |
| | | //刷新安防上报信息 |
| | | HdlAlarmsLogic.Current.RefreshAlarmInfo(); |
| | | |
| | | //保存用户的登陆信息到本地 |
| | | SaveUserInformationToLocation(); |
| | | |
| | | UserCenterResourse.AccountOption.OldHomeStringId = Common.Config.Instance.HomeId; |
| | | UserCenterResourse.AccountOption.OldAccountId = Common.Config.Instance.Account; |
| | | |
| | | //同步数据(二次调用没关系) |
| | | int result = -1; |
| | | if (hadNet == 1) |
| | | { |
| | | result = HdlAutoBackupLogic.SynchronizeDbAutoBackupData(); |
| | | } |
| | | |
| | | //初始化本地的网关信息 |
| | | HdlGatewayLogic.Current.ReFreshByLocal(); |
| | | //初始化本地的设备信息 |
| | | LocalDevice.Current.ReFreshByLocal(); |
| | | |
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步) |
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation(); |
| | | |
| | | if (hadNet == 1) |
| | | { |
| | | //重新发送命令去绑定断网情况下备份的网关 |
| | | HdlGatewayLogic.Current.ResetComandToBindBackupGateway(); |
| | | |
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除 |
| | | HdlGatewayLogic.Current.SynchronizeDbGateway(); |
| | | |
| | | //读取App最低版本 |
| | | HdlFirmwareUpdateLogic.ReadAppLestVersion(); |
| | | //读取网关最低版本 |
| | | HdlFirmwareUpdateLogic.ReadGatewayLestVersion(); |
| | | } |
| | | |
| | | //断开远程Mqtt连接,重新连接 |
| | | HdlThreadLogic.Current.RunThread(async () => |
| | | { |
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true); |
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce(); |
| | | }, ShowErrorMode.NO); |
| | | |
| | | //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用) |
| | | HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId(); |
| | | |
| | | //加载模板缓存 |
| | | //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData(); |
| | | |
| | | //0:已经同步过,不需要同步,这个时候需要提示备份 |
| | | if (result == 0 && ShowPrompted == true) |
| | | { |
| | | //开启自动备份 |
| | | HdlAutoBackupLogic.ShowAutoBackupPromptedForm(); |
| | | } |
| | | //显示引导界面 |
| | | ShowGuideForm(result); |
| | | |
| | | //关闭debug广播 |
| | | UserCenterResourse.HideOption.CheckCanReceiveGateway = 0; |
| | | System.Threading.Thread.Sleep(30); |
| | | if (hadNet == 1) |
| | | { |
| | | //住宅切换时,检测网关连接情况 |
| | | CheckGatewayConnection(); |
| | | } |
| | | UserCenterResourse.DicReceiveGatewayTest = null; |
| | | } |
| | | //APP缓存加载完成 |
| | | UserCenterResourse.AccountOption.AppCanSignout = true; |
| | | if (Shared.Phone.Device.Logic.Send.If_Exist == "1") |
| | | { |
| | | //以本地状态为主打开GPS服务 |
| | | Application.StartGPSLocationService(); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化虚拟住宅的个人中心的数据(切换住宅使用) |
| | | /// </summary> |
| | | private static void InitUserCenterMenmoryByVirtualHome() |
| | | { |
| | | UserCenterResourse.AccountOption.OldHomeStringId = Common.Config.Instance.Home.Id; |
| | | //清空所有成员缓存 |
| | | ClearAllMemberMemory(); |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | //关闭所有接收 |
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent(); |
| | | //初始化本地的网关信息 |
| | | HdlGatewayLogic.Current.ReFreshByLocal(); |
| | | //初始化本地的设备信息 |
| | | Common.LocalDevice.Current.ReFreshByLocal(); |
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步) |
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation(); |
| | | //刷新左边刷新房间视图列表 |
| | | HdlRoomLogic.Current.RefreshRoomListView(); |
| | | //加载模板缓存 |
| | | //TemplateData.TemplateCommonLogic.Current.LoadLocalTemplateMemoryData(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空所有成员缓存 |
| | | /// </summary> |
| | | private static void ClearAllMemberMemory() |
| | | { |
| | | //消息记录重新读取及检测 |
| | | ControlCommonResourse.ReadMessageAgain = true; |
| | | ControlCommonResourse.HadNewMessage = false; |
| | | HdlThreadLogic.Current.RunMain(() => |
| | | { |
| | | for (int i = 0; i < ControlCommonResourse.listMessageManaContr.Count; i++) |
| | | { |
| | | //显示角标特效 |
| | | ControlCommonResourse.listMessageManaContr[i].IsSelected = false; |
| | | } |
| | | }); |
| | | |
| | | //切换住宅清除之前逻辑缓存数据; |
| | | Common.Logic.LogicList.Clear(); |
| | | Common.Logic.LockLogicList.Clear(); |
| | | Common.Logic.SoneLogicList.Clear(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 住宅切换时,检测网关连接情况 |
| | | /// </summary> |
| | | private static void CheckGatewayConnection() |
| | | { |
| | | try |
| | | { |
| | | bool canReceiveGw = false; |
| | | foreach (var gateway in UserCenterResourse.DicReceiveGatewayTest.Values) |
| | | { |
| | | if (gateway.HomeId == Config.Instance.Home.Id) |
| | | { |
| | | //能够搜索得到网关 |
| | | canReceiveGw = true; |
| | | break; |
| | | } |
| | | } |
| | | UserCenterResourse.DicReceiveGatewayTest = null; |
| | | //设置远程连接的初始值 |
| | | ZigBee.Device.ZbGateway.IsRemote = canReceiveGw == false; |
| | | if (canReceiveGw == false) |
| | | { |
| | | //如果是远程的话,追加等待时间 |
| | | System.Threading.Thread.Sleep(1500); |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 初始化登陆账号的信息_______________ |
| | | |
| | | /// <summary> |
| | | /// 初始化登陆账号的信息 -1:无网 1:正常 2:其他错误 |
| | | /// </summary> |
| | | /// <param name="reLoad">是否从新从本地加载(重新初始化登陆账号的信息,不需要重新加载)</param> |
| | | /// <returns></returns> |
| | | private static int InitUserAccoutInfo(bool reLoad) |
| | | { |
| | | //初始化个人信息的标识 |
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = false; |
| | | if (reLoad == true) |
| | | { |
| | | //获取本地记录的用户信息 |
| | | UserCenterResourse.UserInfo = GetUserInformationFromLocation(); |
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, "Admin.png"); |
| | | } |
| | | if (HdlWifiLogic.Current.CanAccessHttp == false) |
| | | { |
| | | //无法连接外网 |
| | | return -1; |
| | | } |
| | | |
| | | //获取登录账号的信息 |
| | | var pra = new AccountInfoPra(); |
| | | //序列化对象 |
| | | var requestJson = JsonConvert.SerializeObject(pra); |
| | | //访问接口 |
| | | byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson), "POST", 4); |
| | | if (byteData == null) |
| | | { |
| | | return -1; |
| | | } |
| | | //检测错误 |
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData)); |
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS") |
| | | { |
| | | return 2; |
| | | } |
| | | |
| | | var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(revertObj.ResponseData.ToString()); |
| | | userInfo.Account = Common.Config.Instance.Account; |
| | | if (string.IsNullOrEmpty(userInfo.UserName) == true) |
| | | { |
| | | //没有昵称的时候,把账号作为昵称 |
| | | userInfo.UserName = Common.Config.Instance.Account; |
| | | } |
| | | |
| | | if (Common.Config.Instance.Home.IsOthreShare == false) |
| | | { |
| | | //身份:管理员 |
| | | userInfo.AuthorityNo = 1; |
| | | userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.Administrator); |
| | | } |
| | | else if (Common.Config.Instance.Home.AccountType == 1) |
| | | { |
| | | //身份:成员(拥有管理员权限) |
| | | userInfo.AuthorityNo = 2; |
| | | userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMemberHadActionAuthority); |
| | | } |
| | | else |
| | | { |
| | | //身份:成员 |
| | | userInfo.AuthorityNo = 3; |
| | | userInfo.AuthorityText = Language.StringByID(R.MyInternationalizationString.uMember); |
| | | } |
| | | |
| | | //UserInfo.AuthorityNo==0代表本地还没有生成文件,这个时候不需要处理 |
| | | if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo |
| | | && UserCenterResourse.UserInfo.AuthorityNo != 0) |
| | | { |
| | | //如果登陆的账号的权限和上一次的不一样,则删除本地这个住宅全部的文件,从头再来 |
| | | string dirPath = Config.Instance.FullPath; |
| | | if (System.IO.Directory.Exists(dirPath) == true) |
| | | { |
| | | try |
| | | { |
| | | //同步数据的判断文件(以防万一删除整个文件夹失败的时候,这个文件被删的话,应该没什么大问题) |
| | | string SynchronizeFile = DirNameResourse.AutoDownLoadBackupCheckFile; |
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原 |
| | | HdlFileLogic.Current.DeleteFile(SynchronizeFile); |
| | | HdlFileLogic.Current.DeleteDirectory(dirPath); |
| | | } |
| | | catch { } |
| | | //创建住宅文件夹 |
| | | Global.CreateHomeDirectory(Config.Instance.HomeId); |
| | | //预创建个人中心全部的文件夹 |
| | | HdlFileLogic.Current.CreatAllUserCenterDirectory(); |
| | | } |
| | | } |
| | | if (string.IsNullOrEmpty(userInfo.UserName) == true) |
| | | { |
| | | //没有昵称的话,把账号丢过去 |
| | | userInfo.UserName = userInfo.Account; |
| | | } |
| | | |
| | | UserCenterResourse.UserInfo = userInfo; |
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, "Admin.png"); |
| | | if (UserCenterResourse.UserInfo.HeadImage != null) |
| | | { |
| | | //写入头像内容 |
| | | HdlFileLogic.Current.SaveByteToFile(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage); |
| | | } |
| | | UserCenterResourse.UserInfo.HeadImage = null; |
| | | //手势密码 |
| | | UserCenterResourse.AccountOption.GestureAuthentication = UserCenterResourse.UserInfo.GesturePwd == null ? string.Empty : UserCenterResourse.UserInfo.GesturePwd; |
| | | UserCenterResourse.UserInfo.GesturePwd = null; |
| | | //密码验证 |
| | | UserCenterResourse.AccountOption.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd; |
| | | UserCenterResourse.UserInfo.StringPwd = null; |
| | | //保存缓存 |
| | | UserCenterResourse.AccountOption.Save(); |
| | | |
| | | //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次) |
| | | var flage = InitAdminConnectMainInfo(); |
| | | //初始化个人信息的标识 |
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = flage == 1; |
| | | |
| | | return flage; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从本地获取用户的登陆信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private static UserInformation GetUserInformationFromLocation() |
| | | { |
| | | var value = HdlFileLogic.Current.ReadFileTextContent(DirNameResourse.UserInfoFile); |
| | | if (value == null) |
| | | { |
| | | return new UserInformation(); |
| | | } |
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value); |
| | | return info; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 重新初始化登陆账号的信息(旨在对应那一瞬间,网络不好,导致误判的情况) |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static bool ReInitUserAccoutInfo() |
| | | { |
| | | //重新初始化账号信息 |
| | | var result = InitUserAccoutInfo(false); |
| | | if (result == 1) |
| | | { |
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除 |
| | | HdlGatewayLogic.Current.SynchronizeDbGateway(); |
| | | //初始化个人信息的标识 |
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = true; |
| | | |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存用户的登陆信息到本地 |
| | | /// </summary> |
| | | private static void SaveUserInformationToLocation() |
| | | { |
| | | //写入内容 |
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.UserInfoFile, UserCenterResourse.UserInfo); |
| | | |
| | | //搞一下主人的默认头像 |
| | | string defultFile = IO.FileUtils.GetImageFilePath("Center/Admin.png"); |
| | | if (defultFile == string.Empty) |
| | | { |
| | | return; |
| | | } |
| | | if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true) |
| | | { |
| | | return; |
| | | } |
| | | //复制过去 |
| | | System.IO.File.Copy(defultFile, UserCenterResourse.UserInfo.UserIconFile); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 初始化管理员权限远程连接___________ |
| | | |
| | | /// <summary> |
| | | /// 初始化管理员权限远程连接主人的信息 -1:无网 1:正常 2:其他错误 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private static int InitAdminConnectMainInfo() |
| | | { |
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3) |
| | | { |
| | | //时代变了,这里管理员和成员都能调用 |
| | | return 1; |
| | | } |
| | | var pra = new |
| | | { |
| | | CommonPage.RequestVersion, |
| | | LoginAccessToken = Config.Instance.Token, |
| | | MainAccountId = Config.Instance.Home.MainUserDistributedMark, |
| | | SharedHid = Config.Instance.Home.Id |
| | | }; |
| | | |
| | | //序列化对象 |
| | | var requestJson = JsonConvert.SerializeObject(pra); |
| | | //访问接口 |
| | | byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("App/GetSharedHomeApiControl", Encoding.UTF8.GetBytes(requestJson)); |
| | | if (byteData == null) |
| | | { |
| | | return -1; |
| | | } |
| | | //检测错误 |
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData)); |
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS") |
| | | { |
| | | return 2; |
| | | } |
| | | |
| | | //分享链接 |
| | | var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(revertObj.ResponseData.ToString()); |
| | | Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl; |
| | | Config.Instance.AdminRequestToken = info.RequestToken; |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 获取控制主人账号的Token____________ |
| | | |
| | | /// <summary> |
| | | /// 获取控制主人账号的Token |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static string GetConnectMainToken() |
| | | { |
| | | //启用管理员权限 |
| | | if (Config.Instance.Home.IsOthreShare == true) |
| | | { |
| | | return Config.Instance.AdminRequestToken; |
| | | } |
| | | return Config.Instance.Token; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 引导界面___________________________ |
| | | |
| | | /// <summary> |
| | | /// 显示引导界面 |
| | | /// </summary> |
| | | /// <param name="result">同步结果 -1:异常 0:已经同步过,不需要同步 1:正常同步 2:没有自动备份数据</param> |
| | | private static void ShowGuideForm(int result) |
| | | { |
| | | var checkFile = 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> |
| | | /// 将16进制的文本翻译为正常文本 |
| | | /// </summary> |
| | | /// <param name="hexText">16进制的文本</param> |
| | | /// <param name="count">以多少个字节为一组</param> |
| | | /// <returns></returns> |
| | | public static string TranslateHexadecimalIntoText(string hexText, int count = 2) |
| | | { |
| | | string textValue = string.Empty; |
| | | while (hexText.Length > 0) |
| | | { |
| | | string temp = hexText.Substring(0, count); |
| | | hexText = hexText.Substring(count); |
| | | int value = Convert.ToInt32(temp, 16); |
| | | textValue += ((char)value).ToString(); |
| | | } |
| | | return textValue; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将文本翻译为16进制的文本 |
| | | /// </summary> |
| | | /// <param name="text">指定文本</param> |
| | | /// <returns></returns> |
| | | public static string TranslateTextIntoHexadecimal(string text) |
| | | { |
| | | string textValue = string.Empty; |
| | | foreach (char c in text) |
| | | { |
| | | int value = Convert.ToInt32(c); |
| | | textValue += Convert.ToString(value, 16); |
| | | } |
| | | return textValue; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 加密和解密_________________________ |
| | | |
| | | /// <summary> |
| | | /// 加密密码 |
| | | /// </summary> |
| | | /// <param name="keys"></param> |
| | | /// <param name="strPsw"></param> |
| | | /// <returns></returns> |
| | | public static string EncryptPassword(string keys, string strPsw) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(strPsw) == true) |
| | | { |
| | | 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(); |
| | | } |
| | | catch { return strPsw; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 解密密码 |
| | | /// </summary> |
| | | /// <param name="strPsw"></param> |
| | | /// <returns></returns> |
| | | public static string DecryptPassword(string keys, string strPsw) |
| | | { |
| | | try |
| | | { |
| | | 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()); |
| | | } |
| | | 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 |
| | | } |
| | | } |