From 9f326f4000847e6167d8166fa2f6a66f53cb3734 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期四, 17 十二月 2020 09:07:13 +0800
Subject: [PATCH] 新云端Ver1.3

---
 ZigbeeApp/Shared/Phone/Common/Logic/HdlMessageLogic.cs |  400 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 400 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Common/Logic/HdlMessageLogic.cs b/ZigbeeApp/Shared/Phone/Common/Logic/HdlMessageLogic.cs
new file mode 100644
index 0000000..3251626
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/Common/Logic/HdlMessageLogic.cs
@@ -0,0 +1,400 @@
+锘縰sing Shared.Phone.UserCenter;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone
+{
+    /// <summary>
+    /// 娑堟伅鐨勯�昏緫
+    /// </summary>
+    public class HdlMessageLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// 娑堟伅鐨勯�昏緫
+        /// </summary>
+        private static HdlMessageLogic m_Current = null;
+        /// <summary>
+        /// 娑堟伅鐨勯�昏緫
+        /// </summary>
+        public static HdlMessageLogic Current
+        {
+            get
+            {
+                if (m_Current == null)
+                {
+                    m_Current = new HdlMessageLogic();
+                    //鍒濆鍖栨秷鎭垪琛�
+                    m_Current.InitHttpMessageEnum();
+                }
+                return m_Current;
+            }
+        }
+
+        /// <summary>
+        /// 娑堟伅鍒楄〃 key:鐘舵�佺爜  value:缈昏瘧鍚嶇О
+        /// </summary>
+        private Dictionary<string, string> dicHttpMsg = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖栨秷鎭痏________________________
+
+        /// <summary>
+        /// 鍒濆鍖栬澶囩殑妯″潡ID鐨勬灇涓�
+        /// </summary>
+        private void InitHttpMessageEnum()
+        {
+            if (this.dicHttpMsg != null)
+            {
+                return;
+            }
+            this.dicHttpMsg = new Dictionary<string, string>();
+
+            var listText = this.GetDeviceNameFileContent();
+            foreach (var dataText in listText)
+            {
+                if (dataText == string.Empty || dataText.StartsWith(";") == true)
+                {
+                    //杩欐槸娉ㄩ噴
+                    continue;
+                }
+                string[] strArry1 = dataText.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
+                if (strArry1.Length != 2)
+                {
+                    //闈炴硶璁剧疆
+                    continue;
+                }
+                this.dicHttpMsg[strArry1[0].Trim()] = strArry1[1].Trim();
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇璁惧鍚嶅瓧鏂囦欢鐨勫唴瀹�
+        /// </summary>
+        /// <returns></returns>
+        private List<string> GetDeviceNameFileContent()
+        {
+            System.IO.StreamReader streamReader = null;
+            var listText = new List<string>();
+            try
+            {
+#if iOS
+                string textFile = Foundation.NSBundle.MainBundle.PathForResource("HttpMessage.ini", null);
+                streamReader = new System.IO.StreamReader(textFile, Encoding.UTF8);
+                string text;
+                while ((text = streamReader.ReadLine()) != null)
+                {
+                    listText.Add(text.Trim());
+                }
+                return listText;
+#endif
+#if Android
+                var stream = Application.Activity.Assets.Open("HttpMessage.ini");
+                streamReader = new System.IO.StreamReader(stream, Encoding.UTF8);
+                string text;
+                while ((text = streamReader.ReadLine()) != null)
+                {
+                    listText.Add(text.Trim());
+                }
+                stream.Close();
+                return listText;
+#endif
+            }
+            catch
+            {
+                return listText;
+            }
+            finally
+            {
+                try
+                {
+                    streamReader?.Close();
+                }
+                catch
+                {
+                }
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鑾峰彇浜戠娑堟伅鍒楄〃___________________
+
+        /// <summary>
+        /// 鑾峰彇浜戠娑堟伅鍒楄〃(娑堟伅璁板綍,鍙兘浼氳繑鍥瀗ull)
+        /// </summary>
+        /// <returns></returns>
+        public List<MessageRecordInfo> GetListMessageFromDb()
+        {
+            //濡傛灉娌℃湁鏋佸厜id鐨勮瘽
+            if (string.IsNullOrEmpty(Common.Config.Instance.PushId) == true)
+            {
+                return null;
+            }
+            var pra = new { pushId = Common.Config.Instance.PushId, homeId = Common.Config.Instance.Home.Id };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("smart-footstone/app/message/list", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺, false, 5);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return null;
+            }
+            return Newtonsoft.Json.JsonConvert.DeserializeObject<List<MessageRecordInfo>>(result.Data.ToString());
+        }
+
+        #endregion
+
+        #region 鈻� 鏍囪娑堟伅宸茶_______________________
+
+        /// <summary>
+        /// 鏍囪浜戠娑堟伅宸茶
+        /// </summary>
+        /// <param name="i_strId">娑堟伅鐨勪富閿�</param>
+        public bool SetTickIsRead(string i_strId)
+        {
+            var pra = new { msgId = i_strId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("smart-footstone/app/message/read", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 璁剧疆浜戠娑堟伅鍏ㄩ儴涓哄凡璇�
+        /// </summary>
+        public bool SetAllTickIsRead()
+        {
+            //濡傛灉娌℃湁鏋佸厜id鐨勮瘽
+            if (string.IsNullOrEmpty(Common.Config.Instance.PushId) == true)
+            {
+                return true;
+            }
+            var pra = new { pushId = Common.Config.Instance.PushId, homeId = Common.Config.Instance.Home.Id };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("smart-footstone/app/message/read_all", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 鍒犻櫎淇℃伅璁板綍_______________________
+
+        /// <summary>
+        /// 鍒犻櫎浜戠淇℃伅璁板綍
+        /// </summary>
+        /// <param name="i_strId">娑堟伅鐨勪富閿�</param>
+        public bool DeleteCloundMessage(string i_strId)
+        {
+            var pra = new { msgId = i_strId };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("smart-footstone/app/message/delete_by_id", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 鍒犻櫎浜戠鍏ㄩ儴鐨勬秷鎭�
+        /// </summary>
+        public bool DeleteAllCloundMessage()
+        {
+            //濡傛灉娌℃湁鏋佸厜id鐨勮瘽
+            if (string.IsNullOrEmpty(Common.Config.Instance.PushId) == true)
+            {
+                return true;
+            }
+            var pra = new { pushId = Common.Config.Instance.PushId, homeId = Common.Config.Instance.Home.Id };
+            var result = HdlHttpLogic.Current.RequestResponseFromZigbeeHttps("smart-footstone/app/message/clear", RestSharp.Method.POST, pra, null, null, CheckMode.A璐﹀彿鏉冮檺);
+            if (result == null || result.Code != HttpMessageEnum.A鎴愬姛)
+            {
+                return false;
+            }
+            return true;
+        }
+
+        #endregion
+
+        #region 鈻� 涓�鑸殑鏂规硶_________________________
+
+        /// <summary>
+        /// 鏄剧ず淇℃伅妗�
+        /// </summary>
+        /// <param name="msgType">淇℃伅绫诲瀷</param>
+        /// <param name="msg">淇℃伅</param>
+        /// <param name="action">鍗曞嚮纭鍚庢墽琛岀殑鍥炶皟鍑芥暟</param>
+        /// <param name="buttonText">鎸夐挳鐨勬枃鏈�</param>
+        /// <param name="i_waitTime">绛夊緟鏃堕棿,鍗曚綅涓虹,璁剧疆纭鎸夐挳鍦ㄥ闀挎椂闂村悗鎵嶈兘澶熺偣鍑�</param>
+        public void ShowMassage(ShowMsgType msgType, string msg, Action action = null, string buttonText = null, int i_waitTime = -1)
+        {
+            //绌哄璞℃椂锛屼笉鏄剧ず
+            if (string.IsNullOrEmpty(msg))
+            {
+                return;
+            }
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                var alert = new ShowMsgControl(msgType, msg, buttonText, null, i_waitTime);
+                if (action != null)
+                {
+                    alert.ConfirmClickEvent += () =>
+                    {
+                        try
+                        {
+                            //鍥炶皟鍑芥暟
+                            action?.Invoke();
+                        }
+                        catch (Exception ex)
+                        {
+                            //鍑虹幇鏈煡閿欒,鏁版嵁涓㈠け
+                            this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
+
+                            //Log鍑哄姏
+                            HdlLogLogic.Current.WriteLog(ex);
+                        }
+                        action = null;
+                    };
+                }
+                alert.Show();
+            });
+        }
+
+        /// <summary>
+        /// 鏄剧ず娌℃湁缃戠粶鐨則ip娑堟伅
+        /// </summary>
+        /// <param name="i_mode">鏄剧ず妯″紡</param>
+        public void ShowNotNetTipMsg(ShowNetCodeMode i_mode)
+        {
+            if (i_mode == ShowNetCodeMode.No)
+            {
+                //鑺傜害浠g爜閲�,杩欐牱鏁磋�屽凡,澶栭潰灏变笉鐢ㄥ垽鏂簡
+                return;
+            }
+            //缃戝叧杩炴帴澶辫触,璇风‘璁ょ綉缁�
+            this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uGatewayIsNotLinkAndCheckNetwork));
+        }
+
+        /// <summary>
+        /// 鏄剧ず璁块棶鎺ュ彛杩斿洖鐨勭姸鎬佺爜鐨勭炕璇憈ip娑堟伅
+        /// </summary>
+        /// <param name="i_mode">鏄剧ず妯″紡</param>
+        /// <param name="i_response">浜戠杩斿洖鐨勪笢瑗�</param>
+        public void ShowNetCodeTipMsg(ShowNetCodeMode i_mode, ResponsePack i_response)
+        {
+            if (i_mode == ShowNetCodeMode.No || i_response.Code == string.Empty)
+            {
+                //鑺傜害浠g爜閲�,杩欐牱鏁磋�屽凡,澶栭潰灏变笉鐢ㄥ垽鏂簡
+                return;
+            }
+            //缈昏瘧鐘舵�佺爜
+            var strMsg = this.TranslateHttpCode(i_response.Code);
+            if (strMsg != null)
+            {
+                this.ShowMassage(ShowMsgType.Tip, strMsg);
+            }
+            else
+            {
+                this.ShowMassage(ShowMsgType.Tip, i_response.Message + "(" + i_response.Code + ")");
+            }
+        }
+
+        /// <summary>
+        /// 鏍规嵁鎺ュ彛鐨勭姸鎬佺爜锛岀炕璇戣繑鍥炰俊鎭�(鍑篖og鐢ㄧ殑)
+        /// </summary>
+        /// <param name="requestName">鎺ュ彛</param>
+        /// <param name="revertObj">浜戠杩斿洖鐨勬暟鎹�</param>
+        /// <param name="bodyObj">鎵胯浇鍦╞ody閲岄潰鐨勭被瀵硅薄</param>
+        /// <param name="dicQueryTip">瀛樻斁鏂囨。涓婃爣绛句负銆恞uery銆戠殑鍙橀噺,鏃犳鏍囩,鍒欒璁剧疆涓簄ull</param>
+        /// <param name="dicPathTip">瀛樻斁鏂囨。涓婃爣绛句负銆恜ath銆戠殑鍙橀噺,鏃犳鏍囩,鍒欒璁剧疆涓簄ull</param>
+        /// <returns></returns>
+        public string GetMsgByRequestName(string requestName, ResponsePack revertObj,
+            object bodyObj, Dictionary<string, object> dicQueryTip, Dictionary<string, object> dicPathTip)
+        {
+            string errorMsg = "鎺ュ彛璁块棶澶辫触锛�" + requestName + " " + revertObj.Code + " " + revertObj.Message + "\r\n";
+
+            errorMsg += "褰撳墠婵�娲荤殑鐣岄潰锛�" + HdlFormLogic.Current.NowActionFormID + "\r\n";
+            if (bodyObj != null)
+            {
+                //搴忓垪鍖栧璞�
+                try
+                {
+                    var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(bodyObj);
+                    errorMsg += "鍙傛暟1锛歕r\n" + requestJson + "\r\n";
+                }
+                catch { errorMsg += "鍙傛暟1锛氬簭鍒楀寲寮傚父锛乗r\n"; }
+            }
+            if (dicQueryTip != null)
+            {
+                //搴忓垪鍖栧璞�
+                try
+                {
+                    var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(dicQueryTip);
+                    errorMsg += "鍙傛暟2锛歕r\n" + requestJson + "\r\n";
+                }
+                catch { errorMsg += "鍙傛暟2锛氬簭鍒楀寲寮傚父锛乗r\n"; }
+            }
+            if (dicPathTip != null)
+            {
+                //搴忓垪鍖栧璞�
+                try
+                {
+                    var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(dicPathTip);
+                    errorMsg += "鍙傛暟3锛歕r\n" + requestJson + "\r\n";
+                }
+                catch { errorMsg += "鍙傛暟3锛氬簭鍒楀寲寮傚父锛乗r\n"; }
+            }
+            HdlLogLogic.Current.WriteLog(-1, errorMsg + "\r\n");
+
+            return this.TranslateHttpCode(revertObj.Code);
+        }
+
+        /// <summary>
+        /// 缈昏瘧浜戠鐨勭姸鎬佺爜(闈炲湪鍐岀殑鐘舵�佺爜,浼氱洿鎺ヨ繑鍥炵姸鎬佺爜)
+        /// </summary>
+        /// <param name="i_code"></param>
+        /// <returns></returns>
+        public string TranslateHttpCode(string i_code)
+        {
+            if (this.dicHttpMsg.ContainsKey(i_code) == true)
+            {
+                return this.dicHttpMsg[i_code];
+            }
+            return null;
+        }
+
+        #endregion
+    }
+
+    /// <summary>
+    /// 淇℃伅鏄剧ず鐨勭被鍨�
+    /// </summary>
+    public enum ShowMsgType
+    {
+        /// <summary>
+        /// 鏅�氭彁绀虹被鍨�
+        /// </summary>
+        Normal = 1,
+        /// <summary>
+        /// 纭绫诲瀷
+        /// </summary>
+        Confirm = 2,
+        /// <summary>
+        /// 閿欒绫诲瀷
+        /// </summary>
+        Error = 3,
+        /// <summary>
+        /// Tip绫诲瀷
+        /// </summary>
+        Tip = 4,
+        /// <summary>
+        /// 鎻愰啋绫诲瀷
+        /// </summary>
+        Remind = 5
+    }
+}

--
Gitblit v1.8.0