From 0f2e0147e8990e913d16d99bc1b94fb6bc53abd7 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期四, 03 十二月 2020 15:35:42 +0800
Subject: [PATCH] 2020-12-03-1

---
 HDL_ON/DAL/Server/IMessageCommon.cs |  329 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 329 insertions(+), 0 deletions(-)

diff --git a/HDL_ON/DAL/Server/IMessageCommon.cs b/HDL_ON/DAL/Server/IMessageCommon.cs
new file mode 100644
index 0000000..5b9e64d
--- /dev/null
+++ b/HDL_ON/DAL/Server/IMessageCommon.cs
@@ -0,0 +1,329 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Shared;
+
+namespace HDL_ON.DAL.Server
+{
+    /// <summary>
+    /// 鎺ュ彛绫荤殑杩斿洖淇℃伅
+    /// </summary>
+    public class IMessageCommon
+    {
+
+        /// <summary>
+        /// 鎺ュ彛绫荤殑杩斿洖淇℃伅
+        /// </summary>
+        private static IMessageCommon m_Current = null;
+        /// <summary>
+        /// 鎺ュ彛绫荤殑杩斿洖淇℃伅
+        /// </summary>
+        public static IMessageCommon Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new IMessageCommon();
+                    //鍒濆鍖栧叏閮ㄧ殑淇℃伅
+                    m_Current.InitAllMsg();
+                }
+                return m_Current;
+            }
+        }
+
+        /// <summary>
+        /// 鏄惁鍦ㄨ幏鍙杢oken
+        /// </summary>
+        public bool isGetingToken;
+
+        /// <summary>
+        /// 鏃犺閿欒(璁块棶浜戠鏃讹紝姝ゆ搷浣滃皢涓嶄細寮瑰嚭閿欒)
+        /// </summary>
+        public bool IgnoreError = false;
+
+        ///// <summary>
+        ///// 鍏ㄩ儴淇℃伅
+        ///// </summary>
+        //private Dictionary<string, Dictionary<string, int>> dicMsg = null;
+
+        /// <summary>
+        /// 閫氱敤閿欒鐮�
+        /// </summary>
+        private Dictionary<string, int> stateCodeDic = null;
+
+
+        /// <summary>
+        /// 鍒濆鍖栧叏閮ㄧ殑淇℃伅
+        /// </summary>
+        public void InitAllMsg()
+        {
+            //dicMsg = new Dictionary<string, Dictionary<string, int>>();
+            #region 鍏遍�氶敊璇爜
+            stateCodeDic = new Dictionary<string, int>();
+            //涓庢湇鍔″櫒閫氳澶辫触
+            stateCodeDic["NETWORK_ERROR"] = HDL_ON.StringId.FailedRequestServer;
+            //鏁版嵁寮傚父
+            stateCodeDic["DATA_EXCEPTION"] = HDL_ON.StringId.DataExceptionPleaseTryAgain;
+
+            #region 鍩虹鏈嶅姟 鏂伴敊璇爜
+            //绯荤粺缁存姢涓瓇璇风◢鍚庡啀璇晘
+            stateCodeDic["2"] = HDL_ON.StringId.SystemMaintenance;
+            //绛惧悕閿欒
+            stateCodeDic["4"] = HDL_ON.StringId.SignatureError;
+            //楠岃瘉鐮佹牎楠屽け璐�
+            stateCodeDic["14"] = HDL_ON.StringId.VerificationCodeWrong;
+            //楠岃瘉鐮佸彂閫侀绻侊紝璇风◢鍚庡啀璇曪紒
+            stateCodeDic["15"] = HDL_ON.StringId.VerificationCodeSentFrequently;
+            //浼氳瘽瓒呮椂锛岃鏇存柊token
+            stateCodeDic[StateCode.TOKEN_EXPIRED] = HDL_ON.StringId.NotLogin;
+            ////鐧诲綍澶辫触锛岃处鍙锋垨鑰呭瘑鐮侀敊璇�
+            stateCodeDic["10008"] = HDL_ON.StringId.LoginFailed_AccountOrPasswordError;
+            //璐﹀彿涓嶅瓨鍦�
+            stateCodeDic[StateCode.ACCOUNT_NOT_EXIST] = HDL_ON.StringId.AccountNotExist;
+            //璐﹀彿宸插瓨鍦�
+            stateCodeDic["10012"] = HDL_ON.StringId.AccountExist;
+            ////璋冪敤鐢ㄦ埛妯″潡鎺ュ彛澶辫触
+            //stateCodeDic["10213"] = HDL_ON.StringId;
+            #endregion
+
+            ////return;
+            //#region 2020-09-18 鏂板鎺ラ敊璇爜
+            //////鎿嶄綔澶辫触锛岃閲嶈瘯
+            ////stateCodeDic ["10001"] = HDL_ON.StringId.uOperationFailed;
+            ////璇锋眰鍙傛暟閿欒
+            //stateCodeDic["10101"] = HDL_ON.StringId.uParameterError;
+            ////鏃犳晥鐧诲綍Token
+            //stateCodeDic["10102"] = HDL_ON.StringId.uNoLogin;
+            ////鐧诲綍澶辫触锛岃处鍙锋垨鑰呭瘑鐮侀敊璇�
+            //stateCodeDic["10103"] = HDL_ON.StringId.Accountorpassworderro;
+            ////娌℃湁璁板綍
+            //stateCodeDic["10104"] = HDL_ON.StringId.NoRecord;
+            ////鎿嶄綔鏉冮檺涓嶈冻
+            //stateCodeDic["10105"] = HDL_ON.StringId.uBeRestrict;
+            ////涓嶅瓨鍦�
+            //stateCodeDic["10106"] = HDL_ON.StringId.NO_EXISTS;
+
+
+            ////-------------------鐢ㄦ埛妯″潡-------------------
+            ////璐﹀彿涓嶅瓨鍦�
+            //stateCodeDic["10201"] = HDL_ON.StringId.uAccountNoExists;
+            ////璐﹀彿宸茬粡瀛樺湪
+            //stateCodeDic["10202"] = HDL_ON.StringId.RegisterSendVerCode_Exist;
+            ////楠岃瘉鐮佸凡澶辨晥
+            //stateCodeDic["10203"] = HDL_ON.StringId.ValidatorCode_NoRecord;
+            ////楠岃瘉鐮侀敊璇�
+            //stateCodeDic["10204"] = HDL_ON.StringId.VerificationCodeError;
+
+
+            ////鐧诲綍澶辫触锛屽瘑鐮侀敊璇�
+            //stateCodeDic["10205"] = HDL_ON.StringId.PasswordIsError;
+            ////楠岃瘉鐮佹棤鏁圼鐢ㄦ埛娌℃湁閫氳繃鎵嬫満[閭]鍙疯幏鍙栭獙璇佺爜]
+            //stateCodeDic["10206"] = HDL_ON.StringId.ValidatorCode_ValidCodeAndPhoneNoEqual;
+            ////楠岃瘉鐮佸彂閫侀绻�
+            //stateCodeDic["10207"] = HDL_ON.StringId.VERIFY_CODE_SENDED;
+            ////璇ヨ处鍙峰凡缁忕粦瀹�
+            //stateCodeDic["10208"] = HDL_ON.StringId.Exist;
+            ////鐢ㄦ埛鍚嶇О宸茬粡瀛樺湪
+            //stateCodeDic["10209"] = HDL_ON.StringId.Exist;
+            ////楠岃瘉鐮佸彂閫佸け璐�
+            //stateCodeDic["10210"] = HDL_ON.StringId.RegisterSendVerCode_SendFail;
+
+            ////-------------------鏇存柊瀵嗙爜妯″潡-------------------
+            ////鍘熷瘑鐮佸拰鏂板瘑鐮佺浉鍚�
+            //stateCodeDic["10211"] = HDL_ON.StringId.UpdatePassword_NewPasswordAndOldPasswordEqual;
+            ////鏃у瘑鐮佷笉瀵�
+            //stateCodeDic["10212"] = HDL_ON.StringId.UpdatePassword_OldPwdNoYes;
+
+            ////-------------------瀛愯处鍙锋ā鍧�-------------------
+            ////瀛愯处鍙峰凡缁忓瓨鍦�
+            //stateCodeDic["10301"] = HDL_ON.StringId.BindSubAccount_Exist;
+            ////瀛愯处鍙蜂笉瀛樺湪
+            //stateCodeDic["10302"] = HDL_ON.StringId.uAccountNoExists;
+            ////涓嶈兘鎶婅嚜宸辨坊鍔犱负鎴愬憳
+            //stateCodeDic["10303"] = HDL_ON.StringId.BindSubAccount_SameAccount;
+            ////涓�鏍风殑杩滅▼璇锋眰
+            //stateCodeDic["10304"] = HDL_ON.StringId.uOperationFailed;
+            ////璐﹀彿宸茬粡瀛樺湪浜庢浣忓畢
+            //stateCodeDic["10305"] = HDL_ON.StringId.BindSubAccount_Exist;
+
+            ////-------------------浣忓畢妯″潡-------------------
+            ////褰撳墠浣忓畢涓嶅睘浜庤璐﹀彿
+            //stateCodeDic["10401"] = HDL_ON.StringId.HomeIdAndTokenNoConsistent;
+            ////浣忓畢鍚嶇О宸插瓨鍦�
+            //stateCodeDic["10402"] = HDL_ON.StringId.EditZigbeeHome_Exist;
+            ////浣忓畢ID宸插瓨鍦�
+            //stateCodeDic["10403"] = HDL_ON.StringId.HOME_ID_EXISTS;
+            ////浣忓畢涓嶅瓨鍦�
+            //stateCodeDic["10404"] = HDL_ON.StringId.uZigbeeHome_NoRecord;
+
+            ////-------------------浣忓畢鍒嗕韩妯″潡-------------------
+            ////浣忓畢鍒嗕韩涓嶅瓨鍦�
+            //stateCodeDic["10405"] = HDL_ON.StringId.NO_EXISTS;
+
+            ////-------------------缃戝叧妯″潡-------------------
+            ////鏄惁寮哄埗瑙g粦缃戝叧
+            //stateCodeDic["10501"] = HDL_ON.StringId.BindGwToHome_BindGatewaysExists;
+            ////搴旂敤鎴愬姛
+            //stateCodeDic["10502"] = HDL_ON.StringId.AmendTheSuccess;
+            ////褰撳墠浣忓畢涓嬪苟娌℃湁缁戝畾鎸囧畾鐨勭綉鍏�
+            //stateCodeDic["10503"] = HDL_ON.StringId.ReleaseGatewayToZigbeeHome_NoBind;
+            ////涓嶆敮鎸�
+            //stateCodeDic["10504"] = HDL_ON.StringId.NOT_SUPPORT;
+            ////缃戝叧MAC涓嶅瓨鍦�
+            //stateCodeDic["10505"] = HDL_ON.StringId.MACError;
+
+            ////-------------------澶囦唤妯″潡-------------------
+            ////澶囨敞鍚嶇О宸茬粡瀛樺湪,璇锋洿鎹㈠悗閲嶈瘯锛佹枃浠跺す鍚嶇О宸茬粡瀛樺湪
+            //stateCodeDic["10601"] = HDL_ON.StringId.uBackupNameExists;
+            ////澶囦唤鏂囦欢澶逛笉瀛樺湪
+            //stateCodeDic["10602"] = HDL_ON.StringId.FolderNoExist;
+            ////澶囦唤鏂囦欢涓嶅瓨鍦�
+            //stateCodeDic["10603"] = HDL_ON.StringId.FileNoExist;
+
+
+            ////-------------------璺ㄥ尯-------------------
+            ////璇ユ帴鍙d笉瀛樺湪璺ㄥ尯鎿嶄綔
+            //stateCodeDic["11001"] = HDL_ON.StringId.NOT_SUPPORT;
+            ////璺ㄥ尯璋冪敤澶辫触
+            //stateCodeDic["11002"] = HDL_ON.StringId.NOT_SUPPORT;
+            ////鏋氫妇閿欒
+            //stateCodeDic["11003"] = HDL_ON.StringId.uOperationFailed;
+
+
+            #endregion
+
+
+        }
+
+        /// <summary>
+        /// 鏍规嵁鎺ュ彛鐨勭姸鎬佺爜锛岀炕璇戣繑鍥炰俊鎭�
+        /// </summary>
+        /// <param name="requestName">鎺ュ彛</param>
+        /// <param name="revertObj">浜戠杩斿洖鐨勬暟鎹�</param>
+        /// <param name="pra">璇锋眰鍙傛暟</param>
+        /// <returns></returns>
+        public string GetMsgByRequestName(string statuCode)
+        {
+            if (IgnoreError == true)
+            {
+                //鏃犺閿欒
+                return null;
+            }
+
+            //鍏遍�氱爜 
+            if (stateCodeDic.ContainsKey(statuCode) == true)
+            {
+                return Language.StringByID(stateCodeDic[statuCode]);
+            }
+
+            //if (dicMsg.ContainsKey(requestName) == true && dicMsg[requestName].ContainsKey(statuCode) == true)
+            //{
+            //    //鍦ㄥ唽鐨凪sg
+            //    return Language.StringByID(dicMsg[requestName][statuCode]);
+            //}
+
+            return Language.StringByID(HDL_ON.StringId.FailedRequestServer) + "\n(" + statuCode + ")";
+        }
+
+
+        /// <summary>
+        /// 寮圭獥鎻愮ず缃戠粶璇锋眰閿欒淇℃伅
+        /// </summary>
+        /// <param name="requestName"></param>
+        /// <param name="statuCode"></param>
+        /// <param name="isTipStyle"></param>
+        /// <param name="tipStr">琛ュ厖鐨勯敊璇彁绀�</param>
+        public void ShowErrorInfoAlter(string statuCode, bool isTipStyle = true, int closeTime = 2, string tipStr = "")
+        {
+            try
+            {
+                //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken
+                if (statuCode == StateCode.TOKEN_EXPIRED)
+                {
+                    StartRefreshToken();
+                }
+                else
+                {
+                    string mes = GetMsgByRequestName(statuCode);
+                    if (mes == null) return;
+                    if (!string.IsNullOrEmpty(tipStr))
+                    {
+                        mes = tipStr + "\n" + mes;
+                    }
+                    if (isTipStyle)
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            var tip = new Tip()
+                            {
+                                Text = mes,
+                                CloseTime = closeTime,
+                                Direction = AMPopTipDirection.None
+                            };
+                            tip.Show(MainPage.BaseView);
+                        });
+                    }
+                    else
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            new Alert("", mes, Language.StringByID(HDL_ON.StringId.Close)).Show();
+                        });
+                    }
+                }
+            }
+            catch { }
+        }
+
+        /// <summary>
+        /// StartRefreshToken
+        /// </summary>
+        public void StartRefreshToken()
+        {
+            if (isGetingToken) return;
+
+            new System.Threading.Thread(() =>
+            {
+                isGetingToken = true;
+
+                try
+                {
+                    var success = new HttpServerRequest().RefreshToken();
+                    if (success) {
+                        Utlis.WriteLine("RefreshToken success");
+                    }
+                }
+                catch
+                {
+                }
+                finally
+                {
+                    isGetingToken = false;
+                }
+            })
+            { IsBackground = true }.Start();
+
+        }
+    }
+
+    /// <summary>
+    /// 甯哥敤鐘舵�佺爜绠$悊
+    /// </summary>
+    public class StateCode
+    {
+        /// <summary>
+        /// 璇锋眰鎴愬姛鐨勭姸鎬佺爜
+        /// </summary>
+        public const string SUCCESS = "0";
+        /// <summary>
+        /// 浼氳瘽瓒呮椂锛岃鏇存柊token
+        /// </summary>
+        public const string TOKEN_EXPIRED = "10001";
+        /// <summary>
+        /// 璐﹀彿涓嶅瓨鍦ㄧ殑閿欒鐮�
+        /// </summary>
+        public const string ACCOUNT_NOT_EXIST = "10010";
+
+
+    }
+}

--
Gitblit v1.8.0