| | |
| | | { |
| | | |
| | | var list = jObjectdata["Data"]["LogicList"]; |
| | | if(list==null){ |
| | | if (list == null) |
| | | { |
| | | return; |
| | | } |
| | | foreach (var listIfon in list) |
| | |
| | | mainGateWay.GwResDataAction += action; |
| | | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2004 } }; |
| | | mainGateWay?.Send("Logic/GetLogicList",jObject.ToString()); |
| | | mainGateWay?.Send("Logic/GetLogicList", jObject.ToString()); |
| | | //await System.Threading.Tasks.Task.Run(async () => |
| | | //{ |
| | | var dateTime = DateTime.Now; |
| | |
| | | Common.Logic logic = null; |
| | | Action<string, string> action = (topic, data) => |
| | | { |
| | | |
| | | |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jObjectdata = JObject.Parse(data); |
| | | if (jObjectdata == null) |
| | |
| | | |
| | | if (topic == $"{gatewayID}/Logic/GetLogicInfo_Respon") |
| | | { |
| | | |
| | | logic = new Common.Logic(); |
| | | var Logicifon = jObjectdata["Data"]; |
| | | logic.LogicId = int.Parse(Logicifon["LogicId"]?.ToString()); |
| | | logic.IsEnable = int.Parse(Logicifon["IsEnable"]?.ToString()); |
| | | logic.LogicName = Logicifon["LogicName"]?.ToString(); |
| | | |
| | | logic.Relationship = int.Parse(Logicifon["Relationship"]?.ToString()); |
| | | logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.TimeAttributeObj>(Logicifon["TimeAttribute"].ToString()); |
| | | logic.Conditions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Conditions"].ToString()); |
| | | var listactions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(Logicifon["Actions"].ToString()); |
| | | if (listactions != null) |
| | | logic = new Common.Logic(); |
| | | var Logicifon = jObjectdata["Data"]; |
| | | logic.LogicId = int.Parse(Logicifon["LogicId"]?.ToString()); |
| | | logic.IsEnable = int.Parse(Logicifon["IsEnable"]?.ToString()); |
| | | logic.LogicName = Logicifon["LogicName"]?.ToString(); |
| | | |
| | | logic.Relationship = int.Parse(Logicifon["Relationship"]?.ToString()); |
| | | logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.TimeAttributeObj>(Logicifon["TimeAttribute"].ToString()); |
| | | logic.Conditions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Conditions"].ToString()); |
| | | var listactions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(Logicifon["Actions"].ToString()); |
| | | if (listactions != null) |
| | | { |
| | | foreach (var actions in listactions) |
| | | { |
| | | foreach (var actions in listactions) |
| | | Dictionary<string, object> actionsdictionary = new Dictionary<string, object>(); |
| | | List<Dictionary<string, string>> tasklist = new List<Dictionary<string, string>>(); |
| | | if (actions["LinkType"].ToString() == "0") |
| | | { |
| | | Dictionary<string, object> actionsdictionary = new Dictionary<string, object>(); |
| | | List<Dictionary<string, string>> tasklist = new List<Dictionary<string, string>>(); |
| | | if (actions["LinkType"].ToString() == "0") |
| | | actionsdictionary.Add("LinkType", actions["LinkType"]); |
| | | actionsdictionary.Add("DeviceAddr", actions["DeviceAddr"]); |
| | | actionsdictionary.Add("Epoint", actions["Epoint"]); |
| | | actionsdictionary.Add("Time", actions["Time"]); |
| | | var list = JArray.Parse(actions["TaskList"].ToString()); |
| | | foreach (var taskIfon in list) |
| | | { |
| | | actionsdictionary.Add("LinkType", actions["LinkType"]); |
| | | actionsdictionary.Add("DeviceAddr", actions["DeviceAddr"]); |
| | | actionsdictionary.Add("Epoint", actions["Epoint"]); |
| | | actionsdictionary.Add("Time", actions["Time"]); |
| | | var list = JArray.Parse(actions["TaskList"].ToString()); |
| | | foreach (var taskIfon in list) |
| | | { |
| | | Dictionary<string, string> dictionary = new Dictionary<string, string>(); |
| | | dictionary.Add("TaskType", taskIfon["TaskType"].ToString()); |
| | | dictionary.Add("Data1", taskIfon["Data1"].ToString()); |
| | | dictionary.Add("Data2", taskIfon["Data2"].ToString()); |
| | | tasklist.Add(dictionary); |
| | | } |
| | | actionsdictionary.Add("TaskList", tasklist); |
| | | Dictionary<string, string> dictionary = new Dictionary<string, string>(); |
| | | dictionary.Add("TaskType", taskIfon["TaskType"].ToString()); |
| | | dictionary.Add("Data1", taskIfon["Data1"].ToString()); |
| | | dictionary.Add("Data2", taskIfon["Data2"].ToString()); |
| | | tasklist.Add(dictionary); |
| | | } |
| | | else |
| | | { |
| | | actionsdictionary = actions; |
| | | } |
| | | |
| | | logic.Actions.Add(actionsdictionary); |
| | | actionsdictionary.Add("TaskList", tasklist); |
| | | } |
| | | else |
| | | { |
| | | actionsdictionary = actions; |
| | | } |
| | | |
| | | logic.Actions.Add(actionsdictionary); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | }; |
| | | }; |
| | | var mainGateWay = ZbGateway.MainGateWay; |
| | |
| | | Common.Logic Logicifon = null; |
| | | Action<string, string> action = (topic, datastring) => |
| | | { |
| | | |
| | | |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jObjectdata = JObject.Parse(datastring); |
| | | if (jObjectdata == null) |
| | |
| | | if (topic == gatewayID + "/Logic/AddLogic_Respon") |
| | | { |
| | | try |
| | | { |
| | | Logicifon=new Common.Logic(); |
| | | { |
| | | Logicifon = new Common.Logic(); |
| | | Logicifon = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.Logic>(jObjectdata["Data"].ToString()); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | var tInfo = new JObject |
| | | { |
| | | ["Type"] = int.Parse(dictionary["Type"]), |
| | | ["IsValid"] =int.Parse(dictionary["IsValid"]), |
| | | ["IsValid"] = int.Parse(dictionary["IsValid"]), |
| | | ["DateType"] = int.Parse(dictionary["DateType"]), |
| | | ["RemindTime"] = int.Parse(dictionary["RemindTime"]), |
| | | ["EnDelay"] = int.Parse(dictionary["EnDelay"]), |
| | |
| | | ["LinkType"] = int.Parse(dictionary["LinkType"].ToString()), |
| | | ["DeviceAddr"] = dictionary["DeviceAddr"].ToString(), |
| | | ["Epoint"] = int.Parse(dictionary["Epoint"].ToString()), |
| | | ["Time"] =int.Parse(dictionary["Time"].ToString()), |
| | | ["Time"] = int.Parse(dictionary["Time"].ToString()), |
| | | ["taskList"] = taskList, |
| | | |
| | | }; |
| | |
| | | |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 3*1000) |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | if (Logicifon != null) |
| | |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 单独控制自动化开关属性 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static async System.Threading.Tasks.Task<int> LogicControlSwitch(Common.Logic logic) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | int intvalue = 3; |
| | | Action<string, string> action = (topic, data) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jObjectdata = JObject.Parse(data); |
| | | if (jObjectdata == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (topic == $"{gatewayID}/Logic/ReviseAttribute_Respon") |
| | | { |
| | | intvalue = int.Parse(jObjectdata["Data"]["Result"].ToString()); |
| | | } |
| | | }; |
| | | var mainGateWay = ZbGateway.MainGateWay; |
| | | if (mainGateWay == null) |
| | | { |
| | | Console.WriteLine("没有主网关"); |
| | | return intvalue; |
| | | } |
| | | mainGateWay.GwResDataAction += action; |
| | | |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2001 } }; |
| | | var date = new JObject(); |
| | | jObject.Add("Data", date); |
| | | date.Add("LogicId", logic.LogicId); |
| | | date.Add("IsEnable", logic.IsEnable); |
| | | //date.Add("LogicName", logic.LogicName); |
| | | //date.Add("Relationship", logic.Relationship); |
| | | mainGateWay?.Send("Logic/ReviseAttribute", jObject.ToString()); |
| | | //await System.Threading.Tasks.Task.Run(async () => |
| | | //{ |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 3 * 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | if (intvalue != 3) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | ZbGateway.MainGateWay.GwResDataAction -= action; |
| | | //}); |
| | | return intvalue; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 获取Logic列表的方法 |
| | | /// </summary> |
| | | /// <returns>The logic identifier.</returns> |
| | | public static async System.Threading.Tasks.Task<List<Common.Logic>> ReadList(int sum) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | |
| | | var listLogic = new List<Common.Logic>(); |
| | | bool @bool = false; |
| | | Action<string, string> action = (topic, data) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jObjectdata = JObject.Parse(data); |
| | | if (jObjectdata == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (topic == $"{gatewayID}/Logic/GetAllLogicListInfo_Respon") |
| | | { |
| | | |
| | | var logic = new Common.Logic(); |
| | | var Logicifon = jObjectdata["Data"]; |
| | | logic.LogicId = int.Parse(Logicifon["LogicId"].ToString()); |
| | | logic.IsEnable = int.Parse(Logicifon["IsEnable"].ToString()); |
| | | logic.LogicName = Logicifon["LogicName"].ToString(); |
| | | logic.Relationship = int.Parse(Logicifon["Relationship"].ToString()); |
| | | logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.TimeAttributeObj>(Logicifon["TimeAttribute"].ToString()); |
| | | logic.Conditions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Conditions"].ToString()); |
| | | List<Dictionary<string, object>> listactions = new List<Dictionary<string, object>>(); |
| | | listactions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(Logicifon["Actions"].ToString()); |
| | | |
| | | if (listactions != null) |
| | | { |
| | | foreach (var actions in listactions) |
| | | { |
| | | Dictionary<string, object> actionsdictionary = new Dictionary<string, object>(); |
| | | List<Dictionary<string, string>> tasklist = new List<Dictionary<string, string>>(); |
| | | if (actions["LinkType"].ToString() == "0") |
| | | { |
| | | actionsdictionary.Add("LinkType", actions["LinkType"]); |
| | | actionsdictionary.Add("DeviceAddr", actions["DeviceAddr"]); |
| | | actionsdictionary.Add("Epoint", actions["Epoint"]); |
| | | actionsdictionary.Add("Time", actions["Time"]); |
| | | var list = JArray.Parse(actions["TaskList"].ToString()); |
| | | foreach (var taskIfon in list) |
| | | { |
| | | Dictionary<string, string> dictionary = new Dictionary<string, string>(); |
| | | dictionary.Add("TaskType", taskIfon["TaskType"].ToString()); |
| | | dictionary.Add("Data1", taskIfon["Data1"].ToString()); |
| | | dictionary.Add("Data2", taskIfon["Data2"].ToString()); |
| | | tasklist.Add(dictionary); |
| | | } |
| | | actionsdictionary.Add("TaskList", tasklist); |
| | | } |
| | | else |
| | | { |
| | | actionsdictionary = actions; |
| | | } |
| | | |
| | | logic.Actions.Add(actionsdictionary); |
| | | } |
| | | |
| | | } |
| | | |
| | | lock (listLogic) |
| | | { |
| | | var @null = listLogic.Find((o) => { return o.LogicId == logic.LogicId; }); |
| | | if (@null == null) |
| | | { |
| | | listLogic.Add(logic); |
| | | } |
| | | } |
| | | |
| | | } |
| | | if (topic == $"{gatewayID}/Logic/AllLogicNum_Respon") |
| | | { |
| | | @bool = true; |
| | | } |
| | | }; |
| | | var mainGateWay = ZbGateway.MainGateWay; |
| | | if (mainGateWay == null) |
| | | { |
| | | Console.WriteLine("没有主网关"); |
| | | return listLogic; |
| | | } |
| | | mainGateWay.GwResDataAction += action; |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2015 } }; |
| | | ZbGateway.MainGateWay?.Send("Logic/GetAllLogicListInfo", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 8 * 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | //if (sum == listLogic.Count) |
| | | //{ |
| | | // break; |
| | | //} |
| | | if (@bool) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | ZbGateway.MainGateWay.GwResDataAction -= action; |
| | | return listLogic; |
| | | }); |
| | | } |
| | | // <summary> |
| | | /// 通过设备找到区域(房间)名称 |
| | | /// </summary> |
| | | /// <param name="btnregionname">Btnregionname.</param> |
| | | /// <param name="device">Device.</param> |
| | | public static void RoomNmae(Button btnregionname, CommonDevice device) |
| | | { |
| | | var room = new Common.Room(); |
| | | var roomlistname = room.GetRoomListNameByDevice(device); |
| | | if (roomlistname.Count == 0) |
| | | { |
| | | btnregionname.Text = Language.StringByID(R.MyInternationalizationString.customroom); |
| | | } |
| | | else |
| | | { |
| | | foreach (var roomname in roomlistname) |
| | | { |
| | | btnregionname.Text += roomname + ","; |
| | | } |
| | | btnregionname.Text = btnregionname.Text.TrimEnd(','); |
| | | } |
| | | var room = new Common.Room();
|
| | | btnregionname.Text = room.GetRoomNameByDevice(device); |
| | | } |
| | | } |
| | | } |