From b1a0bdaa13e1eced0da2c411ce6dd0cbf7327a9a Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期三, 24 三月 2021 16:24:44 +0800
Subject: [PATCH] 2021-24-3-3
---
HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs | 465 +++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 300 insertions(+), 165 deletions(-)
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
index 8fd747b..9236d52 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/Method.cs
@@ -8,6 +8,39 @@
{
public class Method
{
+
+ /// <summary>
+ /// 绾㈠瀹濈▼搴忎富鍏ュ彛
+ /// </summary>
+ /// <param name="frame"></param>
+ /// <param name="function"></param>
+ public void MainView(FrameLayout frame, Entity.Function function,Action action)
+ {
+ Pir pirDevice = new Pir();
+ if (function != null)
+ {//鏁版嵁杞崲
+ pirDevice.name = function.name;
+ pirDevice.deviceId = function.deviceId;
+ pirDevice.sid = function.sid;
+ pirDevice.online = function.online;
+ pirDevice.versions = function.versions;
+ }
+ Pir.currPir = pirDevice;
+ GetControlList(frame, () =>
+ {
+ Application.RunOnMainThread(() =>
+ {
+ var page = new PirMain();
+ MainPage.BasePageView.AddChidren(page);
+ page.Show();
+ MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+ PirMain.BackAction += () =>
+ {
+ action?.Invoke();
+ };
+ });
+ }, Pir.currPir);
+ }
/// <summary>
/// 绠$悊浣嶇疆
@@ -24,16 +57,16 @@
/// <summary>
/// 淇敼鍚嶇О
/// </summary>
- /// <param name="tipText">鎻愮ず鏂囨湰</param>
+ /// <param name="tipText">鎻愮ず鏍囬鏂囨湰</param>
/// <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(StringId.editName, currName, StringId.nameNull, StringId.NameAlreadyExists, list, (text, view
+ new View.TipView().InputBox(tipText, currName, StringId.nameNull, StringId.NameAlreadyExists, list, (text, view
) =>
{
- action(text,view);
+ action(text, view);
}, () => { actionCancel(); }, tag);
}
/// <summary>
@@ -71,7 +104,7 @@
/// <param name="action">鍥炶皟鍑芥暟</param>
public void ThreadAddControl(Control control, FrameLayout frame, Action<Control> action)
{
- DAL.Server.ResponsePackNew responsePackNew = null;
+ Cloud mqttdate = null;
Loading loading = new Loading();
frame.AddChidren(loading);
loading.Start();
@@ -80,10 +113,17 @@
try
{
//鍙戦�佹坊鍔犲懡浠�
- responsePackNew = PirSend.Add(control);
-
-
-
+ var responsePackNew = PirSend.Add(control);
+ if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+ {
+ string sid = responsePackNew.Data.ToString();
+ controldata = "";
+ mqttdate = MqttDate("閬ユ帶鍣�", sid);
+ if (mqttdate != null)
+ {
+ control.sid = sid;
+ }
+ }
}
catch { }
@@ -92,55 +132,47 @@
Application.RunOnMainThread(() =>
{
loading.Hide();
- if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+ ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰�;
+ if (mqttdate != null)
{
- string sid = responsePackNew.Data.ToString();
- var mqttdate =MqttDate(sid);
- ///杩欓噷锛氱洃鍚琈TTP鎺ㄩ�佷笅鏉ヤ富棰橈紝鎵嶇煡閬撴槸鍚︽坊鍔犳垚鍔�
- if (mqttdate != null)
+ //浼戠湢500姣锛屼负绛夊緟浜戠鍒涘缓deviceid锛�
+ System.Threading.Thread.Sleep(500);
+ //璇诲彇娣诲姞閬ユ帶鍣╠eviceID锛屾墠鐭ラ亾鏄惁娣诲姞鎴愬姛锛�
+ GetControl(frame, control, (device) =>
{
- control.sid = sid;
- //浼戠湢500姣锛屼负绛夊緟浜戠鍒涘缓deviceid锛�
- System.Threading.Thread.Sleep(500);
- GetControl(frame, control, (device) =>
+ if (device != null)
{
- if (device != null)
- {
- control.deviceId = device.deviceId;
- frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
-
- action(control);
- }
- else
- {
- //璇诲彇deviceid杩斿洖閿欒鎻愮ず
- View.FailView failView = new View.FailView();
- failView.ShouError((view) =>
- {
- view.Close();
- ThreadAddControl(control, frame, action);
- });
-
- }
- });
- }
- else
- {
- //鐩戝惉Mqtt鎺ㄩ�佷笅鏉ョ姸鎬佺爜鍋氭彁绀�
- View.FailView failView = new View.FailView();
- failView.ShouError((view) =>
+ control.deviceId = device.deviceId;
+ frame.RemoveFromParent();//娣诲姞鎴愬姛鍏抽棴寮圭獥
+ action(control);
+ }
+ else
{
- view.Close();
- ThreadAddControl(control, frame, action);
- });
- }
+ //鐩戝惉Mqtt鎺ㄩ�佷笅鏉ョ姸鎬佺爜鍋氭彁绀�
+ View.FailView failView = new View.FailView();
+ failView.ShouError((view) =>
+ {
+ view.Close();
+ ThreadAddControl(control, frame, action);
+ });
+
+ }
+
+ });
}
else
{
- ErrorShow(responsePackNew);
+ //鐩戝惉Mqtt鎺ㄩ�佷笅鏉ョ姸鎬佺爜鍋氭彁绀�
+ View.FailView failView = new View.FailView();
+ failView.ShouError((view) =>
+ {
+ view.Close();
+ ThreadAddControl(control, frame, action);
+ });
}
- });
+
+ });
}
})
@@ -159,56 +191,62 @@
//鍔犺浇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");
+ var responsePackNew = PirSend.GetDeviceList("ir.module");
+ 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 == PirDevice.Pir.pirDeviceList.Find((c) => c.deviceId == pirJosn.deviceId))
+ {
+ PirDevice.Pir.pirDeviceList.Add(pirJosn);
+ }
+ }
+ }
+
+ }
+
+ }
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
- loading.Hide();
try
{
- if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+ if (Pir.pirDeviceList.Count != 0)
{
- 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++)
+ GetControlList(() =>
{
- 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))
- {
+ loading.Hide();
+ action();
- Pir.pirDeviceList.Add(pirJosn);
-
- }
- }
- }
-
- }
- GetControlList(frame, action);
-
+ });
}
else
{
+ loading.Hide();
Method method = new Method();
- method.ErrorShow(responsePackNew);
+ method.ErrorShow(null,"璇诲彇绾㈠瀹濆垪琛ㄥけ璐�");
}
}
catch { }
@@ -221,17 +259,12 @@
}
/// <summary>
- /// 鑾峰彇閬ユ帶鍣ㄥ垪琛�
+ /// 鑾峰彇鎵�鏈夌孩澶栧疂閬ユ帶鍣ㄥ垪琛�
/// </summary>
- /// <param name="frame">log鍥炬爣鍔犺浇鐣岄潰</param>
/// <param name="action">鍥炶皟鍑芥暟</param>
- public static void GetControlList(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
@@ -241,58 +274,72 @@
var pirDevice = Pir.pirDeviceList[i];
try
{
- responsePackNew = PirSend.ControlList(pirDevice);
+ var responsePackNew = PirSend.ControlList(pirDevice.deviceId);
+ 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];
+ //鏁版嵁杩斿簭鍒楀寲涓篖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);
+ }
+ }
+
+ }
+ }
}
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>
+ /// 鑾峰彇鍗曚釜绾㈠瀹濋仴鎺у櫒鍒楄〃
+ /// </summary>
+ /// <param name="action">鍥炶皟鍑芥暟</param>
+ public static void GetControlList(FrameLayout frame, Action action, Pir pirDevice)
+ {
+ ThreadSend(new Control { deviceId = pirDevice.deviceId }, (responsePackNew) =>
+ {
+ var jArray = 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.deviceId == pirJosn.deviceId))
+ {
+ pirDevice.FunctioList.Add(pirJosn);
+ }
+ }
+ }
+ action();
+ }, "鑾峰彇閬ユ帶鍣ㄥ垪琛�", "frame", frame, null);
}
/// <summary>
@@ -303,45 +350,77 @@
/// <param name="action">鍥炶皟鍑芥暟</param>
public void GetControl(FrameLayout frame, Control control, Action<Entity.Function> action)
{
- Entity.Function function = null;
+ ThreadSend(control, (responsePackNew) =>
+ {
+ var function = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.Function>(responsePackNew.Data.ToString());
+ action(function);
+ }, "鑾峰彇璁惧璇︽儏", "frame", frame, null);
+ }
+ /// <summary>
+ /// 鍙戦�佸懡浠ょ嚎绋�
+ /// </summary>
+ /// <param name="control">鍙戦�佹暟鎹璞�</param>
+ /// <param name="action">鍥炶皟鍑芥暟</param>
+ /// <param name="str">鍒ゆ柇瀛楃</param>
+ /// <param name="view">鍒ゆ柇log鐖舵帶浠�</param>
+ /// <param name="frame">log鐖舵帶浠�</param>
+ /// <param name="dialog">log鐖舵帶浠�</param>
+ public static void ThreadSend(Control control, Action<ResponsePackNew> action, string str,string view, FrameLayout frame, Dialog dialog)
+ {
+
//鍔犺浇log
Loading loading = new Loading();
- frame.AddChidren(loading);
- HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+ if (view == "dialog")
+ {
+ dialog.AddChidren(loading);
+ }
+ else
+ {
+ frame.AddChidren(loading);
+ }
loading.Start();
+ ResponsePackNew responsePackNew = null;
new System.Threading.Thread(() =>
{
try
{
- // 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
- responsePackNew = PirSend.GetinfoBySid(control);
+ 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);
+ }
+ else if (str == "鑾峰彇璁惧璇︽儏")
+ {
+ // 鑾峰彇璁惧璇︽儏閫氳繃(spk,sid)
+ responsePackNew = PirSend.GetinfoBySid(control);
+ }
+ else if (str == "鑾峰彇閬ユ帶鍣ㄥ垪琛�")
+ {
+ responsePackNew = PirSend.ControlList(control.deviceId);
+ }
}
catch { }
finally
{
Application.RunOnMainThread(() =>
{
- try
+ loading.Hide();
+ if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
{
- 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);
- }
+ action(responsePackNew);
}
- catch { }
- finally
+ else
{
- Application.RunOnMainThread(() =>
- {
- loading.Hide();
- action(function);
- });
+ Method method = new Method();
+ method.ErrorShow(responsePackNew, "");
}
});
@@ -349,28 +428,45 @@
})
{ IsBackground = true }.Start();
+
+
}
/// <summary>
- /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑鏁版嵁
+ /// MQTT涓婚鎺ㄩ�佷笅鏉ョ殑閬ユ帶鍣ㄦ暟鎹�
/// </summary>
- public static string mqttdata = "";
+ 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(str))
{
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];
@@ -380,7 +476,10 @@
break;
}
}
- break;
+ if (cloud != null)
+ {
+ break;
+ }
}
catch { }
}
@@ -392,24 +491,63 @@
/// 閿欒鐮佹彁绀�
/// </summary>
/// <param name="responsePackNew"></param>
- /// <param name="str"></param>
- public void ErrorShow(ResponsePackNew responsePackNew,string str="")
+ /// <param name="text">鑷畾涔夐敊璇枃鏈�</param>
+ /// <param name="popValue">寮规绫诲瀷锛�1=闂儊寮规锛�</param>
+ public void ErrorShow(ResponsePackNew responsePackNew, string text, int popValue = 1)
{
- if (str == "鍒犻櫎閬ユ帶鍣�") {
- new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.delFail));
+ string str = "";
+ if (text == "鍒犻櫎閬ユ帶鍣�")
+ {
+ str = Language.StringByID(StringId.delFail);
+ }
+ else if (text == "璇诲彇绾㈠瀹濆垪琛ㄥけ璐�")
+ {
+ str = Language.StringByID(StringId.huoqushujushibao);
}
else
{
- if (responsePackNew != null && responsePackNew.Code == "14005")
+ if (responsePackNew != null)
{
- new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.gatewayNotOnline));
- }
- else
- {
- new Intelligence.Automation.LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
+ switch (responsePackNew.Code)
+ {
+ case "14005":
+ {
+ str = Language.StringByID(StringId.gatewayNotOnline);
+
+ }
+ break;
+ case "10807":
+ {
+ str = Language.StringByID(StringId.bunengchaoguo10);
+
+
+ }
+ break;
+ case "2":
+ {
+ str = Language.StringByID(StringId.xitongweihuzhong);
+ }
+ break;
+ default:
+ {
+ str = Language.StringByID(StringId.huoqushujushibao);
+ }
+ break;
+
+ }
}
+ }
+ switch (popValue)
+ {
+ case 1:
+ {
+ new Intelligence.Automation.LogicView.TipPopView().FlashingBox(str);
+ }
+ break;
+ case 2: { } break;
+ case 3: { } break;
}
}
@@ -417,9 +555,6 @@
[Serializable]
public class Cloud
{
- /// <summary>
- /// 璁惧id
- /// </summary>
public string id = "";
public List<Objects> objects = new List<Objects>();
public string time_stamp = string.Empty;
--
Gitblit v1.8.0