From 2bf5ec775cb57d8015bee58c745a1e48081ff1b1 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 15 十月 2019 11:06:05 +0800
Subject: [PATCH] 首次合并了全部的代码

---
 ZigbeeApp/Shared/Phone/Device/Logic/Send.cs |  275 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 264 insertions(+), 11 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
index 3cb527e..1915625 100755
--- a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
@@ -3,11 +3,13 @@
 using Newtonsoft.Json.Linq;
 using ZigBee.Device;
 using ZigBee.Common;
+using Shared.Common;
 
 namespace Shared.Phone.Device.Logic
 {
     public class Send
     {
+
         /// <summary>
         /// 鑾峰彇LogicId鐨勬柟娉�
         /// </summary>
@@ -97,8 +99,9 @@
                         logic.LogicName = Logicifon["LogicName"]?.ToString();
 
                         logic.Relationship = int.Parse(Logicifon["Relationship"]?.ToString());
-                        logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.TimeAttributeObj>(Logicifon["TimeAttribute"].ToString());
+                        logic.TimeAttribute = Newtonsoft.Json.JsonConvert.DeserializeObject<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());
                         var listactions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(Logicifon["Actions"].ToString());
                         if (listactions != null)
                         {
@@ -133,7 +136,7 @@
 
                         }
 
-                    };
+                    }
                 };
                 var mainGateWay = ZbGateway.MainGateWay;
                 if (mainGateWay == null)
@@ -251,10 +254,6 @@
 
                 try
                 {
-                    //var bytes = new byte[64];
-                    //var LogicNameBytes = System.Text.Encoding.UTF8.GetBytes(logic.LogicName);
-                    //Array.Copy(LogicNameBytes, 0, bytes, 0, 64 < LogicNameBytes.Length ? 64 : LogicNameBytes.Length);
-                    //logic.LogicName = System.Text.Encoding.UTF8.GetString(bytes);
 
                     var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2000 } };
                     var selectMonthList = new JArray { };
@@ -310,8 +309,13 @@
                                     ["AttriButeId"] = int.Parse(dictionary["AttriButeId"]),
                                     ["AttriButeData1"] = int.Parse(dictionary["AttriButeData1"]),
                                     ["AttriButeData2"] = int.Parse(dictionary["AttriButeData2"]),
-                                    ["Range"] = int.Parse(dictionary["Range"]),
+                                    ["Range"] = int.Parse(dictionary["Range"])
                                 };
+                                if (dictionary.ContainsKey("IgnoreTime"))
+                                {
+                                    dInfo.Add("IgnoreTime", int.Parse(dictionary["IgnoreTime"]));
+                                }
+
                                 conditions.Add(dInfo);
                                 break;
                             case 2:
@@ -434,16 +438,51 @@
                                 };
                                 actions.Add(cdInfo);
                                 break;
+                            case 7:
+                                var timeInfo = new JObject
+                                {
+                                    ["LinkType"] = int.Parse(dictionary["LinkType"].ToString()),
+                                    ["DelayTime"] = int.Parse(dictionary["DelayTime"].ToString()),
+                                };
+                                actions.Add(timeInfo);
+                                break;
                         }
+                    }
+                    var accounts = new JArray();
+                    foreach (var dictionary in logic.Accounts) {
+                        var Type = int.Parse(dictionary["Type"]);
+                        switch (Type)
+                        {
+                            case 1: {
+                                    ///
+                                } break;
+                            case 7:
+                                {
+                                    var location = new JObject
+                                    {
+                                        ["Type"] = int.Parse(dictionary["Type"]),
+                                        ["Account"] = dictionary["Account"],
+                                        ["Longitude"] = int.Parse(dictionary["Longitude"]),
+                                        ["Latitude"] = int.Parse(dictionary["Latitude"]),
+                                        ["Radius"] = int.Parse(dictionary["Radius"]),
+
+                                    };
+                                    accounts.Add(location);
+                                }
+                                break;
+                        }
+
                     }
                     var data = new JObject{
                         { "LogicId",logic.LogicId},
                         { "IsEnable", logic.IsEnable} ,
                         { "LogicName", logic.LogicName},
                         { "Relationship",logic.Relationship} ,
+                        { "LogicCustomPushText",logic.LogicCustomPushText} ,
                         { "TimeAttribute", timeAttribute} ,
                         { "Conditions", conditions },
                         { "Actions", actions },
+                        { "Accounts", accounts },
                     };
                     jObject.Add("Data", data);
                     ZbGateway.MainGateWay?.Send("Logic/AddLogic", jObject.ToString());
@@ -503,8 +542,9 @@
                 jObject.Add("Data", date);
                 date.Add("LogicId", logic.LogicId);
                 date.Add("IsEnable", logic.IsEnable);
