From f23ad1b3f9f6193f35f72104d690b21dc67d5c1f Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 06 七月 2020 12:35:25 +0800
Subject: [PATCH] 去掉了访问外网的异步

---
 ZigbeeApp/Shared/Common/CommonPage.cs |   70 +++++++++++++++++------------------
 1 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/ZigbeeApp/Shared/Common/CommonPage.cs b/ZigbeeApp/Shared/Common/CommonPage.cs
index b1c65d1..9a8e327 100755
--- a/ZigbeeApp/Shared/Common/CommonPage.cs
+++ b/ZigbeeApp/Shared/Common/CommonPage.cs
@@ -4,7 +4,7 @@
 using System.Linq;
 using System.Net;
 using System.Text;
-using Shared.Phone.UserCenter.Abount;
+
 namespace Shared.Common
 {
     public class CommonPage : UIDrawerLayout
@@ -28,20 +28,12 @@
         public static Loading Loading = new Loading();
         public void Show()
         {
-            //if (Application.IsPad)
-            //{
-            //    Application.DesignWidth = 2048;
-            //    Application.DesignHeight = 1536;
-            //    Pad.MainPage.Instance .Show();
-            // }
-            //else
-            //{
             Application.DesignWidth = 1080;
             Application.DesignHeight = 1920;
             Application.MainPage.AddChidren(this);
             AddChidren(Phone.UserView.HomePage.Instance);
             Application.MainPage.AddChidren(Loading);
-            //}
+
             Phone.UserView.HomePage.Instance.InitPage();
         }
 
@@ -50,7 +42,7 @@
         /// <summary>
         /// 鐗堟湰鍙�
         /// </summary>
-        public static string CodeIDString = "1.1.0120062401";
+        public static string CodeIDString = "1.1.0120070302";
         /// <summary>
         /// 娉ㄥ唽鏉ユ簮(0:HDL On 1:Zigbee)
         /// </summary>
@@ -87,17 +79,9 @@
         /// </summary>
         public static string PhoneZoneStr = "86";
         /// <summary>
-        /// 鎵嬫満鍖哄悕绉�
-        /// </summary>
-        public static string ZoneNameStr = "涓浗澶ч檰";
-        /// <summary>
         /// APP瀹藉害 -- 1080
         /// </summary>
         public static int AppRealWidth = 1080;
-        /// <summary>
-        /// 璇诲彇澶氬皯椤�--999
-        /// </summary>
-        public static int PageSize = 999;
 
         /// <summary>
         /// 鐢ㄤ簬涓浗澶ч檰楠岃瘉鎵嬫満鍙锋鍒欒〃杈惧紡
@@ -126,10 +110,11 @@
         /// </summary>
         /// <param name="requestUrl">璇锋眰Url</param>
         /// <param name="byteData">璇锋眰鐨勭殑鏁版嵁</param>
+        /// <param name="timeout">瓒呮椂,榛樿10绉�</param>
         /// <returns>寰楀埌鍝嶅簲鐨勬暟鎹�</returns>
-        public async System.Threading.Tasks.Task<Shared.Common.ResponseEntity.ResponsePack> RequestHttpsZigbeeAsync(string requestUrl, byte[] byteData)
+        public ResponseEntity.ResponsePack RequestHttpsZigbeeAsync(string requestUrl, byte[] byteData, int timeout = 10)
         {
-            string result = await this.RequestHttpsZigbeeResultAsync(requestUrl, byteData);
+            string result = this.RequestHttpsZigbeeResultAsync(requestUrl, byteData, timeout);
             if (result != null)
             {
                 try
@@ -151,10 +136,11 @@
         /// </summary>
         /// <param name="requestUrl">璇锋眰Url</param>
         /// <param name="byteData">璇锋眰鐨勭殑鏁版嵁</param>
+        /// <param name="timeout">瓒呮椂,榛樿10绉�</param>
         /// <returns>寰楀埌鍝嶅簲鐨勬暟鎹�</returns>
-        public async System.Threading.Tasks.Task<string> RequestHttpsZigbeeResultAsync(string requestUrl, byte[] byteData)
+        public string RequestHttpsZigbeeResultAsync(string requestUrl, byte[] byteData, int timeout = 10)
         {
-            var result = await RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData);
+            var result = RequestHttpsZigbeeBytesResultAsync(requestUrl, byteData, "POST", timeout);
             if (result != null)
             {
                 return Encoding.UTF8.GetString(result);
@@ -169,12 +155,13 @@
         /// <param name="requestUrl">璇锋眰Url</param>
         /// <param name="byteData">璇锋眰鐨勭殑鏁版嵁</param>
         /// <param name="requestMethod">POST 鎴栬�� GET 绛夌瓑</param>
+        /// <param name="timeout">瓒呮椂,榛樿10绉�</param>
         /// <returns>寰楀埌鍝嶅簲鐨勬暟鎹�</returns>
-        public async System.Threading.Tasks.Task<byte[]> RequestHttpsZigbeeBytesResultAsync(string requestUrl, byte[] byteData, string requestMethod = "POST")
+        public byte[] RequestHttpsZigbeeBytesResultAsync(string requestUrl, byte[] byteData, string requestMethod = "POST", int timeout = 10)
         {
             //璇锋眰Url鐨勫畬鎴愯矾寰�
             var fullUrl = $"{RequestHttpsHost}/{requestUrl}";
-            return await this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.Token, requestMethod);
+            return this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.Token, requestMethod, timeout);
         }
 
         /// <summary>
@@ -184,13 +171,14 @@
         /// <param name="requestUrl">璇锋眰Url</param>
         /// <param name="byteData">璇锋眰鐨勭殑鏁版嵁</param>
         /// <param name="requestMethod">POST 鎴栬�� GET 绛夌瓑</param>
+        /// <param name="timeout">瓒呮椂,榛樿10绉�</param>
         /// <returns>寰楀埌鍝嶅簲鐨勬暟鎹�</returns>
-        public async System.Threading.Tasks.Task<byte[]> RequestZigbeeHttpsByAdmin(string requestUrl, byte[] byteData, string requestMethod = "POST")
+        public byte[] RequestZigbeeHttpsByAdmin(string requestUrl, byte[] byteData, string requestMethod = "POST", int timeout = 10)
         {
             //璇锋眰Url鐨勫畬鎴愯矾寰�
             var fullUrl = $"{Config.Instance.AdminRequestBaseUrl}/{requestUrl}";
-            return await this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.AdminRequestToken, requestMethod);
-        }
+            return this.DoRequestZigbeeHttpsInterface(fullUrl, byteData, Config.Instance.AdminRequestToken, requestMethod, timeout);
+        }
 
         /// <summary>
         /// 璇锋眰鏈嶅姟鍣ㄦ柟娉�
