From a7a6907b3df65db9c4b2bb1237f709db5c985b52 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期二, 03 十二月 2019 10:25:20 +0800
Subject: [PATCH] 2019.12.3
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs | 2652 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 1,329 insertions(+), 1,323 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
old mode 100644
new mode 100755
index 7ad4afc..b778f68
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/UserCenterLogic.cs
@@ -1,1326 +1,1332 @@
-锘縰sing System;
-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;
-
-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">
- /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�恡rue銆�</pra>
- /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖銆恌alse銆�</pra>
- /// </param>
- public static async Task<bool> GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
- {
- //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
- var connectMode = GetHttpConnectMode(checkAuthority);
- //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
- var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
- if (byteData == null)
- {
- if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
- {
- return false;
- }
- byteData = await 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">
- /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�怱uccess銆�</pra>
- /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖銆怑rrorEx銆�</pra>
- /// </param>
- public static async Task<string> GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
- {
- //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
- var connectMode = GetHttpConnectMode(checkAuthority);
- //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
- var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
- if (byteData == null)
- {
- if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
- {
- return "ErrorEx";
- }
- byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
- if (byteData == null)
- {
- return "Error";
- }
- }
- var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
- return revertObj.StateCode;
- }
-
- /// <summary>
- /// 璁块棶鎸囧畾鎺ュ彛锛屽苟杩斿洖鎺ュ彛鎶婂璞″凡缁忓簭鍒楀寲浜嗙殑瀛楃涓诧紝瀛樺湪閿欒淇℃伅鏃讹紝杩斿洖null
- /// </summary>
- /// <returns>杩斿洖锛氭帴鍙f妸瀵硅薄宸茬粡搴忓垪鍖栦簡鐨勫瓧绗︿覆锛屽瓨鍦ㄩ敊璇俊鎭椂锛岃繑鍥瀗ull</returns>
- /// <param name="RequestName">璁块棶鍦板潃</param>
- /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄愶紝璇ュ弬鏁颁笉鑳界渷鐣�</param>
- /// <param name="obj">涓�涓被</param>
- /// <param name="listNotShowError">
- /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炵┖瀛楃涓�</pra>
- /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖绌哄瓧绗︿覆</pra>
- /// </param>
- public static async Task<string> GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
- {
- //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
- var connectMode = GetHttpConnectMode(checkAuthority);
- //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
- var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
- if (byteData == null)
- {
- if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
- {
- return string.Empty;
- }
- byteData = await 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 string.Empty;
- }
- 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">
- /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炵┖瀛楃涓�</pra>
- /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖null</pra>
- /// </param>
- public static async Task<byte[]> GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
- {
- //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
- var connectMode = GetHttpConnectMode(checkAuthority);
- //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
- var revertObj = await GettByteResponsePack(RequestName, connectMode, obj);
-
- if (revertObj == null)
- {
- if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
- {
- return null;
- }
- //閲嶆柊鍙戦��
- revertObj = await 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 async Task<byte[]> ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
- {
- //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
- var connectMode = GetHttpConnectMode(checkAuthority);
-
- byte[] responsePack = null;
- int count = 0;
- while (true)
- {
- await Task.Delay(1000);
- //璋冪敤鎺ュ彛
- responsePack = await 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();
- });
- break;
- }
- }
- return responsePack;
- }
-
- /// <summary>
- /// 鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑鍐呭
- /// </summary>
- /// <returns>鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑鏂囨湰鍐呭</returns>
- /// <param name="RequestName">璁块棶鍦板潃</param>
- /// <param name="connectMode">鎺ュ彛鐨勮繛鎺ユā寮�</param>
- /// <param name="obj">涓�涓被</param>
- private static async Task<byte[]> GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
- {
- try
- {
- //搴忓垪鍖栧璞�
- var requestJson = JsonConvert.SerializeObject(obj);
- //璁块棶鎺ュ彛
- byte[] result = null;
- if (connectMode == HttpConnectMode.Normal)
- {
- //鏅�氳闂�
- result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
- }
- else if (connectMode == HttpConnectMode.Admin)
- {
- //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛�
- result = await 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">浠庢帴鍙f帴鏀跺埌鐨勬暟鎹�</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 (revertObj == null)
- {
- Application.RunOnMainThread(() =>
- {
- //缃戠粶涓嶇ǔ瀹�,璇风◢鍚庡啀璇�
- string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
- var control = new ShowMsgControl(ShowMsgType.Tip, msg);
- control.Show();
- });
-
- return false;
- }
- if (revertObj.StateCode.ToUpper() != "SUCCESS")
- {
- if (listNotShowError != null && listNotShowError.Contains(revertObj.StateCode) == true)
- {
- //涓嶆樉绀洪敊璇�,鐒跺悗杩斿洖true
- return true;
- }
- Application.RunOnMainThread(() =>
- {
- if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
- {
- //濡傛灉鐢ㄦ埛宸茬粡閫�鍑轰簡鐧婚檰,鍒欎笉澶勭悊
- return;
- }
- string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode, pra);
- if (msg != null)
- {
- var control = new ShowMsgControl(ShowMsgType.Tip, msg);
- control.Show();
-
- //鏃犳晥鐧诲綍Token
- if (revertObj.StateCode == "NoLogin")
- {
- UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
- }
- }
- });
-
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// 鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
- /// </summary>
- /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄�</param>
- /// <returns></returns>
- private static HttpConnectMode GetHttpConnectMode(bool checkAuthority)
- {
- if (checkAuthority == false)
- {
- return HttpConnectMode.Normal;
- }
- if (Config.Instance.isAdministrator == true)
- {
- return HttpConnectMode.Admin;
- }
- return HttpConnectMode.Normal;
- }
-
- #endregion
-
- #region 鈻� 娣诲姞鐣岄潰鐩稿叧_______________________
-
- /// <summary>
- /// 妫�娴嬭兘鍚︽坊鍔犵敾闈�
- /// </summary>
- /// <returns>true:鍙互杩藉姞 false:涓嶅彲杩藉姞</returns>
- /// <param name="form">Form</param>
- public static bool CheckCanAddForm(CommonFormBase form)
- {
- //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
- string formName = GetFormName(form);
-
- //浜岄噸杩藉姞涓嶅彲
- if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
- {
- return true;
- }
- //鏆傛椂杩欐牱寮勭湅鐪嬶紝濡傛灉閲嶅锛屽垯鍏抽棴鎺夊師鏉ョ殑鐣岄潰
- var formTemp = UserCenterResourse.DicActionForm[formName];
- formTemp.CloseForm();
- UserCenterResourse.DicActionForm.Remove(formName);
- formTemp = null;
-
- return true;
- }
-
- /// <summary>
- /// 鎶婃墦寮�鐨勭敾闈㈡坊鍔犲埌鍐呭瓨涓�
- /// </summary>
- /// <param name="form">Form.</param>
- public static void AddActionForm(CommonFormBase form)
- {
- //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
- string formName = GetFormName(form);
-
- //浜岄噸杩藉姞涓嶅彲
- if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
- {
- form.FormID = formName;
- //鍐呭瓨娣诲姞
- UserCenterResourse.DicActionForm[formName] = form;
- //娣诲姞鐢婚潰鏃讹紝瀹冭嚜韬氨鏄縺娲荤殑鐣岄潰
- UserCenterResourse.NowActionFormID = form.FormID;
-
- UserCenterResourse.listActionFormId.Add(form.FormID);
- }
- }
-
- /// <summary>
- /// 浠庡垪琛ㄤ腑绉婚櫎鐢婚潰
- /// </summary>
- /// <param name="form">Form</param>
- public static void RemoveActionForm(CommonFormBase form)
- {
- //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
- string formName = GetFormName(form);
-
- if (UserCenterResourse.DicActionForm.ContainsKey(formName) == true)
- {
- //鍒锋柊褰撳墠姝e湪鎿嶄綔鐨勭敾闈D
- if (UserCenterResourse.NowActionFormID == UserCenterResourse.DicActionForm[formName].FormID)
- {
- //鍚戝墠鎺ㄤ竴浣嶅嵆涓轰笅涓�涓縺娲荤殑鐣岄潰
- int index = UserCenterResourse.listActionFormId.IndexOf(UserCenterResourse.NowActionFormID) - 1;
- //鍒濆鍊�
- UserCenterResourse.NowActionFormID = string.Empty;
- if (index >= 0)
- {
- var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
- if (actionForm != null && actionForm is CommonFormBase)
- {
- //璁剧疆褰撳墠婵�娲荤殑鐢婚潰ID
- UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
- //杩藉姞鏉′欢涓�:鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊欐墠澶勭悊
- if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
- {
- try
- {
- var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
- if (Myform is EditorCommonForm)
- {
- //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
- int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
- if (value == 1)
- {
- //Log鍑哄姏
- HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
- }
- }
- }
- catch (Exception ex)
- {
- //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
- var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
- alert.Show();
-
- //Log鍑哄姏
- HdlLogLogic.Current.WriteLog(ex);
- }
- }
- }
- else if (actionForm != null && actionForm is UserView.UserPage)
- {
- //杩欓噷瀹冨凡缁忛��鍒颁富椤典簡,濡傛灉瀹冨寘鍚釜浜轰腑蹇冧富椤电殑璇�
- if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == true)
- {
- //璁剧疆褰撳墠婵�娲荤殑鐢婚潰ID
- UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
- //杩藉姞鏉′欢涓�:鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊欐墠澶勭悊
- if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
- {
- try
- {
- var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
- if (Myform is EditorCommonForm)
- {
- //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
- int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
- if (value == 1)
- {
- //Log鍑哄姏
- HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
- }
- }
- }
- catch (Exception ex)
- {
- //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
- var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
- alert.Show();
-
- //Log鍑哄姏
- HdlLogLogic.Current.WriteLog(ex);
- }
- }
- }
- }
- }
- }
- //绉婚櫎ID
- UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
- //绉婚櫎鐢婚潰
- var formTemp = UserCenterResourse.DicActionForm[formName];
- UserCenterResourse.DicActionForm.Remove(formName);
- formTemp = null;
- }
- }
-
- /// <summary>
- /// 鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
- /// </summary>
- /// <returns>The form name.</returns>
- /// <param name="form">Form.</param>
- public static string GetFormName(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>
- /// 鑾峰彇褰撳墠姝e湪婵�娲荤殑鐢婚潰
- /// </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()
- {
- //澶囦唤鐨勬暟鎹紝鏈夊彲鑳芥槸涓讳汉鑷繁涓婁紶鐨勶紝濡傛灉绠$悊鍛樼櫥闄嗘椂锛屼粬鑾峰彇鐨勫浠芥暟鎹湁鐐圭壒娈�
- //姣斿涓嬮潰杩欎笁涓笢瑗垮湪涓昏处鍙烽偅閲屾槸涓嶉渶瑕佺殑
- 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();
-
- //鍒锋柊鏈湴缃戝叧鏂囦欢
- HdlGatewayLogic.Current.ReFreshByLocal();
- //鍒锋柊鏈湴璁惧
- Common.LocalDevice.Current.ReFreshByLocal();
- //闇�浼樺厛浜庡埛鏂版埧闂�,鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
- HdlGatewayLogic.Current.SynchronizeDbGateway();
- //浠庢湰鍦伴噸鏂板姞杞藉叏閮ㄧ殑鎴块棿
- Common.Room.RefreshAllRoomByLocation();
- }
-
- #endregion
-
- #region 鈻� 鍒犻櫎鏈湴鏂囦欢_______________________
-
- /// <summary>
- /// 鍒犻櫎鏈湴鎵�鏈夋枃浠�
- /// </summary>
- /// <param name="all">true:鍏ㄩ儴鍒犻櫎(鐢ㄤ簬浣忓畢鍒犻櫎) false:閲嶈鐨勬枃浠朵笉鍒犻櫎</param>
- public static void DeleteAllLocationFile(bool all = true)
- {
- string dPath = Config.Instance.FullPath;
- if (System.IO.Directory.Exists(dPath) == false)
- {
- return;
- }
-
- //鐒跺悗鑾峰彇鍏ㄩ儴鐨勬枃浠�
- List<string> listFile = Global.FileListByHomeId();
- foreach (string file in listFile)
- {
- if (all == false && IsNotDeleteFile(file) == true)
- {
- //杩欐槸涓嶈兘鍒犻櫎鐨勬枃浠�
- continue;
- }
- //鍒犻櫎鏂囦欢
- Global.DeleteFilebyHomeId(file);
- }
- //濡傛灉鏄妸鏂囦欢鍏ㄩ儴鍒犻櫎鐨勮瘽锛岄偅涔堟枃浠跺す涔熶竴璧峰垹闄ゆ帀
- if (all == true)
- {
- //鍒犻櫎鏂囦欢澶�
- System.IO.Directory.Delete(dPath, true);
- }
- }
-
- /// <summary>
- /// 鍒ゆ柇鏄笉鏄笉搴旇鍒犻櫎鐨勬枃浠�
- /// </summary>
- /// <param name="fileName"></param>
- /// <returns></returns>
- public static bool IsNotDeleteFile(string fileName)
- {
- if (fileName == "Config.json")
- {
- //涓嶈兘鍒犻櫎Config鏂囦欢
- return true;
- }
- else if (fileName.StartsWith("House_") == true)
- {
- //涓嶈兘鍒犻櫎浣忓畢鏂囦欢
- return true;
- }
- return false;
- }
-
- #endregion
-
- #region 鈻� 閲嶆柊鐧诲綍___________________________
-
- /// <summary>
- /// 閲嶆柊鐧诲綍
- /// </summary>
- /// <param name="account">璐﹀彿</param>
- /// <param name="noticeDb">鏄惁閫氱煡浜戠</param>
- public static void ReLoginAgain(string account = "", bool noticeDb = true)
- {
- UserCenterResourse.Option.OldAccountId = string.Empty;
- //鍏抽棴鎵�鏈夋帴鏀�
- HdlDeviceAttributeLogic.Current.RemoveAllEvent();
- //娓呴櫎鍗囩骇鍒楄〃
- FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
- FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
-
- HdlThreadLogic.Current.RunThread(async () =>
- {
- //妫�娴婣PP鏄惁鑳藉閫�鍑�
- while (UserCenterResourse.Option.AppCanSignout == false)
- {
- await Task.Delay(500);
- }
- //璁惧畾涓�涓椂闂�
- Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
- Config.Instance.Save();
-
- //娓呯┖褰撳墠浣忓畢id
- Shared.Common.Config.Instance.HomeId = string.Empty;
- HdlGatewayLogic.Current.ClearAllRealGateway();
- try
- {
- ZigBee.Device.ZbGateway.RemoteMqttClient?.DisconnectAsync();
- }
- catch { }
-
- if (noticeDb == true)
- {
- //閫氱煡浜戠锛屽凡缁忛��鍑虹櫥闄�
- var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
- }
- HdlThreadLogic.Current.RunMain(() =>
- {
- //鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
- CloseAllOpenForm();
-
- //鏄剧ず鐧婚檰鐢婚潰
- var formLogin = new Shared.Phone.Device.Account.AccountLogin();
- Shared.Common.CommonPage.Instance.AddChidren(formLogin);
- formLogin.Show(account);
- });
- });
- }
-
- /// <summary>
- /// 鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
- /// </summary>
- public static void CloseAllOpenForm()
- {
- var listForm = new List<CommonFormBase>();
- var listId = new List<string>();
- foreach (CommonFormBase form in UserCenterResourse.DicActionForm.Values)
- {
- if (form.FormID != "UserMainForm")
- {
- listForm.Insert(0, form);
- listId.Add(form.FormID);
- }
- }
- foreach (var id in listId)
- {
- UserCenterResourse.DicActionForm.Remove(id);
- }
-
- //鍏抽棴鎵�鏈夌敾闈�
- foreach (CommonFormBase form in listForm)
- {
- form.CloseForm();
- }
- listForm.Clear();
- }
-
- #endregion
-
- #region 鈻� 瀛愭帶浠剁殑Y杞村潗鏍嘷___________________
-
- /// <summary>
- /// 鎸囧畾浣嶇疆绫诲瀷鑾峰彇Rowlayout鐨勫瓙鎺т欢鐨刌杞村潗鏍�(璇风‘淇濆瓙鎺т欢涓嶅ぇ浜庣埗瀹瑰櫒)
- /// </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)
- {
- 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;
- }
- }
-
- #endregion
-
- #region 鈻� 鎷兼帴淇℃伅___________________________
-
- /// <summary>
- /// 鎷兼帴璺緞(鍏ㄨ矾寰�)锛屼互浣忓畢ID鐨勬枃浠跺す涓鸿捣鐐癸紝褰撴病鏈夋寚瀹氬弬鏁版椂锛屽垯杩斿洖銆愪綇瀹匢D鐨勬枃浠跺す銆戠殑鍏ㄨ矾寰�
- /// </summary>
- /// <param name="listNames">瑕佹嫾鎺ョ殑璺緞</param>
- /// <returns></returns>
- public static string CombinePath(params object[] listNames)
- {
- string rootPath = Config.Instance.FullPath;
- if (listNames == null || listNames.Length == 0)
- {
- return rootPath;
- }
- foreach (var file in listNames)
- {
- if (file == null)
- {
- continue;
- }
- rootPath = System.IO.Path.Combine(rootPath, file.ToString());
- }
- return rootPath;
- }
-
- /// <summary>
- /// 鎷兼帴缃戝叧鍥炲瓒呮椂鐨勪俊鎭�
- /// </summary>
- /// <param name="errorMsg">閿欒淇℃伅</param>
- /// <param name="resultData">缃戝叧杩斿洖鐨剅esultData,閲岄潰鏈夈�恊rrorMessageBase銆戣繖涓笢瑗跨殑閭g瀵硅薄</param>
- /// <param name="strResultData">缃戝叧杩斿洖鐨剅esultData,閲岄潰鐨勩�恊rrorMessageBase銆戠殑鍊�,璁惧畾鏈夋鍊兼椂锛宺esultData鏃犳晥</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)
- {
- 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>
- public async static Task<bool> InitUserCenterMenmoryAndThread()
- {
- //APP缂撳瓨鍔犺浇寮�濮�
- UserCenterResourse.Option.AppCanSignout = false;
-
- //寮哄埗鎸囧畾涓嶅叧闂繘搴︽潯
- ProgressBar.SetCloseBarFlag(true);
-
- //鍙湁鍦ㄤ綇瀹匢D涓嶄竴鏍风殑鏃跺�欐墠鍋氳繖涓搷浣�
- if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
- || Common.Config.Instance.Account != UserCenterResourse.Option.OldAccountId)
- {
- //鍔犺浇璐﹀彿閰嶇疆淇℃伅
- var optionInfo = UserCenterResourse.Option.Load();
- UserCenterResourse.Option = optionInfo;
- //鍙樻洿鏍圭敤鎴峰浘鐗囩洰褰曡矾寰�
- UserCenterResourse.Option.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
-
- //鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅
- await InitUserAccoutInfo();
- //鍒濆鍖栫鐞嗗憳鏉冮檺淇℃伅
- await InitAdminConnectMqttInfo(true);
-
- //鍒濆鍖栫紦瀛樻垚鍛樼殑淇℃伅
- InitLocalMemberListInfo();
-
- //閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
- HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
-
- //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
- CreatAllUserCenterDirectory();
-
- //鍏抽棴鎵�鏈夋帴鏀�
- HdlDeviceAttributeLogic.Current.RemoveAllEvent();
- //鍒锋柊瀹夐槻涓婃姤淇℃伅
- HdlAlarmsLogic.Current.RefreshAlarmInfo();
- //娣诲姞淇濆瓨瀹夐槻璁惧鎶ヨ鐨勪簨浠�(涓嶉渶瑕佸啀鎵ц浠讳綍鎿嶄綔,骞朵笖姘镐箙瀛樺湪)
- HdlAlarmsLogic.Current.AddAlarmInfoEvent();
-
- //淇濆瓨鐢ㄦ埛鐨勭櫥闄嗕俊鎭埌鏈湴
- SaveUserInformationToLocation();
-
- UserCenterResourse.Option.OldHomeStringId = Common.Config.Instance.HomeId;
- UserCenterResourse.Option.OldAccountId = Common.Config.Instance.Account;
-
- //鍚屾鏁版嵁(浜屾璋冪敤娌″叧绯�)
- var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
-
- //鍒濆鍖栨湰鍦扮殑缃戝叧淇℃伅
- HdlGatewayLogic.Current.ReFreshByLocal();
- //鍒濆鍖栨湰鍦扮殑璁惧淇℃伅
- Common.LocalDevice.Current.ReFreshByLocal();
-
- //鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
- HdlGatewayLogic.Current.SynchronizeDbGateway();
-
- //鍒濆鍖栦綇瀹呭璞�
- Common.Config.Instance.Home = House.GetHouseByHouseId(Common.Config.Instance.HomeId);
-
- //鍒濆鍖栨埧闂�(閮洩鍩庨偅杈逛笉鍋氬鐞�,闇�瑕佽繖閲岀壒娈婃墽琛屼竴姝�)
- Room.RefreshAllRoomByLocation();
-
- //鍒锋柊APP鍓嶄竴娆¢�夋嫨鐨勭綉鍏矷D(鍙互鍙嶅璋冪敤,闇�瑕佸湪缃戝叧鍒濆鍖栧畬浜嗕箣鍚庢墠鑳借皟鐢�)
- HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
-
- //娓呯┖寮哄埗鎸囧畾鏂囨湰鐨勯檮鍔犱俊鎭�
- ProgressBar.SetAppendText(string.Empty);
-
- //0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�,杩欎釜鏃跺�欓渶瑕佹彁绀哄浠�
- //if (result == 0)
- //{
- // //寮�鍚嚜鍔ㄥ浠芥彁绀�
- // HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
- //}
- }
-
- //鎭㈠鍙叧闂繘搴︽潯
- ProgressBar.SetCloseBarFlag(false);
- //APP缂撳瓨鍔犺浇瀹屾垚
- UserCenterResourse.Option.AppCanSignout = true;
-
- return true;
- }
-
- #endregion
-
- #region 鈻� 鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅_______________
-
- /// <summary>
- /// 鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅
- /// </summary>
- /// <returns></returns>
- private async static Task<bool> InitUserAccoutInfo()
- {
- //鑾峰彇鏈湴璁板綍鐨勭敤鎴蜂俊鎭�
- UserCenterResourse.UserInfo = GetUserInformationFromLocation();
- UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
-
- //鑾峰彇鐧诲綍璐﹀彿鐨勪俊鎭�
- 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)
- {
- //鏂綉鐨勮瘽锛岃骞插槢灏卞共鍢涘惂,鎬讳箣涓嶈兘鎺т富浜虹殑涓滆タ
- Config.Instance.isAdministrator = false;
- return false;
- }
-
- var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(result);
- 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);
- }
-
- if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo)
- {
- //濡傛灉鐧婚檰鐨勮处鍙风殑鏉冮檺鍜屼笂涓�娆$殑涓嶄竴鏍�,鍒欏垹闄ゆ湰鍦拌繖涓綇瀹呭叏閮ㄧ殑鏂囦欢,浠庡ご鍐嶆潵
- string dirPath = CombinePath();
- if (System.IO.Directory.Exists(dirPath) == true)
- {
- //鍏堣褰曡捣浣忓畢鐨勪竴浜涗俊鎭�
- var house = House.GetHouseByHouseId(Config.Instance.HomeId);
- //鍒犻櫎鏁翠釜鏂囦欢澶�
- System.IO.Directory.Delete(dirPath, true);
- //鍒涘缓浣忓畢鏂囦欢澶�
- 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)
- {
- //娌℃湁鏄电О鐨勮瘽,鎶婅处鍙蜂涪杩囧幓
- userInfo.UserName = userInfo.Account;
- }
-
- UserCenterResourse.UserInfo = userInfo;
- UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
- if (UserCenterResourse.UserInfo.HeadImage != null)
- {
- //鍐欏叆澶村儚鍐呭
- Shared.IO.FileUtils.WriteFileByBytes(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
- }
- UserCenterResourse.UserInfo.HeadImage = null;
-
- //鍒濆鍖栫鐞嗗憳鎺у埗涓讳汉鐨勮繛鎺ュ湴鍧�(鍥犱负杩欎釜杩炴帴Token鏄笉浼氭敼鍙樼殑,鎵�浠ュ彧闇�瑕佸垵濮嬪寲涓�娆�)
- await InitAdminConnectMainInfo();
-
- return true;
- }
-
- /// <summary>
- /// 浠庢湰鍦拌幏鍙栫敤鎴风殑鐧婚檰淇℃伅
- /// </summary>
- /// <returns></returns>
- private static UserInformation GetUserInformationFromLocation()
- {
- string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
- var value = LoadFileContent(fileName);
- if (value == null)
- {
- return new UserInformation();
- }
- var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
- return info;
- }
-
- /// <summary>
- /// 淇濆瓨鐢ㄦ埛鐨勭櫥闄嗕俊鎭埌鏈湴
- /// </summary>
- private static void SaveUserInformationToLocation()
- {
- string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
- //鍐欏叆鍐呭
- SaveFileContent(fullName, 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>
- /// 鍒濆鍖栫鐞嗗憳鏉冮檺杩滅▼杩炴帴涓讳汉鐨勪俊鎭�
- /// </summary>
- /// <returns></returns>
- public static async Task<bool> InitAdminConnectMainInfo()
- {
- //鍏堟竻绌�
- Config.Instance.isAdministrator = false;
- Config.Instance.AdminRequestBaseUrl = string.Empty;
- Config.Instance.AdminRequestToken = string.Empty;
-
- if (UserCenterResourse.UserInfo.AuthorityNo != 2)
- {
- //鎷ユ湁绠$悊鍛樻潈闄愮殑鎴愬憳鎵嶈兘杩欐牱鎼�, 杩欓噷蹇呴』鏄�2
- return true;
- }
- var pra = new
- {
- CommonPage.RequestVersion,
- LoginAccessToken = Config.Instance.Token,
- MainAccountId = Config.Instance.Home.MainUserDistributedMark,
- 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)
- {
- return false;
- }
-
- Config.Instance.isAdministrator = true;
- //鍒嗕韩閾炬帴
- var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(result);
- Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
- Config.Instance.AdminRequestToken = info.RequestToken;
-
- return true;
- }
-
- /// <summary>
- /// 鍒濆鍖栫鐞嗗憳鏉冮檺鐨勮繙绋嬭繛鎺ヤ俊鎭�
- /// </summary>
- /// <param name="stopRemote">鏄惁涓柇杩滅▼</param>
- /// <returns></returns>
- public static async Task<bool> InitAdminConnectMqttInfo(bool stopRemote = false)
- {
- if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
- {
- //鍙湁鎴愬憳鍒嗚韩鎵嶈兘璋冪敤杩欎釜鍑芥暟
- return true;
- }
- var praMqtt = new
- {
- CommonPage.RequestVersion,
- LoginAccessToken = Config.Instance.Token,
- Config.Instance.Home.MainUserDistributedMark,
- HomeId = Config.Instance.Home.Id
- };
-
- var listNotShow = new List<string>() { "NotSetAgain" };
- var result2 = await GetResponseDataByRequestHttps("App/GetConnectMainUserMqttInfo", false, praMqtt, listNotShow);
- if (string.IsNullOrEmpty(result2) == true)
- {
- return false;
- }
-
- //杩滅▼Mqtt
- var info2 = JsonConvert.DeserializeObject<MemberAdministratorMqttResult>(result2);
- Config.Instance.AdminConnectZigbeeMqttBrokerPwd = info2.ConnectZigbeeMqttBrokerPwd;
- Config.Instance.AdminConnectZigbeeMqttClientId = info2.ConnectZigbeeMqttClientId;
- Config.Instance.AdminMqttKey = info2.MqttKey;
- Config.Instance.AdminZigbeeMqttBrokerLoadSubDomain = info2.ZigbeeMqttBrokerLoadSubDomain;
- Config.Instance.AdminConnectZigbeeMqttBrokerName = info2.ConnectZigbeeMqttBrokerName;
-
- return true;
- }
-
- #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);
- }
-
- #endregion
-
- #region 鈻� 棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶筥________
-
- /// <summary>
- /// 棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
- /// </summary>
- public static void CreatAllUserCenterDirectory()
- {
- //鏈湴缂撳瓨鐨勬牴鐩綍
- string LocalDirectory = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory);
- Global.CreateEmptyDirectory(LocalDirectory);
-
- //鑷姩澶囦唤銆愭枃浠跺す銆�(缂栬緫,杩藉姞)
- string directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //鑷姩澶囦唤銆愭枃浠跺す銆�(鍒犻櫎)
- directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupdeleteDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //涓嬭浇澶囦唤鐨勬椂鍊欐墍浣跨敤鐨勪复鏃躲�愭枃浠跺す銆�
- directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadBackupTempDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //淇濆瓨瀹夐槻璁板綍鐨勩�愭枃浠跺す銆�
- directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.SafeguardAlarmDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //涓婁紶缃戝叧澶囦唤鏂囦欢鍒颁簯绔殑涓存椂銆愭枃浠跺す銆�
- directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.GatewayBackupDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //涓嬭浇鍒嗕韩鏂囦欢鐨勪复鏃躲�愭枃浠跺す銆�
- directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadShardDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //LOG鍑哄姏銆愭枃浠跺す銆�
- directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.LogDirectory);
- Global.CreateEmptyDirectory(directory);
-
- //鐢ㄦ埛鍥剧墖鐩綍璺緞銆愭枃浠跺す銆�
+锘縰sing System;
+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;
+
+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">
+ /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�恡rue銆�</pra>
+ /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖銆恌alse銆�</pra>
+ /// </param>
+ public static async Task<bool> GetResultStatuByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
+ {
+ //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
+ var connectMode = GetHttpConnectMode(checkAuthority);
+ //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
+ var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
+ if (byteData == null)
+ {
+ if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
+ {
+ return false;
+ }
+ byteData = await 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">
+ /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炪�怱uccess銆�</pra>
+ /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖銆怑rrorEx銆�</pra>
+ /// </param>
+ public static async Task<string> GetResultCodeByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
+ {
+ //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
+ var connectMode = GetHttpConnectMode(checkAuthority);
+ //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
+ var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
+ if (byteData == null)
+ {
+ if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
+ {
+ return "ErrorEx";
+ }
+ byteData = await ResetByteRequestHttps(RequestName, checkAuthority, obj);
+ if (byteData == null)
+ {
+ return "Error";
+ }
+ }
+ var revertObj = JsonConvert.DeserializeObject<ResponsePack>(Encoding.UTF8.GetString(byteData));
+ return revertObj.StateCode;
+ }
+
+ /// <summary>
+ /// 璁块棶鎸囧畾鎺ュ彛锛屽苟杩斿洖鎺ュ彛鎶婂璞″凡缁忓簭鍒楀寲浜嗙殑瀛楃涓诧紝瀛樺湪閿欒淇℃伅鏃讹紝杩斿洖null
+ /// </summary>
+ /// <returns>杩斿洖锛氭帴鍙f妸瀵硅薄宸茬粡搴忓垪鍖栦簡鐨勫瓧绗︿覆锛屽瓨鍦ㄩ敊璇俊鎭椂锛岃繑鍥瀗ull</returns>
+ /// <param name="RequestName">璁块棶鍦板潃</param>
+ /// <param name="checkAuthority">鏄惁妫�娴嬫潈闄愶紝璇ュ弬鏁颁笉鑳界渷鐣�</param>
+ /// <param name="obj">涓�涓被</param>
+ /// <param name="listNotShowError">
+ /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炵┖瀛楃涓�</pra>
+ /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖绌哄瓧绗︿覆</pra>
+ /// </param>
+ public static async Task<string> GetResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
+ {
+ //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
+ var connectMode = GetHttpConnectMode(checkAuthority);
+ //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
+ var byteData = await GettByteResponsePack(RequestName, connectMode, obj);
+ if (byteData == null)
+ {
+ if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
+ {
+ return string.Empty;
+ }
+ byteData = await 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 string.Empty;
+ }
+ 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">
+ /// <pra>涓嶉渶瑕佹樉绀洪敊璇殑閿欒绫诲埆(鎺ュ彛杩斿洖鐨勯敊璇被鍒�),濡傛灉鍖呭惈锛屽垯浼氳繑鍥炵┖瀛楃涓�</pra>
+ /// <pra>濡傛灉鎸囧畾鏈塏otSetAgain,鍒欎笉浜屾鍙戦��(姣斿鏂綉),鐒跺悗杩斿洖null</pra>
+ /// </param>
+ public static async Task<byte[]> GetByteResponseDataByRequestHttps(string RequestName, bool checkAuthority, object obj, List<string> listNotShowError = null)
+ {
+ //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
+ var connectMode = GetHttpConnectMode(checkAuthority);
+ //鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑姣旂壒鏁版嵁
+ var revertObj = await GettByteResponsePack(RequestName, connectMode, obj);
+
+ if (revertObj == null)
+ {
+ if (listNotShowError != null && listNotShowError.Contains("NotSetAgain") == true)
+ {
+ return null;
+ }
+ //閲嶆柊鍙戦��
+ revertObj = await 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 async Task<byte[]> ResetByteRequestHttps(string RequestName, bool checkAuthority, object obj)
+ {
+ //鑾峰彇鎺ュ彛鐨勮繛鎺ユā寮�
+ var connectMode = GetHttpConnectMode(checkAuthority);
+
+ byte[] responsePack = null;
+ int count = 0;
+ while (true)
+ {
+ await Task.Delay(1000);
+ //璋冪敤鎺ュ彛
+ responsePack = await 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();
+ });
+ break;
+ }
+ }
+ return responsePack;
+ }
+
+ /// <summary>
+ /// 鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑鍐呭
+ /// </summary>
+ /// <returns>鑾峰彇浠庢帴鍙i偅閲屽彇鍒扮殑鏂囨湰鍐呭</returns>
+ /// <param name="RequestName">璁块棶鍦板潃</param>
+ /// <param name="connectMode">鎺ュ彛鐨勮繛鎺ユā寮�</param>
+ /// <param name="obj">涓�涓被</param>
+ private static async Task<byte[]> GettByteResponsePack(string RequestName, HttpConnectMode connectMode, object obj)
+ {
+ try
+ {
+ //搴忓垪鍖栧璞�
+ var requestJson = JsonConvert.SerializeObject(obj);
+ //璁块棶鎺ュ彛
+ byte[] result = null;
+ if (connectMode == HttpConnectMode.Normal)
+ {
+ //鏅�氳闂�
+ result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, Encoding.UTF8.GetBytes(requestJson));
+ }
+ else if (connectMode == HttpConnectMode.Admin)
+ {
+ //浠ョ鐞嗗憳鐨勮韩浠借闂紝鑷韩鏄垚鍛�
+ result = await 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">浠庢帴鍙f帴鏀跺埌鐨勬暟鎹�</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 (revertObj == null)
+ {
+ Application.RunOnMainThread(() =>
+ {
+ //缃戠粶涓嶇ǔ瀹�,璇风◢鍚庡啀璇�
+ string msg = Language.StringByID(R.MyInternationalizationString.uNetIsUnStabilityAndDoAgain);
+ var control = new ShowMsgControl(ShowMsgType.Tip, msg);
+ control.Show();
+ });
+
+ return false;
+ }
+ if (revertObj.StateCode.ToUpper() != "SUCCESS")
+ {
+ if (listNotShowError != null && listNotShowError.Contains(revertObj.StateCode) == true)
+ {
+ //涓嶆樉绀洪敊璇�,鐒跺悗杩斿洖true
+ return true;
+ }
+ Application.RunOnMainThread(() =>
+ {
+ if (HdlCheckLogic.Current.IsAccountLoginOut() == true)
+ {
+ //濡傛灉鐢ㄦ埛宸茬粡閫�鍑轰簡鐧婚檰,鍒欎笉澶勭悊
+ return;
+ }
+ string msg = IMessageCommon.Current.GetMsgByRequestName(RequestName, revertObj.StateCode, pra);
+ if (msg != null)
+ {
+ var control = new ShowMsgControl(ShowMsgType.Tip, msg);
+ control.Show();
+
+ //鏃犳晥鐧诲綍Token
+ if (revertObj.StateCode == "NoLogin")
+ {
+ UserCenterLogic.ReLoginAgain(Config.Instance.Account, false);
+ }
+ }
+ });
+
+ 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.isAdministrator == true)
+ {
+ return HttpConnectMode.Admin;
+ }
+ return HttpConnectMode.Normal;
+ }
+
+ #endregion
+
+ #region 鈻� 娣诲姞鐣岄潰鐩稿叧_______________________
+
+ /// <summary>
+ /// 妫�娴嬭兘鍚︽坊鍔犵敾闈�
+ /// </summary>
+ /// <returns>true:鍙互杩藉姞 false:涓嶅彲杩藉姞</returns>
+ /// <param name="form">Form</param>
+ public static bool CheckCanAddForm(CommonFormBase form)
+ {
+ //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
+ string formName = GetFormName(form);
+
+ //浜岄噸杩藉姞涓嶅彲
+ if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
+ {
+ return true;
+ }
+ //鏆傛椂杩欐牱寮勭湅鐪嬶紝濡傛灉閲嶅锛屽垯鍏抽棴鎺夊師鏉ョ殑鐣岄潰
+ var formTemp = UserCenterResourse.DicActionForm[formName];
+ formTemp.CloseForm();
+ UserCenterResourse.DicActionForm.Remove(formName);
+ formTemp = null;
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鎶婃墦寮�鐨勭敾闈㈡坊鍔犲埌鍐呭瓨涓�
+ /// </summary>
+ /// <param name="form">Form.</param>
+ public static void AddActionForm(CommonFormBase form)
+ {
+ //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
+ string formName = GetFormName(form);
+
+ //浜岄噸杩藉姞涓嶅彲
+ if (UserCenterResourse.DicActionForm.ContainsKey(formName) == false)
+ {
+ form.FormID = formName;
+ //鍐呭瓨娣诲姞
+ UserCenterResourse.DicActionForm[formName] = form;
+ //娣诲姞鐢婚潰鏃讹紝瀹冭嚜韬氨鏄縺娲荤殑鐣岄潰
+ UserCenterResourse.NowActionFormID = form.FormID;
+
+ UserCenterResourse.listActionFormId.Add(form.FormID);
+ }
+ }
+
+ /// <summary>
+ /// 浠庡垪琛ㄤ腑绉婚櫎鐢婚潰
+ /// </summary>
+ /// <param name="form">Form</param>
+ public static void RemoveActionForm(CommonFormBase form)
+ {
+ //鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
+ string formName = GetFormName(form);
+
+ if (UserCenterResourse.DicActionForm.ContainsKey(formName) == true)
+ {
+ //鍒锋柊褰撳墠姝e湪鎿嶄綔鐨勭敾闈D
+ if (UserCenterResourse.NowActionFormID == UserCenterResourse.DicActionForm[formName].FormID)
+ {
+ //鍚戝墠鎺ㄤ竴浣嶅嵆涓轰笅涓�涓縺娲荤殑鐣岄潰
+ int index = UserCenterResourse.listActionFormId.IndexOf(UserCenterResourse.NowActionFormID) - 1;
+ //鍒濆鍊�
+ UserCenterResourse.NowActionFormID = string.Empty;
+ if (index >= 0)
+ {
+ var actionForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
+ if (actionForm != null && actionForm is CommonFormBase)
+ {
+ //璁剧疆褰撳墠婵�娲荤殑鐢婚潰ID
+ UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
+ //杩藉姞鏉′欢涓�:鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊欐墠澶勭悊
+ if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
+ {
+ try
+ {
+ var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
+ if (Myform is EditorCommonForm)
+ {
+ //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
+ int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
+ if (value == 1)
+ {
+ //Log鍑哄姏
+ HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
+ var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
+ alert.Show();
+
+ //Log鍑哄姏
+ HdlLogLogic.Current.WriteLog(ex);
+ }
+ }
+ }
+ else if (actionForm != null && actionForm is UserView.UserPage)
+ {
+ //杩欓噷瀹冨凡缁忛��鍒颁富椤典簡,濡傛灉瀹冨寘鍚釜浜轰腑蹇冧富椤电殑璇�
+ if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == true)
+ {
+ //璁剧疆褰撳墠婵�娲荤殑鐢婚潰ID
+ UserCenterResourse.NowActionFormID = UserCenterResourse.listActionFormId[index];
+ //杩藉姞鏉′欢涓�:鍏抽棴鐨勭晫闈负EditorCommonForm鐨勬椂鍊欐墠澶勭悊
+ if ((form is EditorCommonForm) && UserCenterResourse.DicActionForm.ContainsKey(UserCenterResourse.NowActionFormID) == true)
+ {
+ try
+ {
+ var Myform = UserCenterResourse.DicActionForm[UserCenterResourse.NowActionFormID];
+ if (Myform is EditorCommonForm)
+ {
+ //瑙﹀彂鐣岄潰鍐嶆婵�娲荤殑浜嬩欢
+ int value = ((EditorCommonForm)Myform).FormActionAgainEvent();
+ if (value == 1)
+ {
+ //Log鍑哄姏
+ HdlLogLogic.Current.WriteLog(1, Myform.FormID + " 琚縺娲�");
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
+ var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnknownErrorAndDataLost));
+ alert.Show();
+
+ //Log鍑哄姏
+ HdlLogLogic.Current.WriteLog(ex);
+ }
+ }
+ }
+ }
+ }
+ }
+ //绉婚櫎ID
+ UserCenterResourse.listActionFormId.Remove(UserCenterResourse.DicActionForm[formName].FormID);
+ //绉婚櫎鐢婚潰
+ var formTemp = UserCenterResourse.DicActionForm[formName];
+ UserCenterResourse.DicActionForm.Remove(formName);
+ formTemp = null;
+ }
+ }
+
+ /// <summary>
+ /// 鑾峰彇鐢婚潰鑻辨枃鍚嶅瓧
+ /// </summary>
+ /// <returns>The form name.</returns>
+ /// <param name="form">Form.</param>
+ public static string GetFormName(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>
+ /// 鑾峰彇褰撳墠姝e湪婵�娲荤殑鐢婚潰
+ /// </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()
+ {
+ //澶囦唤鐨勬暟鎹紝鏈夊彲鑳芥槸涓讳汉鑷繁涓婁紶鐨勶紝濡傛灉绠$悊鍛樼櫥闄嗘椂锛屼粬鑾峰彇鐨勫浠芥暟鎹湁鐐圭壒娈�
+ //姣斿涓嬮潰杩欎笁涓笢瑗垮湪涓昏处鍙烽偅閲屾槸涓嶉渶瑕佺殑
+ 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();
+
+ //鍒锋柊鏈湴缃戝叧鏂囦欢
+ HdlGatewayLogic.Current.ReFreshByLocal();
+ //鍒锋柊鏈湴璁惧
+ Common.LocalDevice.Current.ReFreshByLocal();
+ //闇�浼樺厛浜庡埛鏂版埧闂�,鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
+ HdlGatewayLogic.Current.SynchronizeDbGateway();
+ //浠庢湰鍦伴噸鏂板姞杞藉叏閮ㄧ殑鎴块棿
+ Common.Room.RefreshAllRoomByLocation();
+ }
+
+ #endregion
+
+ #region 鈻� 鍒犻櫎鏈湴鏂囦欢_______________________
+
+ /// <summary>
+ /// 鍒犻櫎鏈湴鎵�鏈夋枃浠�
+ /// </summary>
+ /// <param name="all">true:鍏ㄩ儴鍒犻櫎(鐢ㄤ簬浣忓畢鍒犻櫎) false:閲嶈鐨勬枃浠朵笉鍒犻櫎</param>
+ public static void DeleteAllLocationFile(bool all = true)
+ {
+ string dPath = Config.Instance.FullPath;
+ if (System.IO.Directory.Exists(dPath) == false)
+ {
+ return;
+ }
+
+ //鐒跺悗鑾峰彇鍏ㄩ儴鐨勬枃浠�
+ List<string> listFile = Global.FileListByHomeId();
+ foreach (string file in listFile)
+ {
+ if (all == false && IsNotDeleteFile(file) == true)
+ {
+ //杩欐槸涓嶈兘鍒犻櫎鐨勬枃浠�
+ continue;
+ }
+ //鍒犻櫎鏂囦欢
+ Global.DeleteFilebyHomeId(file);
+ }
+ //濡傛灉鏄妸鏂囦欢鍏ㄩ儴鍒犻櫎鐨勮瘽锛岄偅涔堟枃浠跺す涔熶竴璧峰垹闄ゆ帀
+ if (all == true)
+ {
+ //鍒犻櫎鏂囦欢澶�
+ System.IO.Directory.Delete(dPath, true);
+ }
+ }
+
+ /// <summary>
+ /// 鍒ゆ柇鏄笉鏄笉搴旇鍒犻櫎鐨勬枃浠�
+ /// </summary>
+ /// <param name="fileName"></param>
+ /// <returns></returns>
+ public static bool IsNotDeleteFile(string fileName)
+ {
+ if (fileName == "Config.json")
+ {
+ //涓嶈兘鍒犻櫎Config鏂囦欢
+ return true;
+ }
+ else if (fileName.StartsWith("House_") == true)
+ {
+ //涓嶈兘鍒犻櫎浣忓畢鏂囦欢
+ return true;
+ }
+ return false;
+ }
+
+ #endregion
+
+ #region 鈻� 閲嶆柊鐧诲綍___________________________
+
+ /// <summary>
+ /// 閲嶆柊鐧诲綍
+ /// </summary>
+ /// <param name="account">璐﹀彿</param>
+ /// <param name="noticeDb">鏄惁閫氱煡浜戠</param>
+ public static void ReLoginAgain(string account = "", bool noticeDb = true)
+ {
+ UserCenterResourse.Option.OldAccountId = string.Empty;
+ //鍏抽棴鎵�鏈夋帴鏀�
+ HdlDeviceAttributeLogic.Current.RemoveAllEvent();
+ //娓呴櫎鍗囩骇鍒楄〃
+ FirmwareUpdateResourse.dicDeviceUpdateList.Clear();
+ FirmwareUpdateResourse.dicGatewayUpdateList.Clear();
+
+ HdlThreadLogic.Current.RunThread(async () =>
+ {
+ //妫�娴婣PP鏄惁鑳藉閫�鍑�
+ while (UserCenterResourse.Option.AppCanSignout == false)
+ {
+ await Task.Delay(500);
+ }
+ //璁惧畾涓�涓椂闂�
+ Config.Instance.LoginDateTime = new DateTime(1970, 1, 1);
+ Config.Instance.Save();
+
+ //娓呯┖褰撳墠浣忓畢id
+ Shared.Common.Config.Instance.HomeId = string.Empty;
+ HdlGatewayLogic.Current.ClearAllRealGateway();
+ try
+ {
+ ZigBee.Device.ZbGateway.RemoteMqttClient?.DisconnectAsync();
+ }
+ catch { }
+
+ if (noticeDb == true)
+ {
+ //閫氱煡浜戠锛屽凡缁忛��鍑虹櫥闄�
+ var result = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("ZigbeeUsers/SignOut", null, "GET");
+ }
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
+ CloseAllOpenForm();
+
+ //鏄剧ず鐧婚檰鐢婚潰
+ var formLogin = new Shared.Phone.Device.Account.AccountLogin();
+ Shared.Common.CommonPage.Instance.AddChidren(formLogin);
+ formLogin.Show(account);
+ });
+ });
+ }
+
+ /// <summary>
+ /// 鍏抽棴鎵�鏈夋墦寮�浜嗙殑鐣岄潰
+ /// </summary>
+ public static void CloseAllOpenForm()
+ {
+ var listForm = new List<CommonFormBase>();
+ var listId = new List<string>();
+ foreach (CommonFormBase form in UserCenterResourse.DicActionForm.Values)
+ {
+ if (form.FormID != "UserMainForm")
+ {
+ listForm.Insert(0, form);
+ listId.Add(form.FormID);
+ }
+ }
+ foreach (var id in listId)
+ {
+ UserCenterResourse.DicActionForm.Remove(id);
+ }
+
+ //鍏抽棴鎵�鏈夌敾闈�
+ foreach (CommonFormBase form in listForm)
+ {
+ form.CloseForm();
+ }
+ listForm.Clear();
+ }
+
+ #endregion
+
+ #region 鈻� 瀛愭帶浠剁殑Y杞村潗鏍嘷___________________
+
+ /// <summary>
+ /// 鎸囧畾浣嶇疆绫诲瀷鑾峰彇Rowlayout鐨勫瓙鎺т欢鐨刌杞村潗鏍�(璇风‘淇濆瓙鎺т欢涓嶅ぇ浜庣埗瀹瑰櫒)
+ /// </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)
+ {
+ 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;
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鎷兼帴淇℃伅___________________________
+
+ /// <summary>
+ /// 鎷兼帴璺緞(鍏ㄨ矾寰�)锛屼互浣忓畢ID鐨勬枃浠跺す涓鸿捣鐐癸紝褰撴病鏈夋寚瀹氬弬鏁版椂锛屽垯杩斿洖銆愪綇瀹匢D鐨勬枃浠跺す銆戠殑鍏ㄨ矾寰�
+ /// </summary>
+ /// <param name="listNames">瑕佹嫾鎺ョ殑璺緞</param>
+ /// <returns></returns>
+ public static string CombinePath(params object[] listNames)
+ {
+ string rootPath = Config.Instance.FullPath;
+ if (listNames == null || listNames.Length == 0)
+ {
+ return rootPath;
+ }
+ foreach (var file in listNames)
+ {
+ if (file == null)
+ {
+ continue;
+ }
+ rootPath = System.IO.Path.Combine(rootPath, file.ToString());
+ }
+ return rootPath;
+ }
+
+ /// <summary>
+ /// 鎷兼帴缃戝叧鍥炲瓒呮椂鐨勪俊鎭�
+ /// </summary>
+ /// <param name="errorMsg">閿欒淇℃伅</param>
+ /// <param name="resultData">缃戝叧杩斿洖鐨剅esultData,閲岄潰鏈夈�恊rrorMessageBase銆戣繖涓笢瑗跨殑閭g瀵硅薄</param>
+ /// <param name="strResultData">缃戝叧杩斿洖鐨剅esultData,閲岄潰鐨勩�恊rrorMessageBase銆戠殑鍊�,璁惧畾鏈夋鍊兼椂锛宺esultData鏃犳晥</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)
+ {
+ 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>
+ public async static Task<bool> InitUserCenterMenmoryAndThread()
+ {
+ //APP缂撳瓨鍔犺浇寮�濮�
+ UserCenterResourse.Option.AppCanSignout = false;
+
+ //寮哄埗鎸囧畾涓嶅叧闂繘搴︽潯
+ ProgressBar.SetCloseBarFlag(true);
+
+ //鍙湁鍦ㄤ綇瀹匢D涓嶄竴鏍风殑鏃跺�欐墠鍋氳繖涓搷浣�
+ if (Common.Config.Instance.HomeId != UserCenterResourse.Option.OldHomeStringId
+ || Common.Config.Instance.Account != UserCenterResourse.Option.OldAccountId)
+ {
+ //鍔犺浇璐﹀彿閰嶇疆淇℃伅
+ var optionInfo = UserCenterResourse.Option.Load();
+ UserCenterResourse.Option = optionInfo;
+ //鍙樻洿鏍圭敤鎴峰浘鐗囩洰褰曡矾寰�
+ UserCenterResourse.Option.UserPictruePath = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, DirNameResourse.UserPictrueDirectory);
+
+ //鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅
+ await InitUserAccoutInfo();
+ //鍒濆鍖栫鐞嗗憳鏉冮檺淇℃伅
+ await InitAdminConnectMqttInfo(true);
+
+ //鍒濆鍖栫紦瀛樻垚鍛樼殑淇℃伅
+ InitLocalMemberListInfo();
+
+ //閲嶆柊鍙戦�佸懡浠ゅ幓缁戝畾鏂綉鎯呭喌涓嬪浠界殑缃戝叧
+ HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
+
+ //棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
+ CreatAllUserCenterDirectory();
+
+ //鍏抽棴鎵�鏈夋帴鏀�
+ HdlDeviceAttributeLogic.Current.RemoveAllEvent();
+ //鍒锋柊瀹夐槻涓婃姤淇℃伅
+ HdlAlarmsLogic.Current.RefreshAlarmInfo();
+ //娣诲姞淇濆瓨瀹夐槻璁惧鎶ヨ鐨勪簨浠�(涓嶉渶瑕佸啀鎵ц浠讳綍鎿嶄綔,骞朵笖姘镐箙瀛樺湪)
+ HdlAlarmsLogic.Current.AddAlarmInfoEvent();
+
+ //淇濆瓨鐢ㄦ埛鐨勭櫥闄嗕俊鎭埌鏈湴
+ SaveUserInformationToLocation();
+
+ UserCenterResourse.Option.OldHomeStringId = Common.Config.Instance.HomeId;
+ UserCenterResourse.Option.OldAccountId = Common.Config.Instance.Account;
+
+ //鍚屾鏁版嵁(浜屾璋冪敤娌″叧绯�)
+ var result = await HdlAutoBackupLogic.SynchronizeDbAutoBackupData();
+
+ //鍒濆鍖栨湰鍦扮殑缃戝叧淇℃伅
+ HdlGatewayLogic.Current.ReFreshByLocal();
+ //鍒濆鍖栨湰鍦扮殑璁惧淇℃伅
+ Common.LocalDevice.Current.ReFreshByLocal();
+
+ //鍚屾浜戠鐨勭綉鍏砳d锛屽鏋滄湰鍦版嫢鏈変簯绔笉瀛樺湪鐨刬d锛屽垯琛ㄧず搴旇琚崲缁戜簡锛岀洿鎺ュ垹闄�
+ HdlGatewayLogic.Current.SynchronizeDbGateway();
+
+ //鍒濆鍖栦綇瀹呭璞�
+ Common.Config.Instance.Home = House.GetHouseByHouseId(Common.Config.Instance.HomeId);
+
+ //鍒濆鍖栨埧闂�(閮洩鍩庨偅杈逛笉鍋氬鐞�,闇�瑕佽繖閲岀壒娈婃墽琛屼竴姝�)
+ Room.RefreshAllRoomByLocation();
+
+ //鍒锋柊APP鍓嶄竴娆¢�夋嫨鐨勭綉鍏矷D(鍙互鍙嶅璋冪敤,闇�瑕佸湪缃戝叧鍒濆鍖栧畬浜嗕箣鍚庢墠鑳借皟鐢�)
+ HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
+
+ //娓呯┖寮哄埗鎸囧畾鏂囨湰鐨勯檮鍔犱俊鎭�
+ ProgressBar.SetAppendText(string.Empty);
+
+ //0:宸茬粡鍚屾杩囷紝涓嶉渶瑕佸悓姝�,杩欎釜鏃跺�欓渶瑕佹彁绀哄浠�
+ //if (result == 0)
+ //{
+ // //寮�鍚嚜鍔ㄥ浠芥彁绀�
+ // HdlAutoBackupLogic.ShowAutoBackupPromptedForm();
+ //}
+ }
+
+ //鎭㈠鍙叧闂繘搴︽潯
+ ProgressBar.SetCloseBarFlag(false);
+ //APP缂撳瓨鍔犺浇瀹屾垚
+ UserCenterResourse.Option.AppCanSignout = true;
+
+ return true;
+ }
+
+ #endregion
+
+ #region 鈻� 鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅_______________
+
+ /// <summary>
+ /// 鍒濆鍖栫櫥闄嗚处鍙风殑淇℃伅
+ /// </summary>
+ /// <returns></returns>
+ private async static Task<bool> InitUserAccoutInfo()
+ {
+ //鑾峰彇鏈湴璁板綍鐨勭敤鎴蜂俊鎭�
+ UserCenterResourse.UserInfo = GetUserInformationFromLocation();
+ UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
+
+ //鑾峰彇鐧诲綍璐﹀彿鐨勪俊鎭�
+ 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)
+ {
+ //鏂綉鐨勮瘽锛岃骞插槢灏卞共鍢涘惂,鎬讳箣涓嶈兘鎺т富浜虹殑涓滆タ
+ Config.Instance.isAdministrator = false;
+ return false;
+ }
+
+ var userInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(result);
+ 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);
+ }
+
+ if (UserCenterResourse.UserInfo.AuthorityNo != userInfo.AuthorityNo)
+ {
+ //濡傛灉鐧婚檰鐨勮处鍙风殑鏉冮檺鍜屼笂涓�娆$殑涓嶄竴鏍�,鍒欏垹闄ゆ湰鍦拌繖涓綇瀹呭叏閮ㄧ殑鏂囦欢,浠庡ご鍐嶆潵
+ string dirPath = CombinePath();
+ if (System.IO.Directory.Exists(dirPath) == true)
+ {
+ //鍏堣褰曡捣浣忓畢鐨勪竴浜涗俊鎭�
+ var house = House.GetHouseByHouseId(Config.Instance.HomeId);
+ //鍒犻櫎鏁翠釜鏂囦欢澶�
+ System.IO.Directory.Delete(dirPath, true);
+ //鍒涘缓浣忓畢鏂囦欢澶�
+ 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)
+ {
+ //娌℃湁鏄电О鐨勮瘽,鎶婅处鍙蜂涪杩囧幓
+ userInfo.UserName = userInfo.Account;
+ }
+
+ UserCenterResourse.UserInfo = userInfo;
+ UserCenterResourse.UserInfo.UserIconFile = System.IO.Path.Combine(UserCenterResourse.Option.UserPictruePath, "Admin.png");
+ if (UserCenterResourse.UserInfo.HeadImage != null)
+ {
+ //鍐欏叆澶村儚鍐呭
+ Shared.IO.FileUtils.WriteFileByBytes(UserCenterResourse.UserInfo.UserIconFile, UserCenterResourse.UserInfo.HeadImage);
+ }
+ UserCenterResourse.UserInfo.HeadImage = null;
+ //鎵嬪娍瀵嗙爜
+ UserCenterResourse.Option.GestureAuthentication = UserCenterResourse.UserInfo.GesturePwd == null ? string.Empty : UserCenterResourse.UserInfo.GesturePwd;
+ UserCenterResourse.UserInfo.GesturePwd = null;
+ //瀵嗙爜楠岃瘉
+ UserCenterResourse.Option.PswAuthentication = UserCenterResourse.UserInfo.StringPwd == null ? string.Empty : UserCenterResourse.UserInfo.StringPwd;
+ UserCenterResourse.UserInfo.StringPwd = null;
+
+ //鍒濆鍖栫鐞嗗憳鎺у埗涓讳汉鐨勮繛鎺ュ湴鍧�(鍥犱负杩欎釜杩炴帴Token鏄笉浼氭敼鍙樼殑,鎵�浠ュ彧闇�瑕佸垵濮嬪寲涓�娆�)
+ await InitAdminConnectMainInfo();
+
+ return true;
+ }
+
+ /// <summary>
+ /// 浠庢湰鍦拌幏鍙栫敤鎴风殑鐧婚檰淇℃伅
+ /// </summary>
+ /// <returns></returns>
+ private static UserInformation GetUserInformationFromLocation()
+ {
+ string fileName = CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
+ var value = LoadFileContent(fileName);
+ if (value == null)
+ {
+ return new UserInformation();
+ }
+ var info = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInformation>(value);
+ return info;
+ }
+
+ /// <summary>
+ /// 淇濆瓨鐢ㄦ埛鐨勭櫥闄嗕俊鎭埌鏈湴
+ /// </summary>
+ private static void SaveUserInformationToLocation()
+ {
+ string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.UserInfoFile);
+ //鍐欏叆鍐呭
+ SaveFileContent(fullName, 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>
+ /// 鍒濆鍖栫鐞嗗憳鏉冮檺杩滅▼杩炴帴涓讳汉鐨勪俊鎭�
+ /// </summary>
+ /// <returns></returns>
+ public static async Task<bool> InitAdminConnectMainInfo()
+ {
+ //鍏堟竻绌�
+ Config.Instance.isAdministrator = false;
+ Config.Instance.AdminRequestBaseUrl = string.Empty;
+ Config.Instance.AdminRequestToken = string.Empty;
+
+ if (UserCenterResourse.UserInfo.AuthorityNo != 2)
+ {
+ //鎷ユ湁绠$悊鍛樻潈闄愮殑鎴愬憳鎵嶈兘杩欐牱鎼�, 杩欓噷蹇呴』鏄�2
+ return true;
+ }
+ var pra = new
+ {
+ CommonPage.RequestVersion,
+ LoginAccessToken = Config.Instance.Token,
+ MainAccountId = Config.Instance.Home.MainUserDistributedMark,
+ 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)
+ {
+ return false;
+ }
+
+ Config.Instance.isAdministrator = true;
+ //鍒嗕韩閾炬帴
+ var info = JsonConvert.DeserializeObject<MemberAdministratorResult>(result);
+ Config.Instance.AdminRequestBaseUrl = info.RequestBaseUrl;
+ Config.Instance.AdminRequestToken = info.RequestToken;
+
+ return true;
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栫鐞嗗憳鏉冮檺鐨勮繙绋嬭繛鎺ヤ俊鎭�
+ /// </summary>
+ /// <param name="stopRemote">鏄惁涓柇杩滅▼</param>
+ /// <returns></returns>
+ public static async Task<bool> InitAdminConnectMqttInfo(bool stopRemote = false)
+ {
+ if (UserCenterResourse.UserInfo.AuthorityNo != 2 && UserCenterResourse.UserInfo.AuthorityNo != 3)
+ {
+ //鍙湁鎴愬憳鍒嗚韩鎵嶈兘璋冪敤杩欎釜鍑芥暟
+ return true;
+ }
+ var praMqtt = new
+ {
+ CommonPage.RequestVersion,
+ LoginAccessToken = Config.Instance.Token,
+ Config.Instance.Home.MainUserDistributedMark,
+ HomeId = Config.Instance.Home.Id
+ };
+
+ var listNotShow = new List<string>() { "NotSetAgain" };
+ var result2 = await GetResponseDataByRequestHttps("App/GetConnectMainUserMqttInfo", false, praMqtt, listNotShow);
+ if (string.IsNullOrEmpty(result2) == true)
+ {
+ return false;
+ }
+
+ //杩滅▼Mqtt
+ var info2 = JsonConvert.DeserializeObject<MemberAdministratorMqttResult>(result2);
+ Config.Instance.AdminConnectZigbeeMqttBrokerPwd = info2.ConnectZigbeeMqttBrokerPwd;
+ Config.Instance.AdminConnectZigbeeMqttClientId = info2.ConnectZigbeeMqttClientId;
+ Config.Instance.AdminMqttKey = info2.MqttKey;
+ Config.Instance.AdminZigbeeMqttBrokerLoadSubDomain = info2.ZigbeeMqttBrokerLoadSubDomain;
+ Config.Instance.AdminConnectZigbeeMqttBrokerName = info2.ConnectZigbeeMqttBrokerName;
+
+ return true;
+ }
+
+ #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);
+ }
+
+ #endregion
+
+ #region 鈻� 棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶筥________
+
+ /// <summary>
+ /// 棰勫垱寤轰釜浜轰腑蹇冨叏閮ㄧ殑鏂囦欢澶�
+ /// </summary>
+ public static void CreatAllUserCenterDirectory()
+ {
+ //鏈湴缂撳瓨鐨勬牴鐩綍
+ string LocalDirectory = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory);
+ Global.CreateEmptyDirectory(LocalDirectory);
+
+ //鑷姩澶囦唤銆愭枃浠跺す銆�(缂栬緫,杩藉姞)
+ string directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //鑷姩澶囦唤銆愭枃浠跺す銆�(鍒犻櫎)
+ directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.AutoBackupdeleteDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //涓嬭浇澶囦唤鐨勬椂鍊欐墍浣跨敤鐨勪复鏃躲�愭枃浠跺す銆�
+ directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadBackupTempDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //淇濆瓨瀹夐槻璁板綍鐨勩�愭枃浠跺す銆�
+ directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.SafeguardAlarmDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //涓婁紶缃戝叧澶囦唤鏂囦欢鍒颁簯绔殑涓存椂銆愭枃浠跺す銆�
+ directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.GatewayBackupDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //涓嬭浇鍒嗕韩鏂囦欢鐨勪复鏃躲�愭枃浠跺す銆�
+ directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.DownLoadShardDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //LOG鍑哄姏銆愭枃浠跺す銆�
+ directory = System.IO.Path.Combine(LocalDirectory, DirNameResourse.LogDirectory);
+ Global.CreateEmptyDirectory(directory);
+
+ //鐢ㄦ埛鍥剧墖鐩綍璺緞銆愭枃浠跺す銆�
if (UserCenterResourse.Option.UserPictruePath != string.Empty && !System.IO.Directory.Exists(UserCenterResourse.Option.UserPictruePath))
{
System.IO.Directory.CreateDirectory(UserCenterResourse.Option.UserPictruePath);
- }
- }
-
- #endregion
-
- #region 鈻� 鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken____________
-
- /// <summary>
- /// 鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
- /// </summary>
- /// <returns></returns>
- public static string GetConnectMainToken()
- {
- //鍚敤绠$悊鍛樻潈闄�
- if (Config.Instance.isAdministrator == true)
- {
- return Config.Instance.AdminRequestToken;
- }
- return Config.Instance.Token;
- }
-
- #endregion
-
- #region 鈻� 16杩涘埗杞寲_________________________
-
- /// <summary>
- /// 灏�16杩涘埗鐨勬枃鏈炕璇戜负姝e父鏂囨湰
- /// </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)
- {
- 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();
- }
-
- /// <summary>
- /// 瑙e瘑瀵嗙爜
- /// </summary>
- /// <param name="strPsw"></param>
- /// <returns></returns>
- public static string DecryptPassword(string keys, string strPsw)
- {
- if (strPsw == string.Empty)
- {
- return strPsw;
- }
- var des = new System.Security.Cryptography.DESCryptoServiceProvider();
-
- byte[] inputByteArray = new byte[strPsw.Length / 2];
- for (int x = 0; x < strPsw.Length / 2; x++)
- {
- int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
- inputByteArray[x] = (byte)i;
- }
-
- des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
- des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
- var ms = new System.IO.MemoryStream();
- var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
- cs.Write(inputByteArray, 0, inputByteArray.Length);
- cs.FlushFinalBlock();
-
- StringBuilder ret = new StringBuilder();
-
- return System.Text.Encoding.Default.GetString(ms.ToArray());
- }
- #endregion
-
- #region 鈻� 鏂囦欢淇濆瓨鍜岃鍙朹____________________
-
- /// <summary>
- /// 鏂囦欢淇濆瓨(鏁村ぉ蹇樿,鎵�浠ュ缓涓�涓嚱鏁版潵鐜╃帺)
- /// </summary>
- /// <param name="fullName">鍏ㄨ矾寰�</param>
- /// <param name="obj">闇�瑕佸簭鍒楀寲鐨勪笢瑗�</param>
- public static void SaveFileContent(string fullName, object obj)
- {
- var data = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
- var byteData = System.Text.Encoding.UTF8.GetBytes(data);
- //鍐欏叆鍐呭
- Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
- }
-
- /// <summary>
- /// 璇诲彇鏂囦欢(鏂囦欢涓嶅瓨鍦ㄨ繑鍥瀗ull,鏁村ぉ蹇樿,鎵�浠ュ缓涓�涓嚱鏁版潵鐜╃帺)
- /// </summary>
- /// <param name="fullName">鍏ㄨ矾寰�</param>
- /// <returns></returns>
- public static string LoadFileContent(string fullName)
- {
- if (System.IO.File.Exists(fullName) == false)
- {
- return null;
- }
- var varByte = Shared.IO.FileUtils.ReadFile(fullName);
- return System.Text.Encoding.UTF8.GetString(varByte);
- }
-
- #endregion
- }
-}
\ No newline at end of file
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken____________
+
+ /// <summary>
+ /// 鑾峰彇鎺у埗涓讳汉璐﹀彿鐨凾oken
+ /// </summary>
+ /// <returns></returns>
+ public static string GetConnectMainToken()
+ {
+ //鍚敤绠$悊鍛樻潈闄�
+ if (Config.Instance.isAdministrator == true)
+ {
+ return Config.Instance.AdminRequestToken;
+ }
+ return Config.Instance.Token;
+ }
+
+ #endregion
+
+ #region 鈻� 16杩涘埗杞寲_________________________
+
+ /// <summary>
+ /// 灏�16杩涘埗鐨勬枃鏈炕璇戜负姝e父鏂囨湰
+ /// </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)
+ {
+ 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();
+ }
+
+ /// <summary>
+ /// 瑙e瘑瀵嗙爜
+ /// </summary>
+ /// <param name="strPsw"></param>
+ /// <returns></returns>
+ public static string DecryptPassword(string keys, string strPsw)
+ {
+ if (strPsw == string.Empty)
+ {
+ return strPsw;
+ }
+ var des = new System.Security.Cryptography.DESCryptoServiceProvider();
+
+ byte[] inputByteArray = new byte[strPsw.Length / 2];
+ for (int x = 0; x < strPsw.Length / 2; x++)
+ {
+ int i = (Convert.ToInt32(strPsw.Substring(x * 2, 2), 16));
+ inputByteArray[x] = (byte)i;
+ }
+
+ des.Key = ASCIIEncoding.ASCII.GetBytes(keys);
+ des.IV = ASCIIEncoding.ASCII.GetBytes(keys);
+ var ms = new System.IO.MemoryStream();
+ var cs = new System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+
+ StringBuilder ret = new StringBuilder();
+
+ return System.Text.Encoding.Default.GetString(ms.ToArray());
+ }
+ #endregion
+
+ #region 鈻� 鏂囦欢淇濆瓨鍜岃鍙朹____________________
+
+ /// <summary>
+ /// 鏂囦欢淇濆瓨(鏁村ぉ蹇樿,鎵�浠ュ缓涓�涓嚱鏁版潵鐜╃帺)
+ /// </summary>
+ /// <param name="fullName">鍏ㄨ矾寰�</param>
+ /// <param name="obj">闇�瑕佸簭鍒楀寲鐨勪笢瑗�</param>
+ public static void SaveFileContent(string fullName, object obj)
+ {
+ var data = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
+ var byteData = System.Text.Encoding.UTF8.GetBytes(data);
+ //鍐欏叆鍐呭
+ Shared.IO.FileUtils.WriteFileByBytes(fullName, byteData);
+ }
+
+ /// <summary>
+ /// 璇诲彇鏂囦欢(鏂囦欢涓嶅瓨鍦ㄨ繑鍥瀗ull,鏁村ぉ蹇樿,鎵�浠ュ缓涓�涓嚱鏁版潵鐜╃帺)
+ /// </summary>
+ /// <param name="fullName">鍏ㄨ矾寰�</param>
+ /// <returns></returns>
+ public static string LoadFileContent(string fullName)
+ {
+ if (System.IO.File.Exists(fullName) == false)
+ {
+ return null;
+ }
+ var varByte = Shared.IO.FileUtils.ReadFile(fullName);
+ return System.Text.Encoding.UTF8.GetString(varByte);
+ }
+
+ #endregion
+ }
+}
--
Gitblit v1.8.0