From 8e5ba5665861b29a4b8da0335c81d620aa891862 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期一, 08 三月 2021 09:23:54 +0800
Subject: [PATCH] Merge branch 'WJC' into temp-wxr

---
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs |  296 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 259 insertions(+), 37 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index 0c7d14f..0bc89c6 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -1,6 +1,8 @@
 锘縰sing System;
 using HDL_ON.DAL.Server;
 using Shared;
+using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
 
 namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
 {
@@ -9,37 +11,39 @@
         /// <summary>
         /// 娣诲姞閬ユ帶鍣ㄧ殑鏂规硶
         /// </summary>
-        public void AddControl()
+        public void AddControl(FrameLayout frameLayout, Action<Control> action)
         {
             View.TipView tipView = new View.TipView();
-            tipView.InputBox("", (s, dialog) =>
-            {
-                ///娓呴櫎涔嬪墠鍒楄〃鏁版嵁
-                Pir.BuottonList.Clear();
-                if (!string.IsNullOrEmpty(s))
-                {
-                    Control control = new Control();
-                    control.name = s;
-                    control.type = "learn";
-
-                    ThreadAddControl(control,dialog);
+            tipView.InputBox(frameLayout, "", (name, frame) =>
+             {
+                 ///娓呴櫎涔嬪墠鍒楄〃鏁版嵁
+                 Pir.BuottonList.Clear();
+                 if (!string.IsNullOrEmpty(name))
+                 {
+                     Control control = new Control();
+                     control.name = name;
+                     control.type = "learn";
+                     control.spk = "ir.learn";
+                     control.deviceId = Pir.currPir.deviceId;
+                     ThreadAddControl(control, frame, action);
 
 
 
-                }
-            },false);
+                 }
+             }, false);
 
         }
         /// <summary>
         /// 鍙戦�侀仴鎺у櫒鍛戒护鏂规硶
         /// </summary>
         /// <param name="control"></param>
-        /// <param name="dialog"></param>
-        public void ThreadAddControl(Control control, Dialog dialog) {
+        /// <param name="frame"></param>
+        public void ThreadAddControl(Control control, FrameLayout frame, Action<Control> action)
+        {
 
             DAL.Server.ResponsePackNew responsePackNew = null;
             Loading loading = new Loading();
-            dialog.AddChidren(loading);
+            frame.AddChidren(loading);
             loading.Start();
             new System.Threading.Thread(() =>
             {
@@ -53,37 +57,235 @@
                     Application.RunOnMainThread(() =>
                     {
                         loading.Hide();
-                        //if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
-                        //{
-                            ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
-                            dialog.Close();//娣诲姞鎴愬姛鍏抽棴寮圭獥
-                            AddButton addButton = new AddButton();
-                            MainPage.BasePageView.AddChidren(addButton);
-                            addButton.Show(control);
-                            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                        {
+                            bool bool_if = false;
+                            string sid = responsePackNew.Data.ToString();
+                            var mqttdate = MqttDate();
+                            for (int i = 0; i < mqttdate.objects.Count; i++) {
+                                var objects = mqttdate.objects[i];
+                                if (sid == objects.sid) {
+                                    bool_if = true;
+                                    break;
+                                }
+                            }
+                            if (bool_if)
+                            {
+                                control.deviceId = mqttdate.id;
+                                ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
+                                frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
+                                action(control);
+                            }
+                            else
+                            {
+                                //鐩戝惉Mqtt鎺ㄩ�佷笅鏉ョ姸鎬佺爜鍋氭彁绀�
+                                View.FailView failView = new View.FailView();
+                                failView.ShouError((view) =>
+                                {
+                                    view.Close();
+                                    ThreadAddControl(control, frame, action);
+                                });
+                            }
 
-                            //鐩戝惉Mqtt鎺ㄩ�佷笅鏉ョ姸鎬佺爜鍋氭彁绀�
-                            //View.FailView failView = new View.FailView();
-                            //failView.ShouError((view) => {
-                            //    view.Close();
-                            //    ThreadAddControl(control, dialog);
-                            //});
-                        //}
-                        //else
-                        //{
-                        //    ErrorShow(responsePackNew);
-                        //}
+
+                        }
+                        else
+                        {
+                            ErrorShow(responsePackNew);
+                        }
                     });
                 }
             })
             { IsBackground = true }.Start();
 
         }
+
+        /// <summary>
+        /// 鑾峰彇绾㈠璁惧鍒楄〃
+        /// </summary>
+        public static void GetPirDeviceList(FrameLayout frame, Action action)
+        {
+            //娓呴櫎涔嬪墠鍒楄〃;
+            Pir.pirDeviceList.Clear();
+            //鍔犺浇log
+            Loading loading = new Loading();
+            frame.AddChidren(loading);
+            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+            loading.Start();
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    responsePackNew = PirSend.GetDeviceList("ir.module");
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        try
+                        {
+                            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                            {
+                                var jobject = Newtonsoft.Json.Linq.JObject.Parse(responsePackNew.Data.ToString());
+                                string list = jobject["list"].ToString();
+
+                                var jArray = Newtonsoft.Json.Linq.JArray.Parse(list);
+                                for (int a = 0; a < jArray.Count; a++)
+                                {
+                                    var jay = jArray[a];
+                                    string spk = jay["spk"].ToString();
+                                    if (spk == "ir.module")
+                                    {
+                                        //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
+                                        var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
+                                        var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
+                                        if (pirJosn != null)
+                                        {
+                                            if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
+                                            {
+
+                                                Pir.pirDeviceList.Add(pirJosn);
+
+                                            }
+                                        }
+                                    }
+
+                                }
+                                GetControlList(frame, action);
+
+                            }
+                            else
+                            {
+                                Method method = new Method();
+                                method.ErrorShow(responsePackNew);
+                            }
+                        }
+                        catch { }
+
+                    });
+                }
+
+            })
+            { IsBackground = true }.Start();
+
+        }
+        /// <summary>
+        /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
+        /// </summary>
+        public static void GetControlList(FrameLayout frame, Action action)
+        {
+            //鍔犺浇log
+            Loading loading = new Loading();
+            frame.AddChidren(loading);
+            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+            loading.Start();
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    for (int i = 0; i < Pir.pirDeviceList.Count; i++)
+                    {
+                        var pirDevice = Pir.pirDeviceList[i];
+                        try
+                        {
+                            responsePackNew = PirSend.ControlList(pirDevice);
+
+                        }
+                        catch { }
+                        finally
+                        {
+                            Application.RunOnMainThread(() =>
+                            {
+                                try
+                                {
+                                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                                    {
+                                        var jArray = Newtonsoft.Json.Linq.JArray.Parse(responsePackNew.Data.ToString());
+                                        for (int a = 0; a < jArray.Count; a++)
+                                        {
+                                            var jay = jArray[a];
+                                            //鏁版嵁杩斿簭鍒楀寲涓篖ogic瀵硅薄
+                                            var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
+                                            var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(str);
+                                            if (pirJosn != null)
+                                            {
+                                                if (null == pirDevice.FunctioList.Find((c) => c.sid == pirJosn.sid))
+                                                {
+                                                    pirDevice.FunctioList.Add(pirJosn);
+                                                }
+                                            }
+
+                                        }
+                                    }
+                                    else
+                                    {
+                                        //Method method = new Method();
+                                        //method.ErrorShow(responsePackNew);
+                                    }
+                                }
+                                catch { }
+
+                            });
+                        }
+                    }
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        action();
+                    });
+                }
+            })
+            { IsBackground = true }.Start();
+
+        }
+
+        /// <summary>
+        /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁(閬ユ帶鍣ㄦ坊鍔�)
+        /// </summary>
+        public static string addcontronsid = "";
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns></returns>
+        public Cloud MqttDate()
+        {
+            var dateTime = DateTime.Now;
+            while ((DateTime.Now - dateTime).TotalMilliseconds < 5 * 1000)
+            {
+                if (!string.IsNullOrEmpty(addcontronsid))
+                {
+                    break;
+                }
+
+            }
+            return PushData();
+        }
+
+        public Cloud PushData()
+        {
+            Cloud cloud = new Cloud();
+            if (addcontronsid != "")
+            {
+                //var date = Newtonsoft.Json.JsonConvert.SerializeObject(addcontronsid);
+                cloud = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontronsid);
+
+            }
+            return cloud;
+        }
+
+
+
         /// <summary>
         /// 閿欒鐮佹彁绀�
         /// </summary>
         /// <param name="responsePackNew"></param>
-        public  void ErrorShow(ResponsePackNew responsePackNew)
+        public void ErrorShow(ResponsePackNew responsePackNew)
         {
 
             if (responsePackNew != null && responsePackNew.Code == "14005")
@@ -97,5 +299,25 @@
 
             }
         }
+
     }
+    [Serializable]
+    public class Cloud
+    {
+        /// <summary>
+        /// 璁惧id
+        /// </summary>
+        public string id = string.Empty;
+        public List<Objects> objects = new List<Objects>();
+        public string time_stamp = string.Empty;
+
+
+    }
+    [Serializable]
+    public class Objects
+    {
+        public string sid = string.Empty;
+        public string spk = string.Empty;
+    }
+
 }

--
Gitblit v1.8.0