wxr
2021-03-16 9b44e30275621a48335fbea7b32b5065a2859c9c
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -84,7 +84,8 @@
                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                    {
                        string sid = responsePackNew.Data.ToString();
                        mqttdate = MqttDate(sid);
                        controldata = "";
                        mqttdate = MqttDate("遥控器", sid);
                        if (mqttdate != null)
                        {
                            control.sid = sid;
@@ -180,10 +181,24 @@
                                var pirJosn = Newtonsoft.Json.JsonConvert.DeserializeObject<Pir>(str);
                                if (pirJosn != null)
                                {
                                    if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
/* 项目“HDL-ON_iOS”的未合并的更改
在此之前:
                                    if (null == Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
在此之后:
                                    if (null == list.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
*/
                                    if (null == PirDevice.Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
                                    {
                                        Pir.pirDeviceList.Add(pirJosn);
/* 项目“HDL-ON_iOS”的未合并的更改
在此之前:
                                        Pir.pirDeviceList.Add(pirJosn);
在此之后:
                                        list.pirDeviceList.Add(pirJosn);
*/
                                        PirDevice.Pir.pirDeviceList.Add(pirJosn);
                                    }
                                }
@@ -319,6 +334,7 @@
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 发送命令线程
        /// </summary>
@@ -326,47 +342,159 @@
        /// <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)
        public void ThreadSend(Control control, Action<ResponsePackNew> action, string str, FrameLayout frame)
        {
            //加载log
            Loading loading = new Loading();
            frame.AddChidren(loading);
            loading.Start();
            ResponsePackNew responsePackNew = null;
            new System.Threading.Thread(() =>
            {
                try
                {
                    if (str == "删除")
                    {
                        responsePackNew = PirSend.DeleteDevice(control.deviceId);
                    }
                    else if (str == "修改名称")
                    {
                        responsePackNew = PirSend.DeviceRename(control.deviceId, control.name);
                    }
                    else if (str == "删除按键") {
                       // responsePackNew = PirSend.CodeRemove(control.deviceId, control.name);
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                            action(responsePackNew);
                        }
                        else
                        {
                            Method method = new Method();
                            method.ErrorShow(responsePackNew, "");
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// MQTT主题推送下来的数据
        /// 发送命令线程
        /// </summary>
        public static string mqttdata = "";
        /// <param name="control">发送数据对象</param>
        /// <param name="action">回调函数</param>
        /// <param name="str">判断字符</param>
        /// <param name="dialog">log父控件</param>
        public void ThreadSend(Control control, Action<ResponsePackNew> action, string str,Dialog dialog)
        {
            //加载log
            Loading loading = new Loading();
            dialog.AddChidren(loading);
            ResponsePackNew responsePackNew = null;
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    if (str == "删除")
                    {
                        responsePackNew = PirSend.DeleteDevice(control.deviceId);
                    }
                    else if (str == "修改名称")
                    {
                        responsePackNew = PirSend.DeviceRename(control.deviceId, control.name);
                    }
                    else if (str == "删除按键")
                    {
                       // responsePackNew = PirSend.CodeRemove(control.deviceId, control.name);
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                            action(responsePackNew);
                        }
                        else
                        {
                            Method method = new Method();
                            method.ErrorShow(responsePackNew, "");
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// MQTT主题推送下来的遥控器数据
        /// </summary>
        public static string controldata = "";
        /// <summary>
        /// MQTT主题推送下来按键的数据
        /// </summary>
        public static string buttondata = "";
        /// <summary>
        /// 判断这个主题是否是添加遥控器主题
        /// </summary>
        /// <param name="text">表示不同主题数据</param>
        /// <param name="sid">唯一标识</param>
        /// <param name="timeValue">等待时间值</param>
        /// <returns></returns>
        public Cloud MqttDate(string sid, int timeValue = 10)
        public Cloud MqttDate(string text, string sid, int timeValue = 10)
        {
            Cloud cloud = null;
            var dateTime = DateTime.Now;
            while ((DateTime.Now - dateTime).TotalMilliseconds < timeValue * 1000)
            {
                if (!string.IsNullOrEmpty(mqttdata))
                string str = "";
                if (text == "遥控器")
                {
                    str = controldata;
                }
                else if (text == "按键")
                {
                    str = buttondata;
                }
                if (!string.IsNullOrEmpty(controldata))
                {
                    try
                    {
                        var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(mqttdata);
                        var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(str);
                        for (int i = 0; i < cloudjson.objects.Count; i++)
                        {
                            var objects = cloudjson.objects[i];
                            if (sid == objects.sid)
                            {
                                cloud = cloudjson;
                                mqttdata = "";
                                break;
                            }
                        }
                        if (cloud!=null)
                        if (cloud != null)
                        {
                            break;
                        }
@@ -381,44 +509,63 @@
        /// 错误码提示
        /// </summary>
        /// <param name="responsePackNew"></param>
        /// <param name="str"></param>
        public void ErrorShow(ResponsePackNew responsePackNew=null, string str = "")
        /// <param name="text">自定义错误文本</param>
        /// <param name="popValue">弹框类型(1=闪烁弹框)</param>
        public void ErrorShow(ResponsePackNew responsePackNew, string text, int popValue = 1)
        {
            if (str == "删除遥控器")
            string str = "";
            if (text == "删除遥控器")
            {
                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.delFail));
            } else if (str == "读取红外宝列表失败") {
                new Intelligence.Automation.LogicView.TipPopView().FlashingBox("读取红外宝列表失败");
                str = Language.StringByID(StringId.delFail);
            }
            else if (text == "读取红外宝列表失败")
            {
                str = "读取红外宝列表失败"; //Language.StringByID(StringId.delFail);
            }
            else
            {
                if (responsePackNew != null)
                {
                    switch (responsePackNew.Code)
                    {
                        case "14005":
                            {
                                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
                                str = Language.StringByID(StringId.gatewayNotOnline);
                            }
                            break;
                        case "10807":
                            {
                                //红外宝下遥控器超过最大(10个)数量限制
                                new Intelligence.Automation.LogicView.TipPopView().FlashingBox("红外宝下遥控器超过最大(10个)数量限制");
                                str = "红外宝下遥控器超过最大(10个)数量限制";// Language.StringByID(StringId.gatewayNotOnline);
                            }
                            break;
                        case "2":
                            {
                                str = "系统维护中~请稍后再试~";
                            }
                            break;
                        default:
                            {
                                new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
                                str ="获取数据失败" ;// Language.StringByID(StringId.saveFail);
                            }
                            break;
                    }
                }
            }
            switch (popValue)
            {
                case 1:
                    {
                        new Intelligence.Automation.LogicView.TipPopView().FlashingBox(str);
                    }
                    break;
                case 2: { } break;
                case 3: { } break;
            }
        }