From fef8136ca77f03dc4fb8988da94dcaf9dcabc9e0 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期三, 22 四月 2020 19:09:54 +0800 Subject: [PATCH] 2020-04-22 1.增加远程连接过程提示,请求参数合并到一个接口。 --- Crabtree/SmartHome/UI/SimpleControl/MainPage.cs | 215 ++++++++++++++++++++++------------------------------- 1 files changed, 90 insertions(+), 125 deletions(-) diff --git a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs index fdf907a..cd3fc15 100644 --- a/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs +++ b/Crabtree/SmartHome/UI/SimpleControl/MainPage.cs @@ -1,16 +1,14 @@ using System; -using Shared.IO; -using Shared.Net; using System.Text; using System.Collections.Generic; +using System.Net; +using System.IO; +using Shared.SimpleControl.Phone; // <summary> // 绋嬪簭涓诲叆鍙� // </summary> //using SystemConfiguration; -using System.Net; -using System.IO; -using Shared.SimpleControl.Phone; namespace Shared.SimpleControl { /// <summary> @@ -39,12 +37,31 @@ //public static Button LogoButton = new Button (); - public static string RequestVersion = "20200108"; + public static string RequestVersion = "20200422"; public static UserInfo LoginUser; /// <summary> /// 鏄惁鏄鐞嗗憳鏉冮檺(鍙樻洿浜�,鎴愬憳鐨勬椂鍊�,杩欎釜涔熶负ture銆備负浠�涔堜細澹版槑杩欐牱鍙橀噺,鍥犱负鏈変簺鎺ュ彛蹇呴』浣跨敤鍘熸潵鐨凾oken) /// </summary> - public static bool IsAdministrator = false; + public static bool IsAdministrator { + get { + if (UserConfig.Instance == null || UserConfig.Instance.CurrentRegion == null) { + return false; + } else { + return UserConfig.Instance.CurrentRegion.IsOthreShare; + } + } + } + + ///// <summary> + ///// 鏄惁璐﹀彿鍦ㄥ叾瀹冭澶囩櫥褰曚簡 + ///// </summary> + //public static bool IsOtherDevicesLogin = false; + +//#if __IOS__ +// public static readonly string PhoneType = "iOS"; +//#else +// public static readonly string PhoneType = "Android"; +//#endif public static string SoftPadTitle = "Crabtree"; public static string SoftTitle = "Crabtree"; @@ -120,10 +137,13 @@ } else { Phone.UserHomePage.Init (); #if __IOS__ - //Loading.LodingBackgroundColor = 0x10777777; + //Loading.LodingBackgroundColor = 0x10777777; + #else - Loading.LodingBackgroundColor = SkinStyle.Current.MainColor; + //Loading.LodingBackgroundColor = SkinStyle.Current.MainColor; #endif + Loading.TextColor = 0xFFA9A9A9; + Loading.LodingBackgroundColor = SkinStyle.Current.MainColor; } } catch (Exception ex) { //new Alert ("Eorr", ex.Message, "Close").Show(); @@ -146,11 +166,13 @@ Gravity = Gravity.Center, Width = Application.GetRealWidth (560), Height = Application.GetRealHeight (126), - BackgroundColor = SkinStyle.Current.AddTipButtonColor, + //BackgroundColor = SkinStyle.Current.AddTipButtonColor, + BackgroundColor = SkinStyle.Current.MainColor, Radius = 10, IsMoreLines = true, Text = tip, TextSize = 16, + TextColor = 0xFF000000 }; MainFrameLayout.AddChidren (button); button.MouseUpEventHandler += (sender, e) => { @@ -174,112 +196,44 @@ /// <param name="methodType">璇锋眰鏂规硶.</param> /// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param> /// <param name="needHeaders">鏄惁闇�瑕佸寘澶�.</param> - public static ResponsePack RequestHttps (string methodType, string dataStringJson, bool needHeaders = false, bool needTip2 = true, string urlHead = "") + public static ResponsePack RequestHttps (string methodType, string dataStringJson, string urlHead = "") { - ResponsePack revertObj = null; - try { - if (!SystemRemote.checeInternet ()) { - Application.RunOnMainThread (() => { - MainPage.WiFiStatus = "CrabtreeAdd/WiFiUnlink.png"; - MainPage.Loading.Hide (); - }); - } - //new System.Threading.Thread (() => { - // requesTime = DateTime.Now; - // isShowLoading = true; - // while (isShowLoading) { - // System.Threading.Thread.Sleep (1000); - // if (requesTime == DateTime.MinValue) { - // break; - // } - // if (requesTime.AddSeconds (30) < DateTime.Now) { - // Application.RunOnMainThread (Loading.Hide); - // isShowLoading = false; - // } - // } - //}) { IsBackground = true }.Start (); + ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => { + return true; + }; - - #region - var webClient = new WebClient (); - if (urlHead == "") { - urlHead = RequestHttpsHost; - } - //else { - // webClient.Headers.Add ("CONTENT-TYPE", "application/json"); - //} - webClient.Headers.Add ("CONTENT-TYPE", "application/json"); - string url = urlHead + methodType; - if (needHeaders && LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */ - webClient.Headers.Add ("Authorization", LoginUser.LoginTokenString); - } - byte [] bytes = null; - try { - bytes = webClient.UploadData (url, Encoding.UTF8.GetBytes (dataStringJson)); - } catch (System.Net.WebException webEx) { - Application.RunOnMainThread (() => { - MainPage.Loading.Hide (); - revertObj = new ResponsePack () { StateCode = ErrorCode.NetworkError }; - //new Alert ( "","Network abnormal, unable to connect to the Internet", Language.StringByID (R.MyInternationalizationString.Close)).Show (); - return; - }); - } - string responseString = null; - if (bytes != null) { - responseString = Encoding.UTF8.GetString (bytes); - //var DD = Newtonsoft.Json.Linq.JObject .Parse("GFGFDG");DD["ResponseData"]["PageData"] - } - - //var request = (HttpWebRequest)WebRequest.Create (url); - //var data = Encoding.UTF8.GetBytes (dataStringJson); - //request.Method = "POST"; - //request.ContentLength = data.Length; - //if (needHeaders) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */ - // request.Headers.Set (HttpRequestHeader.Authorization, LoginUser.LoginTokenString); - //} - //using (var stream = request.GetRequestStream ()) { - // stream.Write (data, 0, data.Length); - //} - //var response = (HttpWebResponse)request.GetResponse (); - //var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd (); - - if (responseString != null) { - try { - revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString); - //if (revertObj.StateCode.ToUpper() != "SUCCESS") { - // if (methodType == API.IsExistingAccount) { - - // } else if (needTip) { - // Application.RunOnMainThread (() => { - // new Alert ("", revertObj.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show (); - // }); - // } - //} - } catch (Exception ex) { - Console.WriteLine (ex.ToString ()); - revertObj = new ResponsePack () { StateCode = "Data exception" }; - } - } - else { - revertObj = new ResponsePack () { StateCode = ErrorCode.NetworkError }; - //if (methodType == API.Login && needTip) { - // Application.RunOnMainThread (() => { - // new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToDataBase), - // Language.StringByID (R.MyInternationalizationString.Close)).Show (); - // }); - //} else { - // if (needTip) - // FailureToServer (); - //} - } - return revertObj; - #endregion - } catch (Exception ex) { - Console.WriteLine (ex.Message); - return revertObj; - } finally { - //requesTime = requesTime.AddDays(1); + #region + var webClient = new WebClient (); + if (urlHead == "") { + urlHead = RequestHttpsHost; } + //else { + // webClient.Headers.Add ("CONTENT-TYPE", "application/json"); + //} + webClient.Headers.Add ("CONTENT-TYPE", "application/json"); + string url = urlHead + methodType; + if (LoginUser != null) {/* 濡傛灉涓嶉渶瑕侀獙璇乀oken鍙互涓嶇敤浼犲叆 */ + webClient.Headers.Add ("Authorization", LoginUser.LoginTokenString); + } + byte [] bytes = null; + try { + bytes = webClient.UploadData (url, Encoding.UTF8.GetBytes (dataStringJson)); + } catch (System.Net.WebException webEx) { + Application.RunOnMainThread (() => { + MainPage.Loading.Hide (); + }); + return new ResponsePack () { StateCode = ErrorCode.NetworkError }; + } + string responseString = Encoding.UTF8.GetString (bytes); + + try { + return Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString); + } catch (Exception ex) { + Utlis.WriteLine (ex.ToString ()); + return new ResponsePack () { StateCode = "Data exception" }; + } + #endregion + } /// <summary> @@ -289,18 +243,14 @@ /// <param name="methodType">璇锋眰鏂规硶.</param> /// <param name="dataStringJson">璇锋眰鐨勫弬鏁�.</param> /// <param name="needHeaders">鏄惁闇�瑕佸寘澶�.</param> - public static byte [] RequestHttpsReturnByte (string methodType, string dataStringJson, bool needHeaders = false, bool needTip2 = true, string urlHead = "") + public static byte [] RequestHttpsReturnByte (string methodType, string dataStringJson, bool needHeaders = false, string urlHead = "") { ResponsePack revertObj = null; try { - if (!SystemRemote.checeInternet ()) { - Application.RunOnMainThread (() => { - MainPage.WiFiStatus = "CrabtreeAdd/WiFiUnlink.png"; - MainPage.Loading.Hide (); - }); - } - + ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, error) => { + return true; + }; #region var webClient = new WebClient (); @@ -326,7 +276,7 @@ return bytes; #endregion } catch (Exception ex) { - Console.WriteLine (ex.Message); + Utlis.WriteLine (ex.Message); return null; } finally { //requesTime = requesTime.AddDays(1); @@ -339,11 +289,24 @@ /// </summary> public static void FailureToServer () { + //Application.RunOnMainThread (() => { + // new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer), + // Language.StringByID (R.MyInternationalizationString.Close)).Show (); + //}); + ShowAlertOnMainThread (Language.StringByID (R.MyInternationalizationString.FailureToServer)); + } + + /// <summary> + /// 2020-01-11 寮圭獥鎻愮ず + /// </summary> + /// <param name="mes"></param> + public static void ShowAlertOnMainThread (string mes) + { Application.RunOnMainThread (() => { - new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer), - Language.StringByID (R.MyInternationalizationString.Close)).Show (); + new Alert ("", mes, Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } + /// <summary> /// 璁惧涓嶅湪绾匡紝鏃犲搷搴� @@ -369,5 +332,7 @@ MainPage.Loading.Hide (); }); } + + } -} \ No newline at end of file +} -- Gitblit v1.8.0