From f441a3c49f8b5cedee3e4def6fbb448ef40eb9cb Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期三, 10 六月 2020 14:46:58 +0800 Subject: [PATCH] Crabtree-ON 2020-06-10 基于最新HDL ON 优化问题,Crabtree-ONAPP部分功能同步修改优化调整 1. 增加大图片大文件上传处理. 2.远程连接交互提示,由原来的Loading修改成顶部Tip提示。 3.灯光全开、全关和场景控制多线程发送,和HDLON同样加锁处理。 4.Android ,判断移动网络失败,网络监测修复方法修改,后台前台切换优化。 --- Crabtree/SmartHome/UI/SimpleControl/MainPage.cs | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 162 insertions(+), 1 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs index 1f245cc..f549af7 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs @@ -38,7 +38,7 @@ //public static Button LogoButton = new Button (); - public static string RequestVersion = "20200426"; + public static string RequestVersion = "2.506101"; public static UserInfo LoginUser; /// <summary> /// 鏄惁鏄鐞嗗憳鏉冮檺(鍙樻洿浜�,鎴愬憳鐨勬椂鍊�,杩欎釜涔熶负ture銆備负浠�涔堜細澹版槑杩欐牱鍙橀噺,鍥犱负鏈変簺鎺ュ彛蹇呴』浣跨敤鍘熸潵鐨凾oken) @@ -286,6 +286,167 @@ /// <summary> + /// 璇锋眰鏈嶅姟鍣ㄦ柟娉� + /// </summary> + /// <returns>The https.</returns> + /// <param name="methodType">璇锋眰鏂规硶.</param> + public static ResponsePack RequestHttpsNewBig (string methodType, byte [] byteData, UploadHomeAppGatewaySubFilesBigObj mUploadHomeAppGatewaySubFilesBigObj, string urlHead = "", int mTimeout = 10, string requestMethod = "POST") + { + ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => { + return true; + }; + + + #region HttpWebRequest + + try { + + if (urlHead == "") { + urlHead = RequestHttpsHost; + } + string requestFullUrl = urlHead + methodType; + + //鍒濆鍖栨柊鐨剋ebRequst + //1锛� 鍒涘缓httpWebRequest瀵硅薄 + HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create (new Uri (requestFullUrl)); + + //2锛� 鍒濆鍖朒ttpWebRequest瀵硅薄 + webRequest.Method = requestMethod; + + //webRequest.Timeout = mTimeout * 1000; + + webRequest.Headers.Add (HttpRequestHeader.Authorization, LoginUser.LoginTokenString); + webRequest.Headers.Add ("RequestVersion", mUploadHomeAppGatewaySubFilesBigObj.RequestVersion); + webRequest.Headers.Add ("LoginAccessToken", LoginUser.LoginTokenString); + webRequest.Headers.Add ("HomeId", mUploadHomeAppGatewaySubFilesBigObj.HomeId); + webRequest.Headers.Add ("BackupClassId", mUploadHomeAppGatewaySubFilesBigObj.BackupClassId); + webRequest.Headers.Add ("FileName", mUploadHomeAppGatewaySubFilesBigObj.FileName); + webRequest.Headers.Add ("IsOtherAccountCtrl", mUploadHomeAppGatewaySubFilesBigObj.IsOtherAccountCtrl.ToString ()); + + + //var byteData = new byte [] { }锛�//Encoding.UTF8.GetBytes (dataStringJson); + + //if (LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */ + // //瀵瑰簲寰俊缃戝潃 + + //} + + if (requestMethod == "GET") { + //webRequest.ContentType = "text/html"; + webRequest.ContentType = "application/json"; + } else { + webRequest.ContentType = "application/octet-stream"; + //webRequest.ContentType = "application/json"; + webRequest.ContentLength = byteData.Length; + + //3锛� 闄勫姞瑕丳OST缁欐湇鍔″櫒鐨勬暟鎹埌HttpWebRequest瀵硅薄(闄勫姞POST鏁版嵁鐨勮繃绋嬫瘮杈冪壒娈婏紝瀹冨苟娌℃湁鎻愪緵涓�涓睘鎬х粰鐢ㄦ埛瀛樺彇锛岄渶瑕佸啓鍏ttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰銆�) + var newStream = webRequest.GetRequestStream ();//鍒涘缓涓�涓猄tream,璧嬪�兼槸鍐欏叆HttpWebRequest瀵硅薄鎻愪緵鐨勪竴涓猻tream閲岄潰 + newStream.Write (byteData, 0, byteData.Length); + newStream.Flush (); + newStream.Close (); + } + + //4锛� 璇诲彇鏈嶅姟鍣ㄧ殑杩斿洖淇℃伅 + var response = (HttpWebResponse)webRequest.GetResponse (); + using (var stream = response.GetResponseStream ()) { + if (stream == null) { + return new ResponsePack () { StateCode = ErrorCode.NetworkError }; + } + var ms = new MemoryStream (); + var bytes = new byte [1024]; + var len = int.MaxValue; + while (stream.CanRead && 0 < len) { + len = stream.Read (bytes, 0, bytes.Length); + ms.Write (bytes, 0, len); + } + //var backBytes = ms.ToArray (); + string responseString = Encoding.UTF8.GetString (ms.ToArray ()); + + try { + ResponsePack revertObj = new ResponsePack () { }; + revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString); + if (revertObj.StateCode == null) { + revertObj.StateCode = "Data Exception"; + } + return revertObj; + } catch (Exception ex) { + Shared.Utlis.WriteLine (ex.ToString ()); + return new ResponsePack () { StateCode = "Data Exception" }; + } + + //return ms.ToArray (); + } + } catch (Exception ex) { +#if DEBUG + System.Console.WriteLine (ex.Message); +#endif + //The operation has timed out + return new ResponsePack () { StateCode = ErrorCode.NetworkError }; + } + + #endregion + + } + + + #region LoadingTipMsg 杩滅▼杩炴帴Tip + + static Button btnLoadingTipMsg; + + public static void LoadingTipShow (string tip) + { + + if (MainFrameLayout == null) { + return; + } + + Application.RunOnMainThread (() => { + try { + if (btnLoadingTipMsg == null) { + btnLoadingTipMsg = new Button () { + Height = Application.GetRealHeight (90), + BackgroundColor = SkinStyle.Current.MainColor, + //BackgroundColor = 0xFF000000, + Y = Application.GetRealHeight (36), + TextAlignment = TextAlignment.Center, + TextColor = 0xFF000000, + }; + } + if (btnLoadingTipMsg.Parent == null) { + MainFrameLayout.AddChidren (btnLoadingTipMsg); + if (btnLoadingTipMsg.MouseUpEventHandler == null) { + btnLoadingTipMsg.MouseUpEventHandler += (sender, e) => { + if (btnLoadingTipMsg.Parent != null) + btnLoadingTipMsg.RemoveFromParent (); + }; + } + } + + btnLoadingTipMsg.Text = tip; + + } catch { } + }); + } + + public static void LoadingTipHide () + { + if (MainFrameLayout == null) { + return; + } + Application.RunOnMainThread (() => { + try { + if (btnLoadingTipMsg != null) { + if (btnLoadingTipMsg.Parent != null) + btnLoadingTipMsg.RemoveFromParent (); + } + + } catch { } + }); + } + + #endregion + + /// <summary> /// 杩炴帴鏈嶅姟鍣ㄥけ璐� /// </summary> public static void FailureToServer () -- Gitblit v1.8.0