@@ -200,8 +188,9 @@
         /// <param name="byteData">璇锋眰鐨勭殑鏁版嵁</param>
         /// <param name="token">token</param>
         /// <param name="requestMethod">POST 鎴栬�� GET 绛夌瓑</param>
+        /// <param name="timeout">瓒呮椂,榛樿10绉�</param>
         /// <returns>寰楀埌鍝嶅簲鐨勬暟鎹�</returns>
-        public async System.Threading.Tasks.Task<byte[]> DoRequestZigbeeHttpsInterface(string requestFullUrl, byte[] byteData, string token, string requestMethod = "POST")
+        public byte[] DoRequestZigbeeHttpsInterface(string requestFullUrl, byte[] byteData, string token, string requestMethod = "POST", int timeout = 10)
         {
             try
             {
@@ -211,7 +200,9 @@
 
                 //2锛� 鍒濆鍖朒ttpWebRequest瀵硅薄
                 webRequest.Method = requestMethod;
-                webRequest.Timeout = 10 * 1000;
+                webRequest.Timeout = timeout * 1000;
+                //鍙栨秷浣跨敤浠g悊璁块棶
+                webRequest.Proxy = null;
                 if (token != null)
                 {
                     //瀵瑰簲寰俊缃戝潃
@@ -253,11 +244,18 @@
                     return ms.ToArray();
                 }
             }
-            catch (Exception e)
+            catch (WebException e)
             {
-#if DEBUG
-                System.Console.WriteLine(e.Message);
-#endif
+                if (e.Status == WebExceptionStatus.ConnectFailure//鐢辨湁缃戠粶鍒囨崲鍒版棤缃戠粶鏃惰Е鍙�
+                    || e.Status == WebExceptionStatus.Timeout//瓒呮椂
+                    || e.Status == WebExceptionStatus.NameResolutionFailure)//鏈韩灏辨槸鏃犵綉缁滄椂鍚姩鏃惰Е鍙�
+                {
+                    Phone.UserCenter.HdlWifiLogic.Current.CanAccessHttp = false;
+                }
+                return null;
+            }
+            catch (Exception e)
+            {
                 return null;
             }
         }
@@ -359,7 +357,7 @@
         /// 鐧诲綍鎴愬姛鍚庝笂鎶ヨ澶噄d绛夌浉鍏充俊鎭粰鍚庣
         /// </summary>
         /// <returns>杩斿洖鐘舵�佺爜</returns>
-        public async System.Threading.Tasks.Task<string> PushRegID()
+        public string PushRegID()
         {
             try
             {
@@ -379,7 +377,7 @@
                     DeviceType = deviceType
                 };
                 var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(RegIDObj);
-                var reverObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/SignZigbeeNeedPushRegID", System.Text.Encoding.UTF8.GetBytes(requestJson));
+                var reverObj = CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/SignZigbeeNeedPushRegID", System.Text.Encoding.UTF8.GetBytes(requestJson));
                 if (reverObj == null)
                 {
                     return null;

--
Gitblit v1.8.0