using System;
|
using HDL_ON.DAL.Server;
|
using Shared;
|
using System.Collections.Generic;
|
using Newtonsoft.Json.Linq;
|
|
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
|
{
|
public class Method
|
{
|
/// <summary>
|
/// 添加遥控器的方法
|
/// </summary>
|
public void AddControl(FrameLayout frameLayout,Action<Control> action)
|
{
|
View.TipView tipView = new View.TipView();
|
tipView.InputBox(frameLayout,"", (name, frame) =>
|
{
|
///清除之前列表数据
|
Pir.BuottonList.Clear();
|
if (!string.IsNullOrEmpty(name))
|
{
|
Control control = new Control();
|
control.name = name;
|
control.type = "learn";
|
|
ThreadAddControl(control, frame, action);
|
|
|
|
}
|
}, false);
|
|
}
|
/// <summary>
|
/// 发送遥控器命令方法
|
/// </summary>
|
/// <param name="control"></param>
|
/// <param name="frame"></param>
|
public void ThreadAddControl(Control control, FrameLayout frame,Action<Control> action) {
|
|
DAL.Server.ResponsePackNew responsePackNew = null;
|
Loading loading = new Loading();
|
frame.AddChidren(loading);
|
loading.Start();
|
new System.Threading.Thread(() =>
|
{
|
try
|
{
|
responsePackNew = PirSend.Add(control);
|
}
|
catch { }
|
finally
|
{
|
Application.RunOnMainThread(() =>
|
{
|
loading.Hide();
|
if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
|
{
|
if (!string.IsNullOrEmpty(Sid("sid")))
|
{
|
//监听Mqtt推送下来状态码做提示
|
View.FailView failView = new View.FailView();
|
failView.ShouError((view) =>
|
{
|
view.Close();
|
ThreadAddControl(control, frame, action);
|
});
|
}
|
else
|
{
|
///这里:监听MTTP推送下来主题,才知道是否添加成功
|
frame.RemoveFromParent();//添加成功关闭弹窗
|
action(control);
|
}
|
|
|
}
|
else
|
{
|
ErrorShow(responsePackNew);
|
}
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
|
}
|
|
/// <summary>
|
/// MQTT主题推送下来的数据(遥控器添加)
|
/// </summary>
|
public static string addcontronsid = "";
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="sid"></param>
|
/// <returns></returns>
|
public string Sid(string sid)
|
{
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 5* 1000)
|
{
|
if (!string.IsNullOrEmpty(addcontronsid) && addcontronsid == sid)
|
{
|
break;
|
}
|
|
}
|
return addcontronsid;
|
}
|
/// <summary>
|
/// 错误码提示
|
/// </summary>
|
/// <param name="responsePackNew"></param>
|
public void ErrorShow(ResponsePackNew responsePackNew)
|
{
|
|
if (responsePackNew != null && responsePackNew.Code == "14005")
|
{
|
new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
|
|
}
|
else
|
{
|
new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
|
|
}
|
}
|
|
}
|
|
}
|