-                //date.Add("LogicName", logic.LogicName);
-                //date.Add("Relationship", logic.Relationship);
+                date.Add("LogicName", logic.LogicName);
+                date.Add("Relationship", logic.Relationship);
+                date.Add("LogicCustomPushText", logic.LogicCustomPushText);
                 mainGateWay?.Send("Logic/ReviseAttribute", jObject.ToString());
                 //await System.Threading.Tasks.Task.Run(async () =>
                 //{
@@ -635,14 +675,227 @@
             });
         }
         // <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 room = new Common.Room();
             btnregionname.Text = room.GetRoomNameByDevice(device);
         }
+
+        public static List<Common.Room> GetRoomList(string floorId)
+        {
+            return Common.Room.Lists.FindAll((obj) => obj.FloorId == floorId);
+
+        }
+
+        #region  ----鑾峰彇闂ㄩ攣
+        public static List<DoorLock> ReadDoorLockIfon(string doorlockMac)
+        {
+            List<DoorLock> list = new List<DoorLock>();
+            string url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetHomePager";
+            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("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()))
+                           {
+                                //鍒嗕韩鑰匢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/App/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)
+            {
+                if (list.Count != 0)
+                {
+                    break;
+                }
+            }
+            return list;
+
+        }
+
+        public static List<DoorLock> ReadToken(Residential residential)
+        {
+            List<DoorLock> list = new List<DoorLock>();
+            string url = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/App/GetSharedHomeApiControl";
+            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", Config.Instance.Token);
+            postValues.Add("MainAccountId", residential.MainUserDistributedMark);
+            postValues.Add("SharedHid", residential.Id);
+            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 RequestBaseUrl = jObject["ResponseData"]["RequestBaseUrl"].ToString();
+                    var RequestToken = jObject["ResponseData"]["RequestToken"].ToString();
+                    Residential lockifon = new Residential();
+                    lockifon.Url = RequestBaseUrl + "/App/GetDoorLockPager";
+                    lockifon.Token = RequestToken;
+                    lockifon.Id = Config.Instance.HomeId;
+                    lockifon.IsOtherAccountCtrl = true;
+                    lockifon.doorlockmac = residential.doorlockmac;
+                    list = ReadDoorLock(lockifon);
+
+                }
+                catch { }
+            });
+            var datetime = DateTime.Now;
+            while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000)
+            {
+                if (list.Count != 0)
+                {
+                    break;
+                }
+            }
+            return list;
+        }
+
+        public static List<DoorLock> ReadDoorLock(Residential lockifon)
+        {
+            List<DoorLock> list = new List<DoorLock>();
+            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);
+            postValues.Add("HomeId", lockifon.Id);
+            postValues.Add("DoorLockId", lockifon.doorlockmac);//闂ㄩ攣Mac19091
+            postValues.Add("IsOtherAccountCtrl", lockifon.IsOtherAccountCtrl.ToString());
+            System.Threading.Tasks.Task.Run(() =>
+            {
+                try
+                {
+
+                    byte[] responseArray = webClient.UploadValues(lockifon.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());
+                        DoorLock doorLock = new DoorLock();
+                        doorLock.DoorLockLocalUserId = data["DoorLockLocalUserId"].ToString();
+                        doorLock.OpenLockMode = int.Parse(data["OpenLockMode"].ToString());
+                        doorLock.CloudAccountId = data["CloudAccountId"].ToString();
+                        list.Add(doorLock);
+                    }
+
+                }
+                catch
+                {
+
+                }
+
+            });
+            var datetime = DateTime.Now;
+            while ((DateTime.Now - datetime).TotalMilliseconds < 3 * 1000)
+            {
+                if (list.Count != 0)
+                {
+                    break;
+                }
+            }
+            return list;
+        }
+
+        public class Residential
+        {
+            public string Id = string.Empty;
+            public bool IsOthreShare;
+            public string MainUserDistributedMark = string.Empty;
+            public string Url = string.Empty;
+            public string Token = string.Empty;
+            public bool IsOtherAccountCtrl;
+            public string doorlockmac;
+        }
+
+        public class DoorLock
+        {
+            public string DoorLockLocalUserId = string.Empty;
+            public int OpenLockMode;
+            public string CloudAccountId = string.Empty;
+            /// <summary>
+            /// 韬唤+瑙﹀彂婧�(0鎸夐敭/3鍗�/15鎸囩汗)
+            /// </summary>
+            public string UserIdMode
+            {
+                get
+                {
+                    return DoorLockLocalUserId + "_" + OpenLockMode.ToString();
+                }
+            }
+        }
+
+        public class MembershipIfon
+        {
+            public string MembershipId = string.Empty;
+            public List<string> UserIdMode=new List<string>();
+            public string MembershipName = string.Empty;
+        }
+
+        public static List<MembershipIfon> UserList = new List<MembershipIfon>();
+
+        
+        #endregion
     }
 }

--
Gitblit v1.8.0