From 3e7c0a6deda128e639abfa3b8ed9377dbd017526 Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期五, 11 十二月 2020 17:47:24 +0800
Subject: [PATCH] 2020-12-11-4
---
HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs | 206 ++++++++++++++++----------------------------------
1 files changed, 67 insertions(+), 139 deletions(-)
diff --git a/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs b/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs
index 4412688..34747d8 100644
--- a/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs
+++ b/HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs
@@ -7,152 +7,35 @@
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
+ ///// 缃戝叧ID锛堢妗℃湁缃戝叧ID鍗磋繑鍥炴槸MAC锛�
///// </summary>
//public static string gatewayId = DriverLayer.Control.Ins.GatewayId;
/// <summary>
+ /// 缃戝叧ID(鑾峰彇鍢変箰缃戝叧ID)
+ /// </summary>
+ public static string gatewayId
+ {
+ get
+ {
+ if (Entity.DB_ResidenceData.residenceData.HomeGateway == null)
+ {
+ return "";
+ }
+ return Entity.DB_ResidenceData.residenceData.HomeGateway.gatewayId;
+ }
+ }
+ /// <summary>
/// 浣忓畢ID
/// </summary>
- public static string homeId = "1333723044544233473";
- /// <summary>
- /// 缃戝叧ID
- /// </summary>
- public static string gatewayId = "1333723647223775233";
- ///// <summary>
- ///// 鑾峰彇閫昏緫ID鍒楄〃
- ///// </summary>
- ///// <returns></returns>
- //public const string getLogicId = "鑾峰彇閫昏緫ID";
- ///// <summary>
- ///// 鑾峰彇閫昏緫
- ///// </summary>
- ///// <returns></returns>
- //public const string getLogic= "鑾峰彇閫昏緫璇︾粏";
- ///// <summary>
- ///// 娣诲姞鑷姩鍖栧懡浠�
- ///// </summary>
- ///// <returns></returns>
- //public const string addLogic= "娣诲姞鏂伴�昏緫";
- ///// <summary>
- ///// 缂栬緫鏇存柊閫昏緫
- ///// </summary>
- ///// <returns></returns>
- //public const string updateLogic = "缂栬緫閫昏緫";
- ///// <summary>
- ///// 鍒犻櫎閫昏緫
- ///// </summary>
- ///// <returns></returns>
- //public const string delLogic = "鍒犻櫎閫昏緫";
- ///// <summary>
- ///// 閫昏緫寮�鍏�
- ///// </summary>
- ///// <returns></returns>
- //public const string switchLogic = "閫昏緫寮�鍏�";
- //public static ResponsePackNew Logic(string type,Logic logic) {
- // string url = "";
- // var jObject = new JObject { };
- // switch (type) {
- // case getLogicId: {
- // jObject.Add("homeId",homeId);
- // url = NewAPI.API_POST_Logic_List;
- // }
- // break;
- // case getLogic: {
- // var jArray = new JArray { };
- // jArray.Add(logic.userLogicId);
- // jObject.Add("userLogicIds", jArray);
- // url = NewAPI.API_POST_Logic_Info;
- // } break;
- // case addLogic: {
- // try
- // {
- // var cycleJObject = new JObject { };
- // var cyclevaluejArray = new JArray { };
- // cycleJObject.Add("type", logic.cycle.type);
- // foreach (var dictionary in logic.cycle.value)
- // {
- // cyclevaluejArray.Add(dictionary);
- // }
- // cycleJObject.Add("value", cyclevaluejArray);
-
- // var inputArray = new JArray { };
- // foreach (var dictionary in logic.input)
- // {
- // var inputTypeJOb = new JObject { };
- // inputTypeJOb.Add("sid", dictionary.sid);
- // inputTypeJOb.Add("condition_type", dictionary.condition_type);
-
- // var conditionArray = new JArray { };
- // foreach (var dic in dictionary.condition)
- // {
- // var conditionJOb = new JObject { };
- // conditionJOb.Add("key", dic["key"]);
- // conditionJOb.Add("comparator", dic["comparator"]);
- // conditionJOb.Add("data_type", dic["data_type"]);
- // conditionJOb.Add("value", dic["value"]);
- // conditionArray.Add(conditionJOb);
- // }
- // inputTypeJOb.Add("condition", conditionArray);
- // inputArray.Add(inputTypeJOb);
- // }
-
- // var outputArray = new JArray { };
- // foreach (var dictionary in logic.output)
- // {
- // var outputTypeJOb = new JObject { };
- // outputTypeJOb.Add("sid", dictionary.sid);
- // outputTypeJOb.Add("target_type", dictionary.target_type);
- // var statusArray = new JArray { };
- // foreach (var dic in dictionary.status)
- // {
- // var statusJOb = new JObject { };
- // statusJOb.Add("key", dic["key"]);
- // statusJOb.Add("value", dic["value"]);
- // statusArray.Add(statusJOb);
- // }
- // outputTypeJOb.Add("status", statusArray);
- // outputArray.Add(outputTypeJOb);
- // }
-
- // var logicjArray = new JArray { };
- // var logicIfon = new JObject { };
- // logicIfon.Add("sid", logic.sid);
- // logicIfon.Add("gatewayId", gatewayId);
- // logicIfon.Add("name", logic.name);
- // logicIfon.Add("relation", logic.relation);
- // logicIfon.Add("enable", logic.enable);
- // logicIfon.Add("cycle", cycleJObject);
- // logicIfon.Add("input", inputArray);
- // logicIfon.Add("output", outputArray);
- // logicjArray.Add(logicIfon);
- // var jObject = new JObject { { "homeId", homeId }, { "logics", logicjArray } };
- // responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Add);
-
- // }
- // catch (Exception e)
- // {
- // var dd = e.Message;
- // }
- // } break;
- // case updateLogic: {
- // } break;
- // case delLogic: { } break;
- // case switchLogic: { } break;
-
-
- // }
-
- // return RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Add);
- //}
-
+ public static string homeId = Entity.DB_ResidenceData.residenceData.residecenInfo.RegionID;
/// <summary>
@@ -163,18 +46,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.userLogicId);
+ 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>
@@ -248,6 +147,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)
@@ -330,7 +235,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)
{
@@ -350,6 +260,12 @@
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>
@@ -363,6 +279,12 @@
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>
@@ -375,7 +297,6 @@
return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
}
-
/// <summary>
/// 璇锋眰鏈嶅姟鍣�
/// </summary>
@@ -386,6 +307,13 @@
return HttpUtil.RequestHttpsPost(api_Url, requestJson);
}
-
+ /// <summary>
+ /// 鍒锋柊Token
+ /// </summary>
+ public static void RefreshToken()
+ {
+ IMessageCommon.Current.StartRefreshToken();
+ }
+
}
}
--
Gitblit v1.8.0