陈嘉乐
2021-03-09 83df0ebfbd306d0fb5a51a21a7ef2271c0c507ec
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -16,14 +16,20 @@
            View.TipView tipView = new View.TipView();
            tipView.InputBox(frameLayout, "", (name, frame) =>
             {
                 ///清除之前列表数据
                 Pir.BuottonList.Clear();
                 Control control = new Control();
                 control.name = name;
                 control.type = "learn";
                 control.spk = "ir.learn";
                 control.deviceId = Pir.currPir.deviceId;
                 ThreadAddControl(control, frame, action);
                 if (Pir.currPir != null && Pir.currPir.FunctioList.Count < 10)
                 {
                     Control control = new Control();
                     control.name = name;
                     control.type = "learn";
                     control.spk = "ir.learn";
                     control.deviceId = Pir.currPir.deviceId;
                     ThreadAddControl(control, frame, action);
                 }
                 else
                 {
                     View.TipView tt = new View.TipView();
                     tt.TipBox(StringId.tip, StringId.bunengchaoguo10);
                 }
             }, false);
        }
@@ -54,13 +60,20 @@
                        {
                            string sid = responsePackNew.Data.ToString();
                            var mqttdate = MqttDate(sid);
                            if (mqttdate.id!="")
                            if (mqttdate != null)
                            {
                                ///这里:监听MTTP推送下来主题,才知道是否添加成功
                                frame.RemoveFromParent();//添加成功关闭弹窗
                                control.deviceId = mqttdate.id;
                                control.sid = sid;
                                action(control);
                                //休眠500毫秒,为等待云端创建deviceid;
                                System.Threading.Thread.Sleep(500);
                                GetControl(frame, control,(device)=> {
                                    if (device != null)
                                    {
                                        control.deviceId = device.deviceId;
                                        frame.RemoveFromParent();//添加成功关闭弹窗
                                        action(control);
                                    }
                                });
                            }
                            else
                            {
@@ -232,27 +245,85 @@
        }
        /// <summary>
        /// 获取遥控器详细
        /// </summary>
        public void GetControl(FrameLayout frame, Control control, Action<Entity.Function> action)
        {
            Entity.Function function = null;
            //加载log
            Loading loading = new Loading();
            frame.AddChidren(loading);
            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    responsePackNew = PirSend.GetinfoBySid(control);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        try
                        {
                            if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                            {
                                var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data.ToString());
                                function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(str);
                            }
                            else
                            {
                                Method method = new Method();
                                method.ErrorShow(responsePackNew);
                            }
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                loading.Hide();
                                action(function);
                            });
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// MQTT主题推送下来的数据(遥控器添加)
        /// </summary>
        public static string addcontronsid = "";
        public static string addcontrondata = "";
        /// <summary>
        /// MQTT主题推送下来的数据(学习按键)
        /// </summary>
        public static string studybtndata = "";
        /// <summary>
        /// 判断这个主题是否是添加遥控器主题
        /// </summary>
        /// <returns></returns>
        public Cloud MqttDate(string sid)
        public Cloud MqttDate(string sid,int timeValue=10)
        {
            Cloud cloud = new Cloud();
            Cloud cloud=null;
            var dateTime = DateTime.Now;
            while ((DateTime.Now - dateTime).TotalMilliseconds < 10 * 1000)
            while ((DateTime.Now - dateTime).TotalMilliseconds < timeValue * 1000)
            {
                if (!string.IsNullOrEmpty(addcontronsid))
                if (!string.IsNullOrEmpty(addcontrondata))
                {
                    cloud = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontronsid);
                    for (int i = 0; i < cloud.objects.Count; i++)
                   var cloudjson = Newtonsoft.Json.JsonConvert.DeserializeObject<Cloud>(addcontrondata);
                    for (int i = 0; i < cloudjson.objects.Count; i++)
                    {
                        var objects = cloud.objects[i];
                        var objects = cloudjson.objects[i];
                        if (sid == objects.sid)
                        {
                            cloud = cloudjson;
                            break;
                        }
                    }
@@ -289,7 +360,7 @@
        /// <summary>
        /// 设备id
        /// </summary>
        public string id ="";
        public string id = "";
        public List<Objects> objects = new List<Objects>();
        public string time_stamp = string.Empty;
@@ -301,6 +372,14 @@
        public string sid = string.Empty;
        public string spk = string.Empty;
        public List<Attributes> attributes = new List<Attributes>();
    }
    [Serializable]
    public class Attributes
    {
        public string key = "";
        public string data_type = "";
        public List<string> value = new List<string>();
    }
}