| | |
| | | using Shared.Common;
|
| | | using Newtonsoft.Json;
|
| | | using Shared.Common.ResponseEntity;
|
| | | using System.Threading.Tasks;
|
| | | using System.Text.RegularExpressions;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | |
|
| | |
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">
|
| | | /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</pra>
|
| | | /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回【false】</pra>
|
| | | /// </param>
|
| | | public static async Task<bool> GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
|
| | | /// <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 = false)
|
| | | {
|
| | | if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
|
| | | {
|
| | | //当前无法访问网络(当需要重新发送时,跳过这个判断)
|
| | | ShowNotNetMsg(listNotShowError);
|
| | | return false;
|
| | | }
|
| | | //检测是否已经完成账号信息初始化
|
| | | if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
|
| | | {
|
| | | //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
|
| | | ReInitUserAccoutInfo(listNotShowError);
|
| | | return false;
|
| | | }
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null)
|
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null && setAgain == true)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
|
| | | if (setAgain == false)
|
| | | {
|
| | | //不指定重发
|
| | | return false;
|
| | | }
|
| | | byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | byteData = ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | return false;
|
| | |
| | | }
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | //检测是否存在错误信息
|
| | | return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError);
|
| | | return CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">
|
| | | /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【Success】</pra>
|
| | | /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回【ErrorEx】</pra>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
|
| | | /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
|
| | | /// </param>
|
| | | public static async Task<string> GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
|
| | | public static string GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
|
| | | {
|
| | | if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
|
| | | {
|
| | | //当前无法访问网络(当需要重新发送时,跳过这个判断)
|
| | | ShowNotNetMsg(listNotShowError);
|
| | | return "Error";
|
| | | }
|
| | | //检测是否已经完成账号信息初始化
|
| | | if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
|
| | | {
|
| | | //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
|
| | | ReInitUserAccoutInfo(listNotShowError);
|
| | | return "Error";
|
| | | }
|
| | |
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
|
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
|
| | | if (setAgain == false)
|
| | | {
|
| | | return "ErrorEx";
|
| | | //不指定重发
|
| | | return "Error";
|
| | | }
|
| | | byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">
|
| | | /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回空字符串</pra>
|
| | | /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回空字符串</pra>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回【true】</param>
|
| | | /// <param name="setAgain">当发送失败时,是否重发,默认不重发</param>
|
| | | /// </param>
|
| | | public static async Task<string> GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
|
| | | public static string GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null, bool setAgain = false)
|
| | | {
|
| | | if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
|
| | | {
|
| | | //当前无法访问网络(当需要重新发送时,跳过这个判断)
|
| | | ShowNotNetMsg(listNotShowError);
|
| | | return null;
|
| | | }
|
| | | //检测是否已经完成账号信息初始化
|
| | | if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
|
| | | {
|
| | | //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
|
| | | ReInitUserAccoutInfo(listNotShowError);
|
| | | return null;
|
| | | }
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
|
| | | var byteData = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (byteData == null)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
|
| | | if (setAgain == false)
|
| | | {
|
| | | return string.Empty;
|
| | | //不指定重发
|
| | | return null;
|
| | | }
|
| | | byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | 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);
|
| | | bool notError = CheckNotEorrorMsg(revertObj, RequestName, listNotShowError, obj);
|
| | | if (notError == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | if (revertObj == null || revertObj.ResponseData == null)
|
| | | {
|
| | | return string.Empty;
|
| | | return null;
|
| | | }
|
| | | return revertObj.ResponseData.ToString();
|
| | | }
|
| | |
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <param name="listNotShowError">
|
| | | /// <pra>不需要显示错误的错误类别(接口返回的错误类别),如果包含,则会返回空字符串</pra>
|
| | | /// <pra>如果指定有NotSetAgain,则不二次发送(比如断网),然后返回null</pra>
|
| | | /// </param>
|
| | | public static async Task<byte[]> GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
|
| | | /// <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 = false)
|
| | | {
|
| | | if (HdlWifiLogic.Current.CanAccessHttp == false && setAgain == false)
|
| | | {
|
| | | //当前无法访问网络(当需要重新发送时,跳过这个判断)
|
| | | ShowNotNetMsg(listNotShowError);
|
| | | return null;
|
| | | }
|
| | | //检测是否已经完成账号信息初始化
|
| | | if (UserCenterResourse.UserInfo.InitUserInfoSuccess == false)
|
| | | {
|
| | | //不管结果怎么样,如果调用了这个函数,需要重头获取Token,所以必须返回失败
|
| | | ReInitUserAccoutInfo(listNotShowError);
|
| | | return null;
|
| | | }
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | | //获取从接口那里取到的比特数据
|
| | | var revertObj = await GettByteResponsePack(RequestName, connectMode, obj);
|
| | | var revertObj = GettByteResponsePack(RequestName, connectMode, obj);
|
| | |
|
| | | if (revertObj == null)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
|
| | | if (setAgain == false)
|
| | | {
|
| | | //不指定重发
|
| | | return null;
|
| | | }
|
| | | //重新发送
|
| | | revertObj = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | revertObj = ResetByteRequestHttps(RequestName, checkAuthority, obj);
|
| | | if (revertObj == null)
|
| | | {
|
| | | return null;
|
| | |
| | | var data = JsonConvert.DeserializeObject<ResponsePack>(data2);
|
| | | if (data != null && string.IsNullOrEmpty(data.StateCode) == false)
|
| | | {
|
| | | bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError);
|
| | | bool notError = CheckNotEorrorMsg(data, RequestName, listNotShowError, obj);
|
| | | if (notError == false)
|
| | | {
|
| | | return null;
|
| | |
| | | /// <param name="checkAuthority">是否检测权限,该参数不能省略</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | /// <returns></returns>
|
| | | private static async Task<byte[]> ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
|
| | | private static byte[] ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
|
| | | {
|
| | | //获取接口的连接模式
|
| | | var connectMode = GetHttpConnectMode(checkAuthority);
|
| | |
| | | int count = 0;
|
| | | while (true)
|
| | | {
|
| | | await Task.Delay(1000);
|
| | | System.Threading.Thread.Sleep(1000);
|
| | | //调用接口
|
| | | responsePack = await GettByteResponsePack(RequestName, connectMode, obj);
|
| | | responsePack = GettByteResponsePack(RequestName, connectMode, obj);
|
| | | if (responsePack != null)
|
| | | {
|
| | | break;
|
| | |
| | | count++;
|
| | | if (count == 3)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | //网络不稳定,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | | });
|
| | | //显示没有网络的Msg
|
| | | ShowNotNetMsg(null);
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | /// <param name="RequestName">访问地址</param>
|
| | | /// <param name="connectMode">接口的连接模式</param>
|
| | | /// <param name="obj">一个类</param>
|
| | | private static async Task<byte[]> GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
|
| | | private static byte[] GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
|
| | | {
|
| | | try
|
| | | {
|
| | |
| | | if (connectMode == HttpConnectMode.Normal)
|
| | | {
|
| | | //普通访问
|
| | | result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
|
| | | result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
|
| | | }
|
| | | else if (connectMode == HttpConnectMode.Admin)
|
| | | {
|
| | | //以管理员的身份访问,自身是成员
|
| | | result = await CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson));
|
| | | result = CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, Encoding.UTF8.GetBytes(requestJson));
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
| | | /// <param name="revertObj">从接口接收到的数据</param>
|
| | | /// <param name="RequestName">请求接口</param>
|
| | | /// <param name="listNotShowError">不需要显示错误的错误类别(接口返回的错误类别)</param>
|
| | | public static bool CheckNotEorrorMsg(ResponsePack revertObj, string RequestName, List<string> listNotShowError = null)
|
| | | /// <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(() =>
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //网络不稳定,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | | });
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | return false;
|
| | | }
|
| | |
| | | //不显示错误,然后返回true
|
| | | return true;
|
| | | }
|
| | | Application.RunOnMainThread(() =>
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | if (UserCenterLogic.IsAccountLoginOut() == true)
|
| | | if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
|
| | | {
|
| | | //如果用户已经退出了登陆,则不处理
|
| | | return;
|
| | | }
|
| | | string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | |
|
| | | //无效登录Token
|
| | | if (revertObj.StateCode == "NoLogin")
|
| | | string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj, pra);
|
| | | if (msg != null)
|
| | | {
|
| | | UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | |
|
| | | //无效登录Token
|
| | | if (revertObj.StateCode == "NoLogin")
|
| | | {
|
| | | ReLoginAgain(Config.Instance.Account, false);
|
| | | }
|
| | | }
|
| | | });
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | return false;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="checkAuthority">是否检测权限</param>
|
| | | /// <returns></returns>
|
| | | private static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
|
| | | public static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
|
| | | {
|
| | | if (checkAuthority == false)
|
| | | {
|
| | | return HttpConnectMode.Normal;
|
| | | }
|
| | | if (Config.Instance.isAdministrator == true)
|
| | | if (Config.Instance.Home.IsOthreShare == true)
|
| | | {
|
| | | return HttpConnectMode.Admin;
|
| | | }
|
| | | return HttpConnectMode.Normal;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 显示没有网络的Msg
|
| | | /// </summary>
|
| | | private static void ShowNotNetMsg(List<string> listNotShowError)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
|
| | | {
|
| | | //不检测
|
| | | return;
|
| | | }
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | // 当前无网络连接,请确认网络
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork);
|
| | | var control = new ShowMsgControl(ShowMsgType.Tip, msg);
|
| | | control.Show();
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | public static bool CheckCanAddForm(CommonFormBase form)
|
| | | {
|
| | | //获取画面英文名字
|
| | | string formName = GetFormName(form);
|
| | | string formId = GetFormID(form);
|
| | |
|
| | | //二重追加不可
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | //暂时这样弄看看,如果重复,则关闭掉原来的界面
|
| | | var formTemp = UserCenterResourse.DicActionForm[formName];
|
| | | var formTemp = UserCenterResourse.DicActionForm[formId];
|
| | | formTemp.CloseForm();
|
| | | UserCenterResourse.DicActionForm.Remove(formName);
|
| | | formTemp = null;
|
| | | UserCenterResourse.DicActionForm.Remove(formId);
|
| | |
|
| | | return true;
|
| | | }
|
| | |
| | | public static void AddActionForm(CommonFormBase form)
|
| | | {
|
| | | //获取画面英文名字
|
| | | string formName = GetFormName(form);
|
| | | string formId = GetFormID(form);
|
| | |
|
| | | //二重追加不可
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == false)
|
| | | {
|
| | | form.FormID = formName;
|
| | | form.FormID = formId;
|
| | | //内存添加
|
| | | UserCenterResourse.DicActionForm[formName] = form;
|
| | | UserCenterResourse.DicActionForm[formId] = form;
|
| | | //添加画面时,它自身就是激活的界面
|
| | | UserCenterResourse.NowActionFormID = form.FormID;
|
| | |
|
| | |
| | | /// <summary>
|
| | | /// 从列表中移除画面
|
| | | /// </summary>
|
| | | /// <param name="form">Form</param>
|
| | | public static void RemoveActionForm(CommonFormBase form)
|
| | | /// <param name="i_closeForm">关闭的界面</param>
|
| | | public static void RemoveActionForm(CommonFormBase i_closeForm)
|
| | | {
|
| | | //获取画面英文名字
|
| | | string formName = GetFormName(form);
|
| | | //获取画面ID
|
| | | string formId = GetFormID(i_closeForm);
|
| | |
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formName) == true)
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(formId) == true)
|
| | | {
|
| | | //刷新当前正在操作的画面ID
|
| | | if (UserCenterResourse.NowActionFormID == UserCenterResourse.DicActionForm[formName].FormID)
|
| | | //移除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)
|
| | | {
|
| | | //向前推一位即为下一个激活的界面
|
| | | int index = UserCenterResourse.listActionFormId.IndexOf(UserCenterResourse.NowActionFormID) - 1;
|
| | | //初始值
|
| | | UserCenterResourse.NowActionFormID = string.Empty;
|
| | | if (index >= 0)
|
| | | return;
|
| | | }
|
| | | //如果关闭的界面是DialogCommonForm类型,则不需要触发激活函数
|
| | | if (i_closeForm is DialogCommonForm)
|
| | | {
|
| | | if (actionForm is EditorCommonForm)
|
| | | {
|
| | | var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
|
| | | if (actionForm != null && actionForm is CommonFormBase)
|
| | | 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)
|
| | | {
|
| | | //设置当前激活的画面ID
|
| | | UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
|
| | | {
|
| | | //触发界面再次激活的事件
|
| | | UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID]?.FormActionAgainEvent();
|
| | | }
|
| | | }
|
| | | else if (actionForm != null && actionForm is UserView.UserPage)
|
| | | {
|
| | | //这里它已经退到主页了,如果它包含个人中心主页的话
|
| | | if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == true)
|
| | | {
|
| | | //设置当前激活的画面ID
|
| | | UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
|
| | | if (UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
|
| | | {
|
| | | //触发界面再次激活的事件
|
| | | UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID]?.FormActionAgainEvent();
|
| | | }
|
| | | }
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 被激活");
|
| | | }
|
| | | }
|
| | | catch (Exception ex)
|
| | | {
|
| | | //Log出力
|
| | | HdlLogLogic.Current.WriteLog(ex, "界面重新激活异常 " + UserCenterResourse.NowActionFormID);
|
| | | }
|
| | | }
|
| | | //移除ID
|
| | | UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
|
| | | //移除画面
|
| | | var formTemp = UserCenterResourse.DicActionForm[formName];
|
| | | UserCenterResourse.DicActionForm.Remove(formName);
|
| | | formTemp = null;
|
| | | 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>
|
| | | public static string GetFormName(CommonFormBase form)
|
| | | private static string GetFormID(CommonFormBase form)
|
| | | {
|
| | | if (form.FormID != string.Empty)
|
| | | {
|
| | |
| | | /// </summary>
|
| | | public static void RefreshAllMemory()
|
| | | {
|
| | | //备份的数据,有可能是主人自己上传的,如果管理员登陆时,他获取的备份数据有点特殊
|
| | | //比如下面这三个东西在主账号那里是不需要的
|
| | | bool isOthreShare = Config.Instance.Home.IsOthreShare;
|
| | | int accountType = Config.Instance.Home.AccountType;
|
| | | string mainMark = Config.Instance.Home.MainUserDistributedMark;
|
| | | //还原住宅对象
|
| | | Config.Instance.Home = House.GetHouseByHouseId(Config.Instance.Home.Id);
|
| | | Config.Instance.Home.IsOthreShare = isOthreShare;
|
| | | Config.Instance.Home.AccountType = accountType;
|
| | | Config.Instance.Home.MainUserDistributedMark = mainMark;
|
| | | Config.Instance.Home.Save();
|
| | |
|
| | | //刷新住宅对象
|
| | | RefreshHomeObject();
|
| | | //刷新本地网关文件
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //刷新本地设备
|
| | |
| | | //需优先于刷新房间,同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | //从本地重新加载全部的房间
|
| | | Common.Room.RefreshAllRoomByLocation();
|
| | | HdlRoomLogic.Current.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 = HdlResidenceLogic.Current.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
|
| | |
| | | /// <param name="all">true:全部删除(用于住宅删除) false:重要的文件不删除</param>
|
| | | public static void DeleteAllLocationFile(bool all = true)
|
| | | {
|
| | | string dPath = UserCenterResourse.LocalRootPath;
|
| | | string dPath = Config.Instance.FullPath;
|
| | | if (System.IO.Directory.Exists(dPath) == false)
|
| | | {
|
| | | return;
|
| | |
| | | //不能删除Config文件
|
| | | return true;
|
| | | }
|
| | | else if (fileName.StartsWith("DeviceUI_") == true)
|
| | | {
|
| | | //不能删除设备UI文件
|
| | | return true;
|
| | | }
|
| | | else if (fileName.StartsWith("House_") == true)
|
| | | {
|
| | | //不能删除住宅文件
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 各种正确检测_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含大写字母
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain upper was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainUpper(string value)
|
| | | {
|
| | | Regex reg = new Regex("[A-Z]+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含小写字母
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainLower(string value)
|
| | | {
|
| | | Regex reg = new Regex("[a-z]+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含数字
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainNum(string value)
|
| | | {
|
| | | Regex reg = new Regex("[0-9]+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 判断是否包含符号
|
| | | /// </summary>
|
| | | /// <returns><c>true</c>, if contain lower was checked, <c>false</c> otherwise.</returns>
|
| | | /// <param name="value">Value.</param>
|
| | | public static bool CheckContainSymbol(string value)
|
| | | {
|
| | | Regex reg = new Regex("([^a-z0-9A-Z])+");
|
| | | return reg.IsMatch(value);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测邮箱是否合法
|
| | | /// </summary>
|
| | | /// <param name="email"></param>
|
| | | /// <returns></returns>
|
| | | public static bool CheckEmail(string email)
|
| | | {
|
| | | Regex reg = new Regex(CommonPage.EmailRegexStr);
|
| | | return reg.IsMatch(email);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测手机号是否合法
|
| | | /// </summary>
|
| | | /// <param name="phoneNumber">手机号</param>
|
| | | /// <param name="areaCode">地区代码</param>
|
| | | /// <returns></returns>
|
| | | public static bool CheckPhoneNumber(string phoneNumber, string areaCode)
|
| | | {
|
| | | //校验外国手机号
|
| | | if (areaCode != "86")
|
| | | {
|
| | | Regex reg = new Regex(CommonPage.PhoneForForeignRegexStr);
|
| | | return reg.IsMatch(phoneNumber);
|
| | | }
|
| | |
|
| | | //校验国内手机号
|
| | | if (phoneNumber.Length > 11)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | else if (phoneNumber.Length == 11)
|
| | | {
|
| | | Regex reg = new Regex(CommonPage.PhoneRegexStr);
|
| | | return reg.IsMatch(phoneNumber);
|
| | | }
|
| | | else
|
| | | {
|
| | | //正则表达式判断是否数字
|
| | | Regex reg = new Regex("^[0-9]*$");
|
| | | return reg.IsMatch(phoneNumber);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | /// <param name="noticeDb">是否通知云端</param>
|
| | | public static void ReLoginAgain(string account = "", bool noticeDb = true)
|
| | | {
|
| | | UserCenterResourse.oldAccountId = string.Empty;
|
| | | //关闭所有接收
|
| | | HdlDeviceAttributeLogic.Current.RemoveAllEvent();
|
| | | //清除升级列表
|
| | | FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
|
| | | FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
|
| | |
|
| | | new System.Threading.Thread(async () =>
|
| | | if (Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //在APP的缓存还没有加载和读取完成之前,最好别让它下线
|
| | | while (UserCenterResourse.AppLoadMenmoryFinish == false)
|
| | | //如果是虚拟住宅
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | await Task.Delay(500);
|
| | | //设定一个时间
|
| | | Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
|
| | | //清空当前住宅id
|
| | | Config.Instance.HomeId = string.Empty;
|
| | | Config.Instance.Save();
|
| | | //收起左菜单
|
| | | CommonPage.Instance.CloseLeftMenu();
|
| | | //关闭所有打开了的界面
|
| | | CloseAllOpenForm();
|
| | |
|
| | | //显示登陆画面
|
| | | 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
|
| | | Shared.Common.Config.Instance.HomeId = string.Empty;
|
| | | Config.Instance.HomeId = string.Empty;
|
| | | HdlGatewayLogic.Current.ClearAllRealGateway();
|
| | | try
|
| | | {
|
| | | ZigBee.Device.ZbGateway.RemoteMqttClient?.DisconnectAsync();
|
| | | ZigBee.Device.ZbGateway.RemoteMqttClient = null;
|
| | | }
|
| | | catch { }
|
| | |
|
| | | if (noticeDb == true)
|
| | | //断开远程Mqtt连接
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | //通知云端,已经退出登陆
|
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
|
| | | }
|
| | | Application.RunOnMainThread(() =>
|
| | | await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | //收起左菜单
|
| | | CommonPage.Instance.CloseLeftMenu();
|
| | | //关闭所有打开了的界面
|
| | | CloseAllOpenForm();
|
| | |
|
| | | //显示登陆画面
|
| | | var formLogin = new Shared.Phone.Device.Account.AccountLogin();
|
| | | var formLogin = new Login.AccountLoginForm();
|
| | | Shared.Common.CommonPage.Instance.AddChidren(formLogin);
|
| | | formLogin.Show(account);
|
| | | formLogin.ShowForm(account);
|
| | | });
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | |
|
| | | if (noticeDb == true)
|
| | | {
|
| | | //通知云端,已经退出登陆
|
| | | var result = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 关闭所有打开了的界面
|
| | | /// </summary>
|
| | | public static void CloseAllOpenForm()
|
| | | /// <param name="tagetFrom">目标界面,如果指定了的话,则关闭目标界面上层的全部界面(它自身不关闭)</param>
|
| | | public static void CloseAllOpenForm(string tagetFrom = null)
|
| | | {
|
| | | var listForm = new List<CommonFormBase>();
|
| | | var listId = new List<string>();
|
| | | foreach (CommonFormBase form in UserCenterResourse.DicActionForm.Values)
|
| | | while (UserView.HomePage.Instance.ChildrenCount > 0)
|
| | | {
|
| | | if (form.FormID != "UserMainForm")
|
| | | var view = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
|
| | | //(因底层控件修改了, 父控件移除时, 不触发子控件的移除事件)
|
| | | if (view is ViewGroup)
|
| | | {
|
| | | listForm.Insert(0, form);
|
| | | listId.Add(form.FormID);
|
| | | //关闭加载在ViewGroup里面的自定义界面Form
|
| | | CloseViewGroupChildren((ViewGroup)view);
|
| | | }
|
| | |
|
| | | if (view is CommonFormBase)
|
| | | {
|
| | | if (((CommonFormBase)view).FormID == tagetFrom)
|
| | | {
|
| | | //只关闭到指定目标界面
|
| | | return;
|
| | | }
|
| | | ((CommonFormBase)view).CloseForm();
|
| | | }
|
| | | else if (view is UserView.UserPage)
|
| | | {
|
| | | return;
|
| | | }
|
| | | else
|
| | | {
|
| | | view.RemoveFromParent();
|
| | | }
|
| | | }
|
| | | foreach (var id in listId)
|
| | | {
|
| | | UserCenterResourse.DicActionForm.Remove(id);
|
| | | }
|
| | |
|
| | | //关闭所有画面
|
| | | foreach (CommonFormBase form in listForm)
|
| | | {
|
| | | form.CloseForm();
|
| | | }
|
| | | listForm.Clear();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 子控件的Y轴坐标____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 指定位置类型获取Rowlayout的子控件的Y轴坐标(请确保子控件不大于父容器)
|
| | | /// 关闭加载在ViewGroup里面的自定义界面Form(因底层控件修改了,父控件移除时,不触发子控件的移除事件)
|
| | | /// </summary>
|
| | | /// <param name="fatherCtrHeight">父控件的真实高度</param>
|
| | | /// <param name="ctrHeight">子控件的真实高度</param>
|
| | | /// <param name="alignment">位置对齐方式</param>
|
| | | /// <param name="Space">上下间的空白间距,省略时,取行控件共通变量的值。设置为-1时,不计算空白间距</param>
|
| | | /// <returns></returns>
|
| | | public static int GetControlChidrenYaxis(int fatherCtrHeight, int ctrHeight, UViewAlignment alignment, int Space = 0)
|
| | | /// <param name="group"></param>
|
| | | private static void CloseViewGroupChildren(ViewGroup group)
|
| | | {
|
| | | if (Space == 0)
|
| | | for (int i = 0; i < group.ChildrenCount; i++)
|
| | | {
|
| | | //获取行控件的间距
|
| | | if (fatherCtrHeight == ControlCommonResourse.ListViewRowHeight)
|
| | | var view = group.GetChildren(i);
|
| | | if (view is CommonFormBase)
|
| | | {
|
| | | Space = ControlCommonResourse.ListViewRowSpace;
|
| | | ((CommonFormBase)view).CloseForm();
|
| | | i--;
|
| | | }
|
| | | }
|
| | |
|
| | | if (Space < 0)
|
| | | {
|
| | | //不计算间距值
|
| | | Space = 0;
|
| | | }
|
| | |
|
| | | if (alignment == UViewAlignment.Center)
|
| | | {
|
| | | return fatherCtrHeight / 2 - ctrHeight / 2;
|
| | | }
|
| | | else if (alignment == UViewAlignment.Top)
|
| | | {
|
| | | return (fatherCtrHeight / 2 - Space / 2) / 2 - ctrHeight / 2;
|
| | | }
|
| | | else
|
| | | {
|
| | | int top = fatherCtrHeight / 2 + Space / 2;
|
| | | return top + (fatherCtrHeight - top) / 2 - ctrHeight / 2;
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// <returns></returns>
|
| | | public static string CombinePath(params object[] listNames)
|
| | | {
|
| | | string rootPath = UserCenterResourse.LocalRootPath;
|
| | | string rootPath = Config.Instance.FullPath;
|
| | | if (listNames == null || listNames.Length == 0)
|
| | | {
|
| | | return rootPath;
|
| | |
| | | string errorMsgBase = strResultData;
|
| | | if (errorMsgBase == null)
|
| | | {
|
| | | Type myType = resultData.GetType();
|
| | | object errorObj = myType.InvokeMember("errorMessageBase", System.Reflection.BindingFlags.GetField, null, resultData, null);
|
| | | if (errorObj == null)
|
| | | if (resultData is ReceiptGatewayResult)
|
| | | {
|
| | | return errorMsg;
|
| | | errorMsgBase = string.Empty;
|
| | | if (((ReceiptGatewayResult)resultData).ErrorMsgDiv == 0)
|
| | | {
|
| | | errorMsgBase = "回复超时";
|
| | | }
|
| | | }
|
| | | errorMsgBase = errorObj.ToString();
|
| | | 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)
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 检测网关共通错误状态码_____________
|
| | |
|
| | | /// <summary>
|
| | | /// <para>检测网关返回的共通错误状态码(返回null则代表没有错误),支持状态码为</para>
|
| | | /// <para>1:网关无法解析命令数据。</para> |
| | | /// <para>2:协调器正在升级或备份/恢复数据</para> |
| | | /// <para>3:操作设备/组/场景不存在</para> |
| | | /// <para>4:其他错误</para> |
| | | /// <para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary>
|
| | | /// <param name="resultData">网关返回的resultData,里面有【errorResponData】这个东西的那种对象</param>
|
| | | /// <returns></returns>
|
| | | public static string CheckCommonErrorCode(object resultData)
|
| | | {
|
| | | if (resultData == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Type myType = resultData.GetType();
|
| | | object errorObj = myType.InvokeMember("errorResponData", System.Reflection.BindingFlags.GetField, null, resultData, null);
|
| | | if (errorObj == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | Type type = errorObj.GetType();
|
| | | var code = type.InvokeMember("Error", System.Reflection.BindingFlags.GetField, null, errorObj, null);
|
| | | int errorCode = Convert.ToInt32(code);
|
| | |
|
| | | return CheckCommonErrorCode(errorCode);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// <para>检测网关返回的共通错误状态码(返回null则代表没有错误),支持状态码为</para>
|
| | | /// <para>1:网关无法解析命令数据。</para> |
| | | /// <para>2:协调器正在升级或备份/恢复数据</para> |
| | | /// <para>3:操作设备/组/场景不存在</para> |
| | | /// <para>4:其他错误</para> |
| | | /// <para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary>
|
| | | /// <param name="errorCode">错误代码</param>
|
| | | /// <returns></returns>
|
| | | public static string CheckCommonErrorCode(int errorCode)
|
| | | {
|
| | | if (errorCode == 1)
|
| | | {
|
| | | //网关无法解析命令数据
|
| | | return Language.StringByID(R.MyInternationalizationString.uGatewayCannotResolveCommand);
|
| | | }
|
| | | else if (errorCode == 2)
|
| | | {
|
| | | //协调器正在升级或备份或恢复数据中
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uCoordinatorIsUpOrBackupOrRecovering);
|
| | | }
|
| | | else if (errorCode == 3)
|
| | | {
|
| | | //目标设备不存在
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uTargetDeviceIsNotExsit);
|
| | | }
|
| | | else if (errorCode == 4)
|
| | | {
|
| | | //出现未知错误,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain);
|
| | | }
|
| | | else if (errorCode == 5)
|
| | | {
|
| | | //数据传输错误,请稍后再试
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uDataTransmissionFailAndResetAgain);
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 刷新个人中心的内存及线程___________
|
| | |
|
| | | /// <summary>
|
| | | /// 异步方法执行(仅限切换住宅时调用),刷新个人中心的内存及线程
|
| | | /// </summary>
|
| | | public async static Task<bool> InitUserCenterMenmoryAndThread()
|
| | | /// <param name="ShowPrompted">新追加变量:是否显示提示自动备份的界面</param>
|
| | | /// <returns></returns>
|
| | | public static bool InitUserCenterMenmoryAndThread(bool ShowPrompted = true)
|
| | | {
|
| | | //APP缓存加载开始
|
| | | UserCenterResourse.AppLoadMenmoryFinish = false;
|
| | | //调用这个方法,都需要重新刷新主页
|
| | | UserView.UserPage.Instance.RefreshForm = true;
|
| | |
|
| | | //强制指定不关闭进度条
|
| | | ProgressBar.SetCloseBarFlag(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.oldHomeStringId
|
| | | || Common.Config.Instance.Account != UserCenterResourse.oldAccountId)
|
| | | if (Common.Config.Instance.HomeId != UserCenterResourse.AccountOption.OldHomeStringId
|
| | | || Common.Config.Instance.Account != UserCenterResourse.AccountOption.OldAccountId)
|
| | | {
|
| | | //变更根目录路径
|
| | | UserCenterResourse.LocalRootPath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, Config.Instance.Home.Id);
|
| | | UserCenterResourse.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
|
| | | //断开远程Mqtt连接
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | //清空所有成员缓存
|
| | | ClearAllMemberMemory();
|
| | |
|
| | | //加载账号配置信息
|
| | | var optionInfo = UserCenterResourse.AccountOption.Load();
|
| | | UserCenterResourse.AccountOption = optionInfo;
|
| | | //变更根用户图片目录路径
|
| | | UserCenterResourse.AccountOption.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
|
| | |
|
| | | //加载住宅配置信息
|
| | | UserCenterResourse.ResidenceOption = UserCenterResourse.ResidenceOption.Load();
|
| | |
|
| | | //初始化登陆账号的信息
|
| | | await InitUserAccoutInfo();
|
| | | //初始化管理员权限信息
|
| | | await InitAdminConnectMqttInfo(true);
|
| | |
|
| | | //初始化缓存成员的信息
|
| | | InitLocalMemberListInfo();
|
| | |
|
| | | //重新发送命令去绑定断网情况下备份的网关
|
| | | HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | | var hadNet = InitUserAccoutInfo(true);
|
| | | //如果有网络的话
|
| | | if (hadNet == 1)
|
| | | {
|
| | | //重新发送命令去绑定断网情况下备份的网关
|
| | | HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | | //读取隐匿配置
|
| | | HdlBackupLogic.Current.LoadHideOption();
|
| | | }
|
| | |
|
| | | //预创建个人中心全部的文件夹
|
| | | CreatAllUserCenterDirectory();
|
| | |
|
| | | //关闭所有接收
|
| | | HdlDeviceAttributeLogic.Current.RemoveAllEvent();
|
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent();
|
| | | //刷新安防上报信息
|
| | | HdlAlarmsLogic.Current.RefreshAlarmInfo();
|
| | | //添加保存安防设备报警的事件(不需要再执行任何操作,并且永久存在)
|
| | | HdlAlarmsLogic.Current.AddAlarmInfoEvent();
|
| | |
|
| | | //保存用户的登陆信息到本地
|
| | | SaveUserInformationToLocation();
|
| | |
|
| | | UserCenterResourse.oldHomeStringId = Common.Config.Instance.HomeId;
|
| | | UserCenterResourse.oldAccountId = Common.Config.Instance.Account;
|
| | | UserCenterResourse.AccountOption.OldHomeStringId = Common.Config.Instance.HomeId;
|
| | | UserCenterResourse.AccountOption.OldAccountId = Common.Config.Instance.Account;
|
| | |
|
| | | //同步数据(二次调用没关系)
|
| | | var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
|
| | | int result = -1;
|
| | | if (hadNet == 1)
|
| | | {
|
| | | result = HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
|
| | | }
|
| | |
|
| | | //初始化本地的网关信息
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //初始化本地的设备信息
|
| | | Common.LocalDevice.Current.ReFreshByLocal();
|
| | |
|
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | LocalDevice.Current.ReFreshByLocal();
|
| | |
|
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
|
| | | Room.RefreshAllRoomByLocation();
|
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation();
|
| | |
|
| | | if (hadNet == 1)
|
| | | {
|
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | }
|
| | |
|
| | | //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用)
|
| | | HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
|
| | |
|
| | | //清空强制指定文本的附加信息
|
| | | ProgressBar.SetAppendText(string.Empty);
|
| | |
|
| | | //0:已经同步过,不需要同步,这个时候需要提示备份
|
| | | if (result == 0)
|
| | | if (result == 0 && ShowPrompted == true)
|
| | | {
|
| | | //开启自动备份提示
|
| | | //HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
|
| | | //开启自动备份
|
| | | HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
|
| | | }
|
| | | //显示引导界面
|
| | | ShowGuideForm(result);
|
| | | }
|
| | |
|
| | | //恢复可关闭进度条
|
| | | ProgressBar.SetCloseBarFlag(false);
|
| | | //APP缓存加载完成
|
| | | UserCenterResourse.AppLoadMenmoryFinish = true;
|
| | | UserCenterResourse.AccountOption.AppCanSignout = true;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化虚拟住宅的个人中心的数据(切换住宅使用)
|
| | | /// </summary>
|
| | | private static void InitUserCenterMenmoryByVirtualHome()
|
| | | {
|
| | | UserCenterResourse.AccountOption.OldHomeStringId = Common.Config.Instance.Home.Id;
|
| | | //清空所有成员缓存
|
| | | ClearAllMemberMemory();
|
| | | //预创建个人中心全部的文件夹
|
| | | CreatAllUserCenterDirectory();
|
| | | //关闭所有接收
|
| | | HdlGatewayReceiveLogic.Current.RemoveAllEvent();
|
| | | //初始化本地的网关信息
|
| | | HdlGatewayLogic.Current.ReFreshByLocal();
|
| | | //初始化本地的设备信息
|
| | | Common.LocalDevice.Current.ReFreshByLocal();
|
| | | //初始化房间(郭雪城那边不做处理,需要这里特殊执行一步)
|
| | | HdlRoomLogic.Current.RefreshAllRoomByLocation();
|
| | | //刷新左边刷新房间视图列表
|
| | | HdlRoomLogic.Current.RefreshRoomListView();
|
| | | }
|
| | |
|
| | | /// <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();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | #region ■ 初始化登陆账号的信息_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化登陆账号的信息
|
| | | /// 初始化登陆账号的信息 -1:无网 1:正常 2:其他错误
|
| | | /// </summary>
|
| | | /// <param name="reLoad">是否从新从本地加载(重新初始化登陆账号的信息,不需要重新加载)</param>
|
| | | /// <returns></returns>
|
| | | private async static Task<bool> InitUserAccoutInfo()
|
| | | private static int InitUserAccoutInfo(bool reLoad)
|
| | | {
|
| | | //获取本地记录的用户信息
|
| | | UserCenterResourse.UserInfo = GetUserInformationFromLocation();
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.UserPictruePath, "Admin.png");
|
| | | //初始化个人信息的标识
|
| | | 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 listNotShow = new List<string>() { "NotSetAgain" };
|
| | | string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetAccountInfo", false, pra, listNotShow);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | //序列化对象
|
| | | var requestJson = JsonConvert.SerializeObject(pra);
|
| | | //访问接口
|
| | | byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/GetAccountInfo", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (byteData == null)
|
| | | {
|
| | | //断网的话,该干嘛就干嘛吧,总之不能控主人的东西
|
| | | Config.Instance.isAdministrator = false;
|
| | | return false;
|
| | | 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>(result);
|
| | | var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(revertObj.ResponseData.ToString());
|
| | | userInfo.Account = Common.Config.Instance.Account;
|
| | | if (string.IsNullOrEmpty(userInfo.UserName) == true)
|
| | | {
|
| | |
| | | string dirPath = CombinePath();
|
| | | if (System.IO.Directory.Exists(dirPath) == true)
|
| | | {
|
| | | //先记录起住宅的一些信息
|
| | | var house = House.GetHouseByHouseId(Config.Instance.HomeId);
|
| | | //删除整个文件夹
|
| | | System.IO.Directory.Delete(dirPath, true);
|
| | | try
|
| | | {
|
| | | //同步数据的判断文件(以防万一删除整个文件夹失败的时候,这个文件被删的话,应该没什么大问题)
|
| | | string SynchronizeFile = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AutoDownLoadBackupCheckFile);
|
| | | //如果本地已经拥有了这个文件,则说明不是新手机,不再自动还原
|
| | | if (System.IO.File.Exists(SynchronizeFile) == true)
|
| | | {
|
| | | System.IO.File.Delete(SynchronizeFile);
|
| | | }
|
| | | //删除整个文件夹
|
| | | System.IO.Directory.Delete(dirPath, true);
|
| | | }
|
| | | catch { }
|
| | | //创建住宅文件夹
|
| | | Global.CreateHomeDirectory(Config.Instance.HomeId);
|
| | | //预创建个人中心全部的文件夹
|
| | | CreatAllUserCenterDirectory();
|
| | |
|
| | | var newHouse = new House();
|
| | | newHouse.Id = house.Id;
|
| | | newHouse.Name = house.Name;
|
| | | newHouse.IsOthreShare = house.IsOthreShare;
|
| | | newHouse.AccountType = house.AccountType;
|
| | | newHouse.MainUserDistributedMark = house.MainUserDistributedMark;
|
| | | newHouse.Save();
|
| | | }
|
| | | }
|
| | | if (string.IsNullOrEmpty(userInfo.UserName) == true)
|
| | |
| | | }
|
| | |
|
| | | UserCenterResourse.UserInfo = userInfo;
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.UserPictruePath, "Admin.png");
|
| | | UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, "Admin.png");
|
| | | if (UserCenterResourse.UserInfo.HeadImage != null)
|
| | | {
|
| | | //写入头像内容
|
| | | Shared.IO.FileUtils.WriteFileByBytes(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;
|
| | |
|
| | | //初始化管理员控制主人的连接地址(因为这个连接Token是不会改变的,所以只需要初始化一次)
|
| | | await InitAdminConnectMainInfo();
|
| | | var flage = InitAdminConnectMainInfo();
|
| | | //初始化个人信息的标识
|
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = flage == 1;
|
| | |
|
| | | return true;
|
| | | return flage;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | private static UserInformation GetUserInformationFromLocation()
|
| | | {
|
| | | string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
|
| | | if (System.IO.File.Exists(fileName) == false)
|
| | | var value = LoadFileContent(fileName);
|
| | | if (value == null)
|
| | | {
|
| | | return new UserInformation();
|
| | | }
|
| | | var varByte = Shared.IO.FileUtils.ReadFile(fileName);
|
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(System.Text.Encoding.UTF8.GetString(varByte));
|
| | | var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
|
| | | return info;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 重新初始化登陆账号的信息(旨在对应那一瞬间,网络不好,导致误判的情况)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private static bool ReInitUserAccoutInfo(List<string> listNotShowError)
|
| | | {
|
| | | //重新初始化账号信息
|
| | | var result = InitUserAccoutInfo(false);
|
| | | //连接不了外网的时候
|
| | | if (result == -1)
|
| | | {
|
| | | if (listNotShowError != null && listNotShowError.Contains("NotCheck") == true)
|
| | | {
|
| | | //有这个标识时,不提示错误
|
| | | return false;
|
| | | }
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | //当前无网络连接,请确认网络
|
| | | var alert = new ShowMsgControl(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uNowIsDonotNetworkAndCheckNetwork));
|
| | | alert.Show();
|
| | | });
|
| | | }
|
| | | if (result == 1)
|
| | | {
|
| | | //同步云端的网关id,如果本地拥有云端不存在的id,则表示应该被换绑了,直接删除
|
| | | HdlGatewayLogic.Current.SynchronizeDbGateway();
|
| | | //初始化个人信息的标识
|
| | | UserCenterResourse.UserInfo.InitUserInfoSuccess = true;
|
| | |
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// </summary>
|
| | | private static void SaveUserInformationToLocation()
|
| | | {
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(UserCenterResourse.UserInfo);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | |
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
|
| | | //写入内容
|
| | | Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
|
| | | SaveFileContent(fullName, UserCenterResourse.UserInfo);
|
| | |
|
| | | //搞一下主人的默认头像
|
| | | string defultFile = IO.FileUtils.GetImageFilePath("Center/Admin.png");
|
| | |
| | | {
|
| | | return;
|
| | | }
|
| | | string nowFile = System.IO.Path.Combine(UserCenterResourse.UserPictruePath, "Admin.png");
|
| | | if (System.IO.File.Exists(nowFile) == true)
|
| | | if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //复制过去
|
| | | System.IO.File.Copy(defultFile, nowFile);
|
| | | System.IO.File.Copy(defultFile, UserCenterResourse.UserInfo.UserIconFile);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | #region ■ 初始化管理员权限远程连接___________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化管理员权限远程连接主人的信息
|
| | | /// 初始化管理员权限远程连接主人的信息 -1:无网 1:正常 2:其他错误
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public static async Task<bool> InitAdminConnectMainInfo()
|
| | | private static int InitAdminConnectMainInfo()
|
| | | {
|
| | | //先清空
|
| | | Config.Instance.isAdministrator = false;
|
| | | Config.Instance.AdminRequestBaseUrl = string.Empty;
|
| | | Config.Instance.AdminRequestToken = string.Empty;
|
| | |
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 2)
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
|
| | | {
|
| | | //拥有管理员权限的成员才能这样搞, 这里必须是2
|
| | | return true;
|
| | | //时代变了,这里管理员和成员都能调用
|
| | | return 1;
|
| | | }
|
| | | var pra = new
|
| | | {
|
| | |
| | | SharedHid = Config.Instance.Home.Id
|
| | | };
|
| | |
|
| | | var listNotShow = new List<string>() { "NotSetAgain" };
|
| | | var result = await GetResponseDataByRequestHttps("App/GetSharedHomeApiControl", false, pra, listNotShow);
|
| | | if (string.IsNullOrEmpty(result) == true)
|
| | | //序列化对象
|
| | | var requestJson = JsonConvert.SerializeObject(pra);
|
| | | //访问接口
|
| | | byte[] byteData = CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("App/GetSharedHomeApiControl", Encoding.UTF8.GetBytes(requestJson));
|
| | | if (byteData == null)
|
| | | {
|
| | | return false;
|
| | | return -1;
|
| | | }
|
| | | //检测错误
|
| | | var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
|
| | | if (revertObj.StateCode.ToUpper() != "SUCCESS")
|
| | | {
|
| | | return 2;
|
| | | }
|
| | |
|
| | | Config.Instance.isAdministrator = true;
|
| | | //分享链接
|
| | | var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(result);
|
| | | var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(revertObj.ResponseData.ToString());
|
| | | Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
|
| | | Config.Instance.AdminRequestToken = info.RequestToken;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化管理员权限的远程连接信息
|
| | | /// </summary>
|
| | | /// <param name="stopRemote">是否中断远程</param>
|
| | | /// <returns></returns>
|
| | | public static async Task<bool> InitAdminConnectMqttInfo(bool stopRemote = false)
|
| | | {
|
| | | if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
|
| | | {
|
| | | //只有成员分身才能调用这个函数
|
| | | return true;
|
| | | }
|
| | | var praMqtt = new
|
| | | {
|
| | | CommonPage.RequestVersion,
|
| | | LoginAccessToken = Config.Instance.Token,
|
| | | Config.Instance.Home.MainUserDistributedMark,
|
| | | HomeId = Config.Instance.Home.Id
|
| | | };
|
| | |
|
| | | var listNotShow = new List<string>() { "NotSetAgain" };
|
| | | var result2 = await GetResponseDataByRequestHttps("App/GetConnectMainUserMqttInfo", false, praMqtt, listNotShow);
|
| | | if (string.IsNullOrEmpty(result2) == true)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
|
| | | //远程Mqtt
|
| | | var info2 = JsonConvert.DeserializeObject<MemberAdministratorMqttResult>(result2);
|
| | | Config.Instance.AdminConnectZigbeeMqttBrokerPwd = info2.ConnectZigbeeMqttBrokerPwd;
|
| | | Config.Instance.AdminConnectZigbeeMqttClientId = info2.ConnectZigbeeMqttClientId;
|
| | | Config.Instance.AdminMqttKey = info2.MqttKey;
|
| | | Config.Instance.AdminZigbeeMqttBrokerLoadSubDomain = info2.ZigbeeMqttBrokerLoadSubDomain;
|
| | | Config.Instance.AdminConnectZigbeeMqttBrokerName = info2.ConnectZigbeeMqttBrokerName;
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化缓存成员的信息_______________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化缓存成员的信息
|
| | | /// </summary>
|
| | | private static void InitLocalMemberListInfo()
|
| | | {
|
| | | //先清空
|
| | | UserCenterResourse.ListMemberInfo.Clear();
|
| | | string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.MemberListInfoFile);
|
| | | if (System.IO.File.Exists(fileName) == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | | var varByte = Shared.IO.FileUtils.ReadFile(fileName);
|
| | | UserCenterResourse.ListMemberInfo = JsonConvert.DeserializeObject<List<MemberInfoRes>>(System.Text.Encoding.UTF8.GetString(varByte));
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存缓存成员的信息
|
| | | /// </summary>
|
| | | public static void SaveLocalMemberListInfo()
|
| | | {
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(UserCenterResourse.ListMemberInfo);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | |
|
| | | string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.MemberListInfoFile);
|
| | | //写入内容
|
| | | Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
|
| | | return 1;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadShardDirectory);
|
| | | Global.CreateEmptyDirectory(directory);
|
| | |
|
| | | //LOG出力【文件夹】
|
| | | directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.LogDirectory);
|
| | | Global.CreateEmptyDirectory(directory);
|
| | |
|
| | | //用户图片目录路径【文件夹】
|
| | | if (!System.IO.Directory.Exists(UserCenterResourse.UserPictruePath)) |
| | | if (UserCenterResourse.AccountOption.UserPictruePath != string.Empty && !System.IO.Directory.Exists(UserCenterResourse.AccountOption.UserPictruePath)) |
| | | { |
| | | System.IO.Directory.CreateDirectory(UserCenterResourse.UserPictruePath); |
| | | System.IO.Directory.CreateDirectory(UserCenterResourse.AccountOption.UserPictruePath); |
| | | }
|
| | | }
|
| | |
|
| | |
| | | public static string GetConnectMainToken()
|
| | | {
|
| | | //启用管理员权限
|
| | | if (Config.Instance.isAdministrator == true)
|
| | | 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 = 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
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 检测账号是否已经退出_______________
|
| | | #region ■ 加密和解密_________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 检测账号是否已经退出 true:已经退出 false:没有退出
|
| | | /// 加密密码
|
| | | /// </summary>
|
| | | /// <param name="keys"></param>
|
| | | /// <param name="strPsw"></param>
|
| | | /// <returns></returns>
|
| | | public static bool IsAccountLoginOut()
|
| | | public static string EncryptPassword(string keys, string strPsw)
|
| | | {
|
| | | return Config.Instance.HomeId == string.Empty;
|
| | | try
|
| | | {
|
| | | 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();
|
| | | }
|
| | | 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
|
| | |
|
| | | #region ■ 文件保存和读取_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 文件保存(整天忘记,所以建一个函数来玩玩)
|
| | | /// </summary>
|
| | | /// <param name="fullName">全路径</param>
|
| | | /// <param name="obj">需要序列化的东西</param>
|
| | | public static void SaveFileContent(string fullName, object obj)
|
| | | {
|
| | | var data = JsonConvert.SerializeObject(obj);
|
| | | SaveTexToFile(fullName, data);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 文件保存(整天忘记,所以建一个函数来玩玩)
|
| | | /// </summary>
|
| | | /// <param name="fullName">全路径</param>
|
| | | /// <param name="obj">需要序列化的东西</param>
|
| | | public static void SaveTexToFile(string fullName, string textValue)
|
| | | {
|
| | | var byteData = Encoding.UTF8.GetBytes(textValue);
|
| | | //写入内容
|
| | | System.IO.FileStream fileStream = null;
|
| | | try
|
| | | {
|
| | | fileStream = new System.IO.FileStream(fullName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
|
| | | fileStream.Write(byteData, 0, byteData.Length);
|
| | | fileStream.Flush();
|
| | | }
|
| | | catch { }
|
| | | finally
|
| | | {
|
| | | fileStream?.Close();
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 读取文件,不限制住宅(文件不存在返回null,整天忘记,所以建一个函数来玩玩)
|
| | | /// </summary>
|
| | | /// <param name="fullName">全路径</param>
|
| | | /// <returns></returns>
|
| | | public static string LoadFileContent(string fullName)
|
| | | {
|
| | | //读取文件
|
| | | var varByte = ReadFileContent(fullName);
|
| | | if (varByte == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return Encoding.UTF8.GetString(varByte);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 读取文件,不限制住宅,文件不存在返回null
|
| | | /// </summary>
|
| | | /// <param name="fullName">全路径</param>
|
| | | /// <returns></returns>
|
| | | public static byte[] ReadFileContent(string fullName)
|
| | | {
|
| | | if (System.IO.File.Exists(fullName) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | System.IO.FileStream fileStream = null;
|
| | | try
|
| | | {
|
| | | fileStream = new System.IO.FileStream(fullName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
|
| | | byte[] array = new byte[fileStream.Length];
|
| | | fileStream.Read(array, 0, array.Length);
|
| | | return array;
|
| | | }
|
| | | catch
|
| | | {
|
| | | return null;
|
| | | }
|
| | | finally
|
| | | {
|
| | | fileStream?.Close();
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|