From 29209469ac17d877eb92d008456b58ad901bfb58 Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期三, 30 十月 2019 14:37:42 +0800 Subject: [PATCH] 2019-10-30-1 --- ZigbeeApp/Shared/Phone/Device/Logic/Send.cs | 298 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 226 insertions(+), 72 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs index 348124f..061d345 100644 --- a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs +++ b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs @@ -4,17 +4,18 @@ using ZigBee.Device; using ZigBee.Common; using Shared.Common; +using System.Collections.Specialized; namespace Shared.Phone.Device.Logic { public class Send { - + #region ----鑾峰彇Logic /// <summary> /// 鑾峰彇LogicId鐨勬柟娉� /// </summary> /// <returns>The logic identifier.</returns> - public static async System.Threading.Tasks.Task<List<int>> GetLogicId() + public static async System.Threading.Tasks.Task<List<int>> GetLogicId(int LogicType) { return await System.Threading.Tasks.Task.Run(async () => { @@ -53,6 +54,8 @@ mainGateWay.GwResDataAction += action; var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2004 } }; + var jObjectdata1 = new JObject { { "LogicType", LogicType } }; + jObject.Add("Data", jObjectdata1); mainGateWay?.Send("Logic/GetLogicList", jObject.ToString()); //await System.Threading.Tasks.Task.Run(async () => //{ @@ -74,7 +77,7 @@ /// 鑾峰彇Logic鐨勬柟娉� /// </summary> /// <returns>The logic identifier.</returns> - public static async System.Threading.Tasks.Task<Common.Logic> GetLogic(int LogicId) + public static async System.Threading.Tasks.Task<Common.Logic> GetLogic(int LogicId, int LogicType) { return await System.Threading.Tasks.Task.Run(async () => { @@ -149,7 +152,8 @@ { var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2002 } }; var data = new JObject { - { "LogicId",LogicId} + { "LogicId",LogicId}, + { "LogicType",LogicType} }; jObject.Add("Data", data); ZbGateway.MainGateWay?.Send("Logic/GetLogicInfo", jObject.ToString()); @@ -449,13 +453,26 @@ } } var accounts = new JArray(); - foreach (var dictionary in logic.Accounts) { + foreach (var dictionary in logic.Accounts) + { var Type = int.Parse(dictionary["Type"]); switch (Type) { - case 1: { + case 1: + { /// - } break; + if (logic.LogicType == 1) + { + var accounts1 = new JObject + { + ["Type"] = int.Parse(dictionary["Type"]), + ["Account"] = dictionary["Account"], + + }; + accounts.Add(accounts1); + } + } + break; case 7: { var location = new JObject @@ -478,6 +495,7 @@ { "IsEnable", logic.IsEnable} , { "LogicName", logic.LogicName}, { "Relationship",logic.Relationship} , + { "LogicType",logic.LogicType} , { "LogicCustomPushText",logic.LogicCustomPushText} , { "TimeAttribute", timeAttribute} , { "Conditions", conditions }, @@ -566,13 +584,13 @@ /// 鑾峰彇Logic鍒楄〃鐨勬柟娉� /// </summary> /// <returns>The logic identifier.</returns> - public static async System.Threading.Tasks.Task<List<Common.Logic>> ReadList(int sum) + public static async System.Threading.Tasks.Task<List<Common.Logic>> ReadList(int sum, int LogicType) { return await System.Threading.Tasks.Task.Run(async () => { - var listLogic = new List<Common.Logic>(); - bool @bool = false; + var listLogic = new List<Common.Logic>(); + // bool @bool = false; Action<string, string> action = (topic, data) => { var gatewayID = topic.Split('/')[0]; @@ -590,9 +608,11 @@ 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.LogicType = int.Parse(Logicifon["LogicType"].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()); + logic.Accounts = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(Logicifon["Accounts"].ToString()); List<Dictionary<string, object>> listactions = new List<Dictionary<string, object>>(); listactions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(Logicifon["Actions"].ToString()); @@ -639,10 +659,10 @@ } } - if (topic == $"{gatewayID}/Logic/AllLogicNum_Respon") - { - @bool = true; - } + //if (topic == $"{gatewayID}/Logic/AllLogicNum_Respon") + //{ + // @bool = true; + //} }; var mainGateWay = ZbGateway.MainGateWay; if (mainGateWay == null) @@ -654,6 +674,8 @@ try { var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2015 } }; + var jObjectdata = new JObject { { "LogicType", LogicType } }; + jObject.Add("Data", jObjectdata); ZbGateway.MainGateWay?.Send("Logic/GetAllLogicListInfo", jObject.ToString()); } catch { } @@ -661,14 +683,14 @@ while ((DateTime.Now - dateTime).TotalMilliseconds < 8 * 1000) { await System.Threading.Tasks.Task.Delay(100); - //if (sum == listLogic.Count) - //{ - // break; - //} - if (@bool) + if (sum == listLogic.Count) { break; } + //if (@bool) + //{ + // break; + //} } ZbGateway.MainGateWay.GwResDataAction -= action; return listLogic; @@ -690,6 +712,7 @@ return Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId); } +# endregion #region ----鑾峰彇闂ㄩ攣 public static List<DoorLock> ReadDoorLockIfon(string doorlockMac) @@ -700,57 +723,57 @@ System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); postValues.Add("RequestVersion", CommonPage.RequestVersion); postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); - System.Threading.Tasks.Task.Run(() => - { - try - { - - byte[] responseArray = webClient.UploadValues(url, postValues); - var str = System.Text.Encoding.UTF8.GetString(responseArray); - var jObject = JObject.Parse(str); - if (jObject == null || jObject["StateCode"].ToString() != "Success") - { - return; - } - var pageData = jObject["ResponseData"]["PageData"].ToString(); - var datalist = JArray.Parse(pageData); - for (int i = 0; i < datalist.Count; i++) - { - var data = JObject.Parse(datalist[i].ToString()); - if (Config.Instance.HomeId == data["Id"].ToString()) - { - Residential residential = new Residential(); - - if (Convert.ToBoolean(data["IsOthreShare"].ToString())) - { + System.Threading.Tasks.Task.Run(() => + { + try + { + + byte[] responseArray = webClient.UploadValues(url, postValues); + var str = System.Text.Encoding.UTF8.GetString(responseArray); + var jObject = JObject.Parse(str); + if (jObject == null || jObject["StateCode"].ToString() != "Success") + { + return; + } + var pageData = jObject["ResponseData"]["PageData"].ToString(); + var datalist = JArray.Parse(pageData); + for (int i = 0; i < datalist.Count; i++) + { + var data = JObject.Parse(datalist[i].ToString()); + if (Config.Instance.HomeId == data["Id"].ToString()) + { + Residential residential = new Residential(); + + if (Convert.ToBoolean(data["IsOthreShare"].ToString())) + { //鍒嗕韩鑰匢D residential.Id = data["Id"].ToString(); //鏄惁鏄垎浜处鍙穂true(鏄垎浜�);false;(涓嶆槸鍒嗕韩)]; residential.IsOthreShare = Convert.ToBoolean(data["IsOthreShare"].ToString()); //鍒嗕韩鑰呬綇瀹匢D - residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); - residential.IsOtherAccountCtrl = true; - residential.doorlockmac = doorlockMac; - list = ReadToken(residential); - } - else - { - residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/DoorLock/GetDoorLockPager"; - residential.Token = Config.Instance.Token; - residential.Id = Config.Instance.HomeId; - residential.IsOtherAccountCtrl = false; - residential.doorlockmac = doorlockMac; - list = ReadDoorLock(residential); - - } - } - - } - } - catch { } - }); + residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); + residential.IsOtherAccountCtrl = true; + residential.doorlockmac = doorlockMac; + list = ReadToken(residential); + } + else + { + residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/DoorLock/GetDoorLockPager"; + residential.Token = Config.Instance.Token; + residential.Id = Config.Instance.HomeId; + residential.IsOtherAccountCtrl = false; + residential.doorlockmac = doorlockMac; + list = ReadDoorLock(residential); + + } + } + + } + } + catch { } + }); var datetime = DateTime.Now; - while ((DateTime.Now - datetime).TotalMilliseconds < 3*1000) + while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000) { if (list.Count != 0) { @@ -785,7 +808,7 @@ var RequestBaseUrl = jObject["ResponseData"]["RequestBaseUrl"].ToString(); var RequestToken = jObject["ResponseData"]["RequestToken"].ToString(); Residential lockifon = new Residential(); - lockifon.Url = RequestBaseUrl + "/App/GetDoorLockPager"; + lockifon.Url = RequestBaseUrl + "/DoorLock/GetDoorLockPager"; lockifon.Token = RequestToken; lockifon.Id = Config.Instance.HomeId; lockifon.IsOtherAccountCtrl = true; @@ -809,7 +832,7 @@ public static List<DoorLock> ReadDoorLock(Residential lockifon) { List<DoorLock> list = new List<DoorLock>(); - System.Net.WebClient webClient = new System.Net.WebClient(); + System.Net.WebClient webClient = new System.Net.WebClient(); System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); postValues.Add("RequestVersion", CommonPage.RequestVersion); postValues.Add("LoginAccessToken", lockifon.Token); @@ -841,13 +864,13 @@ } } - catch + catch(Exception e) { - + var s = e.Message; } }); - var datetime = DateTime.Now; + var datetime = DateTime.Now; while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000) { if (list.Count != 0) @@ -889,13 +912,144 @@ public class MembershipIfon { public string MembershipId = string.Empty; - public List<string> UserIdMode=new List<string>(); + public List<string> UserIdMode = new List<string>(); public string MembershipName = string.Empty; } public static List<MembershipIfon> UserList = new List<MembershipIfon>(); - + #endregion + /* + public async System.Threading.Tasks.Task<List<>> a() + { + string url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager"; + System.Collections.Specialized.NameValueCollection postValues = new System.Collections.Specialized.NameValueCollection(); + postValues.Add("RequestVersion", CommonPage.RequestVersion); + postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); + var str = await WebClientAsync(postValues, url); + var jObject = JObject.Parse(str); + if (jObject == null || jObject["StateCode"].ToString() != "Success") + { + return null; + } + var pageData = jObject["ResponseData"]["PageData"].ToString(); + var datalist = JArray.Parse(pageData); + for (int i = 0; i < datalist.Count; i++) + { + var data = JObject.Parse(datalist[i].ToString()); + if (Config.Instance.HomeId == data["Id"].ToString()) + { + Residential residential = new Residential(); + + if (Convert.ToBoolean(data["IsOthreShare"].ToString())) + { + //鍒嗕韩鑰匢D + residential.Id = data["Id"].ToString(); + //鏄惁鏄垎浜处鍙穂true(鏄垎浜�);false;(涓嶆槸鍒嗕韩)]; + residential.IsOthreShare = Convert.ToBoolean(data["IsOthreShare"].ToString()); + //鍒嗕韩鑰呬綇瀹匢D + residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); + residential.IsOtherAccountCtrl = true; + //residential.doorlockmac = doorlockMac; + //list = ReadToken(residential); + } + else + { + residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/DoorLock/GetDoorLockPager"; + residential.Token = Config.Instance.Token; + residential.Id = Config.Instance.HomeId; + residential.IsOtherAccountCtrl = false; + //residential.doorlockmac = doorlockMac; + //list = ReadDoorLock(residential); + + } + } + + } + } + + public async System.Threading.Tasks.Task<string> aa(int value, string url, Residential residential = null) + { + NameValueCollection postValues = new NameValueCollection(); + if (value == 1) + { + + } + else if (value == 2) + { + postValues.Add("RequestVersion", CommonPage.RequestVersion); + postValues.Add("LoginAccessToken", Config.Instance.Token); + postValues.Add("MainAccountId", residential.MainUserDistributedMark); + postValues.Add("SharedHid", residential.Id); + } + else + { + postValues.Add("RequestVersion", CommonPage.RequestVersion); + postValues.Add("ReqDto.LoginAccessToken", Config.Instance.Token); + + } + return await WebClientAsync(postValues, url); + } + + public async System.Threading.Tasks.Task<string> aaa(NameValueCollection postValues, string url) + { + var str = await aa(0, "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager"); + var jObject = JObject.Parse(str); + if (jObject == null || jObject["StateCode"].ToString() != "Success") + { + return null; + } + var pageData = jObject["ResponseData"]["PageData"].ToString(); + var datalist = JArray.Parse(pageData); + for (int i = 0; i < datalist.Count; i++) + { + var data = JObject.Parse(datalist[i].ToString()); + if (Config.Instance.HomeId == data["Id"].ToString()) + { + Residential residential = new Residential(); + if (Convert.ToBoolean(data["IsOthreShare"].ToString())) + { + //鍒嗕韩鑰匢D + residential.Id = data["Id"].ToString(); + //鏄惁鏄垎浜处鍙穂true(鏄垎浜�);false;(涓嶆槸鍒嗕韩)]; + residential.IsOthreShare = Convert.ToBoolean(data["IsOthreShare"].ToString()); + //鍒嗕韩鑰呬綇瀹匢D + residential.MainUserDistributedMark = data["MainUserDistributedMark"].ToString(); + residential.IsOtherAccountCtrl = true; + //residential.doorlockmac = doorlockMac; + //list = ReadToken(residential); + + var str = await WebClientAsync(residential, postValues, url); + } + else + { + residential.Url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/DoorLock/GetDoorLockPager"; + residential.Token = Config.Instance.Token; + residential.Id = Config.Instance.HomeId; + residential.IsOtherAccountCtrl = false; + //residential.doorlockmac = doorlockMac; + var str = await WebClientAsync(postValues, url); + + } + } + + } + } + + /// <summary> + /// 璇锋眰鏈嶅姟鍣ㄧ殑鏂规硶 + /// </summary> + /// <param name="postValues">post鍙傛暟</param> + /// <param name="url"></param> + /// <returns></returns> + public async System.Threading.Tasks.Task<string> WebClientAsync(NameValueCollection postValues, string url) + { + + System.Net.WebClient webClient = new System.Net.WebClient(); + byte[] responseArray = webClient.UploadValues(url, postValues); + return System.Text.Encoding.UTF8.GetString(responseArray); + } + */ } } -- Gitblit v1.8.0