From 5eeafe3af80bfd88306bd8ad9e76c8f4b51ca35f Mon Sep 17 00:00:00 2001 From: hxb <hxb@hdlchina.com.cn> Date: 星期四, 17 十二月 2020 14:16:20 +0800 Subject: [PATCH] 增加本地发送的重发机制 --- HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs | 103 +++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 78 insertions(+), 25 deletions(-) diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs index 6f61531..580a8a6 100644 --- a/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs +++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs @@ -1,4 +1,4 @@ -锘縰sing System; +using System; using System.IO; using System.Net; using HDL_ON.DAL.Server; @@ -7,25 +7,34 @@ namespace HDL_ON.UI.UI2.Intelligence.Automation { - public class Send + public class Send { - ///// <summary> - ///// 浣忓畢ID - ///// </summary> - //public static string homeId = Entity.DB_ResidenceData.residenceData.CurReginID; - ///// <summary> - ///// 缃戝叧ID - ///// </summary> - //public static string gatewayId = DriverLayer.Control.Ins.GatewayId; + /// <summary> + /// 缃戝叧ID(鑾峰彇鍢変箰缃戝叧ID) + /// </summary> + public static string gatewayId + { + get + { + if (Entity.DB_ResidenceData.Instance.HomeGateway == null) + { + return DriverLayer.Control.Ins.GatewayId; + } + return Entity.DB_ResidenceData.Instance.HomeGateway.gatewayId; + } + } /// <summary> /// 浣忓畢ID /// </summary> - public static string homeId = "1333681497069043713"; - /// <summary> - /// 缃戝叧ID - /// </summary> - public static string gatewayId = "1333682616549752834"; + public static string homeId + { + get + { + return Entity.DB_ResidenceData.Instance.CurrentRegion.RegionID; + } + } + /// <summary> /// 鑾峰彇閫昏緫ID鍒楄〃 /// </summary> @@ -34,18 +43,34 @@ { var jObject = new JObject { { "homeId", homeId } }; var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_List); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + getLogicIdList(); + } return responsePackNew; } /// <summary> /// 鑾峰彇閫昏緫 /// </summary> + /// <param name="listIdList">閫昏緫ID鍒楄〃</param> /// <returns></returns> - public static ResponsePackNew getLogic(Logic logic) + public static ResponsePackNew getLogic(List<string> listIdList) { var jArray = new JArray { }; - jArray.Add(logic.sid); + for (int i = 0; i < listIdList.Count; i++) + { + jArray.Add(listIdList[i]); + } var jObject = new JObject { { "userLogicIds", jArray } }; var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Info); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + getLogic(listIdList); + } return responsePackNew; } /// <summary> @@ -119,6 +144,12 @@ logicjArray.Add(logicIfon); var jObject = new JObject { { "homeId", homeId }, { "logics", logicjArray } }; responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Add); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + AddLogic(logic); + } } catch (Exception e) @@ -129,7 +160,6 @@ return responsePackNew; } - /// <summary> /// 缂栬緫鏇存柊閫昏緫 /// </summary> @@ -190,6 +220,7 @@ var logicjArray = new JArray { }; var logicIfon = new JObject { }; + logicIfon.Add("userLogicId", logic.userLogicId); logicIfon.Add("sid", logic.sid); logicIfon.Add("gatewayId", gatewayId); logicIfon.Add("name", logic.name); @@ -201,7 +232,12 @@ logicjArray.Add(logicIfon); var jObject = new JObject { { "homeId", homeId }, { "logics", logicjArray } }; responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Update); - + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + updateLogic(logic); + } } catch (Exception e) { @@ -218,9 +254,15 @@ public static ResponsePackNew delLogic(Logic logic) { var jArray = new JArray { }; - jArray.Add(logic.sid); + jArray.Add(logic.userLogicId); var jObject = new JObject { { "userLogicIds", jArray } }; var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Delete); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + delLogic(logic); + } return responsePackNew; } /// <summary> @@ -229,25 +271,29 @@ /// <returns></returns> public static ResponsePackNew switchLogic(Logic logic) { - logic.enable ="false"; var jArray = new JArray { }; - var job = new JObject { { "userLogicId", logic.sid } , { "enable", logic.enable } }; + var job = new JObject { { "userLogicId", logic.userLogicId } , { "enable", logic.enable } }; jArray.Add(job); var jObject = new JObject { { "logics", jArray } }; var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Enable); + //濡傛灉鏄痶oken杩囨湡鍒欏埛鏂皌oken + if (responsePackNew.Code == StateCode.TOKEN_EXPIRED) + { + RefreshToken(); + switchLogic(logic); + } return responsePackNew; } /// <summary> ///璇锋眰鏈嶅姟鍣紙涓庝綇瀹呮湁鍏�:渚嬪锛沨omeId锛� /// </summary> /// <returns></returns> - public static ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 10) + public static ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 3) { var requestJson = HttpUtil.GetSignRequestJson(o); return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout); } - /// <summary> /// 璇锋眰鏈嶅姟鍣� /// </summary> @@ -258,6 +304,13 @@ return HttpUtil.RequestHttpsPost(api_Url, requestJson); } - + /// <summary> + /// 鍒锋柊Token + /// </summary> + public static void RefreshToken() + { + IMessageCommon.Current.StartRefreshToken(); + } + } } -- Gitblit v1.8.0