陈嘉乐
2021-03-12 bd2c6c39668f2495d14440ae2d6bb7a7856e9d2f
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -28,12 +28,12 @@
        /// <param name="list">当前存在名称列表</param>
        /// <param name="currName">当前名称</param>
        /// <param name="action">回调函数</param>
        public void EditControlName(int tipText ,List<string> list, string currName, Action<string, Dialog> action,Action actionCancel, bool tag=false)
        public void EditControlName(int tipText, List<string> list, string currName, Action<string, Dialog> action, Action actionCancel, bool tag = false)
        {
            new View.TipView().InputBox(tipText, currName, StringId.nameNull, StringId.NameAlreadyExists, list, (text, view
                ) =>
            {
                action(text,view);
                action(text, view);
            }, () => { actionCancel(); }, tag);
        }
        /// <summary>
@@ -190,8 +190,6 @@
                            }
                        }
                        //GetControlList(frame, action);
                       // GetControlList();
                    }
                }
@@ -200,20 +198,22 @@
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                       // action();
                        try
                        {
                            if (Pir.pirDeviceList.Count != 0)
                            {
                                GetControlList1(frame, action);
                                var list = Pir.pirDeviceList;
                                GetControlList(() =>
                                {
                                    loading.Hide();
                                    action();
                                });
                            }
                            else
                            {
                                //Method method = new Method();
                                //method.ErrorShow(responsePackNew);
                                loading.Hide();
                                Method method = new Method();
                                method.ErrorShow(null,"读取红外宝列表失败");
                            }
                        }
                        catch { }
@@ -228,60 +228,10 @@
        /// <summary>
        /// 获取遥控器列表
        /// </summary>
        public static void GetControlList()
        {
            new System.Threading.Thread(() =>
            {
                for (int i = 0; i < Pir.pirDeviceList.Count; i++)
                {
                    var pirDevice = Pir.pirDeviceList[i];
                    try
                    {
                        var responsePackNew = PirSend.ControlList(pirDevice);
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                            var jArray = JArray.Parse(responsePackNew.Data.ToString());
                            for (int a = 0; a < jArray.Count; a++)
                            {
                                var jay = jArray[a];
                                //数据返序列化为Logic对象
                                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);
                                    }
                                }
                            }
                        }
                    }
                    catch { }
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 获取遥控器列表
        /// </summary>
        /// <param name="frame">log图标加载界面</param>
        /// <param name="action">回调函数</param>
        public static void GetControlList1(FrameLayout frame, Action action)
        public static void GetControlList(Action action)
        {
            //加载log
            Loading loading = new Loading();
            frame.AddChidren(loading);
            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
@@ -291,52 +241,42 @@
                        var pirDevice = Pir.pirDeviceList[i];
                        try
                        {
                            responsePackNew = PirSend.ControlList(pirDevice);
                            var responsePackNew = PirSend.ControlList(pirDevice);
                            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                            {
                                var jArray = JArray.Parse(responsePackNew.Data.ToString());
                                for (int a = 0; a < jArray.Count; a++)
                                {
                                    var jay = jArray[a];
                                    //数据返序列化为Logic对象
                                    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);
                                        }
                                    }
                                }
                            }
                        }
                        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];
                                            //数据返序列化为Logic对象
                                            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);
                                                }
                                            }
                                        }
                                    }
                                }
                                catch { }
                            });
                        }
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        action();
                    });
                }
            })
            { IsBackground = true }.Start();
@@ -379,6 +319,22 @@
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 发送命令线程
        /// </summary>
        /// <param name="control">发送数据对象</param>
        /// <param name="action">回调函数</param>
        /// <param name="str">判断字符</param>
        /// <param name="frame">log父控件</param>
        /// <param name="dialog">log父控件</param>
        public void ThreadSend(Control control, Action<HDL_ON.DAL.Server.ResponsePackNew> action, string str, FrameLayout frame, Dialog dialog)
        {
        }
        /// <summary>
        /// MQTT主题推送下来的数据
        /// </summary>
@@ -426,11 +382,14 @@
        /// </summary>
        /// <param name="responsePackNew"></param>
        /// <param name="str"></param>
        public void ErrorShow(ResponsePackNew responsePackNew, string str = "")
        public void ErrorShow(ResponsePackNew responsePackNew=null, string str = "")
        {
            if (str == "删除遥控器")
            {
                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.delFail));
            } else if (str == "读取红外宝列表失败") {
                new Intelligence.Automation.LogicView.TipPopView().FlashingBox("读取红外宝列表失败");
            }
            else
            {