From 1f5636d69332170ea3a41c76c9519f6ff6f0a8d9 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期一, 28 十月 2019 15:40:30 +0800
Subject: [PATCH] 合并了代码

---
 ZigbeeApp/Shared/Phone/Device/Logic/Send.cs |  543 +++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 479 insertions(+), 64 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
old mode 100644
new mode 100755
index 67f0ddd..a4e865e
--- a/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
+++ b/ZigbeeApp/Shared/Phone/Device/Logic/Send.cs
@@ -3,16 +3,18 @@
 using Newtonsoft.Json.Linq;
 using ZigBee.Device;
 using ZigBee.Common;
+using Shared.Common;
 
 namespace Shared.Phone.Device.Logic
 {
     public class Send
     {
+
         /// <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 () =>
             {
@@ -30,7 +32,8 @@
                     {
 
                         var list = jObjectdata["Data"]["LogicList"];
-                        if(list==null){
+                        if (list == null)
+                        {
                             return;
                         }
                         foreach (var listIfon in list)
@@ -50,7 +53,9 @@
                 mainGateWay.GwResDataAction += action;
 
                 var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 2004 } };
-                mainGateWay?.Send("Logic/GetLogicList",jObject.ToString());
+                var jObjectdata1 = new JObject { { "LogicType", LogicType } };
+                jObject.Add("Data", jObjectdata1);
+                mainGateWay?.Send("Logic/GetLogicList", jObject.ToString());
                 //await System.Threading.Tasks.Task.Run(async () =>
                 //{
                 var dateTime = DateTime.Now;
@@ -71,14 +76,14 @@
         /// 鑾峰彇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 () =>
             {
                 Common.Logic logic = null;
                 Action<string, string> action = (topic, data) =>
                 {
-                   
+
                     var gatewayID = topic.Split('/')[0];
                     var jObjectdata = JObject.Parse(data);
                     if (jObjectdata == null)
@@ -88,51 +93,52 @@
 
                     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<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)
+                        {
+                            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;
                 if (mainGateWay == null)
@@ -145,7 +151,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());
@@ -219,7 +226,7 @@
                 Common.Logic Logicifon = null;
                 Action<string, string> action = (topic, datastring) =>
                 {
-                   
+
                     var gatewayID = topic.Split('/')[0];
                     var jObjectdata = JObject.Parse(datastring);
                     if (jObjectdata == null)
@@ -230,8 +237,8 @@
                     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)
@@ -250,10 +257,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 { };
@@ -281,7 +284,7 @@
                                 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"]),
@@ -309,8 +312,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:
@@ -397,7 +405,7 @@
                                     ["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,
 
                                 };
@@ -433,16 +441,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());
@@ -454,7 +497,7 @@
 
 
                 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)
@@ -467,26 +510,398 @@
             });
         }
         /// <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);
+                date.Add("LogicCustomPushText", logic.LogicCustomPushText);
+                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,int LogicType)
+        {
+            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.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());
+                        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 } };
+                    var jObjectdata = new JObject { { "LogicType", LogicType } };
+                    jObject.Add("Data", jObjectdata);
+                    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 = 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/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)
             {
-                btnregionname.Text = Language.StringByID(R.MyInternationalizationString.customroom);
-            }
-            else
-            {
-                foreach (var roomname in roomlistname)
+                if (list.Count != 0)
                 {
-                    btnregionname.Text += roomname + ",";
+                    break;
                 }
-                btnregionname.Text = btnregionname.Text.TrimEnd(',');
+            }
+            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