From eb424d24e39bab4a245725f35deab3f234ea0f13 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期五, 13 十二月 2019 10:48:50 +0800
Subject: [PATCH] 2019.12.13
---
ZigbeeApp/Shared/Common/Device.cs | 230 ++++++++++++++++++++++++++------------------------------
1 files changed, 107 insertions(+), 123 deletions(-)
diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs
old mode 100755
new mode 100644
index c175a45..0d7cf92
--- a/ZigbeeApp/Shared/Common/Device.cs
+++ b/ZigbeeApp/Shared/Common/Device.cs
@@ -37,22 +37,21 @@
}
}
/// <summary>
- /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨
+ /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(鎺掑簭)
/// </summary>
public List<CommonDevice> listAllDevice
{
get
{
- var list = new List<CommonDevice>();
- foreach (var listMac in this.dicDeviceSort.Values)
+ lock (dicAllDevice)
{
- foreach (var strMac in listMac)
+ var list = new List<CommonDevice>();
+ foreach (var device in dicAllDevice.Values)
{
- var listTemp = this.GetDevicesByMac(strMac);
- list.AddRange(listTemp);
+ list.Add(device);
}
+ return list;
}
- return list;
}
}
@@ -85,13 +84,9 @@
/// </summary>
private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
/// <summary>
- /// 璁惧Mac椤哄簭(閲岄潰鏄疢ac鍦板潃)
+ /// 鐗╃悊璁惧灞炰簬鍝釜鎴块棿鐨勮褰�
/// </summary>
- private Dictionary<string, List<string>> dicDeviceSort = null;
- /// <summary>
- /// 璁惧鏂囦欢鐨勫墠缂�鍚嶅瓧
- /// </summary>
- public const string deviceFirstName = "Device_";
+ private Dictionary<string, string> dicDeviceRoomId = null;
#endregion
@@ -175,9 +170,9 @@
}
}
//鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢
- this.DeleteGatewayFileByMemberModel();
- //鍒濆鍖栬澶囬『搴�
- this.InitDeviceSort();
+ this.DeleteGatewayFileByMemberModel();
+ //鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
+ this.InitRealDeviceRoomId();
}
/// <summary>
@@ -312,16 +307,6 @@
/// <param name="device">璁惧瀵硅薄(杩欎釜涓滆タ鏈夊彲鑳戒細琚洿鏀�)</param>
public void AddDeviceToMemory(ref CommonDevice device)
{
- if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false)
- {
- dicDeviceSort[device.CurrentGateWayId] = new List<string>();
- }
- if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false)
- {
- //淇濆瓨椤哄簭
- dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr);
- UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
- }
string mainKeys = this.GetDeviceMainKeys(device);
//濡傛灉瀹冩槸鍗囩骇鐨勯《绔鐐�,鍒欎笉鑳借瀹冨姞鍏ュ埌缂撳瓨锛屼絾鏄彲浠ヨ浠栫敓鎴愭枃浠�
if (device is OTADevice)
@@ -469,6 +454,11 @@
}
//澶囦唤鏁版嵁
await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac鍚嶇О, newMacName);
+ //濡傛灉瀹冨彧鏈変竴涓洖璺�,鍒欐洿鏀圭鐐瑰悕瀛�
+ if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count == 1)
+ {
+ return await this.ReName(device, newMacName);
+ }
}
return true;
}
@@ -521,18 +511,17 @@
this.ShowErrorMsg(msg);
return false;
}
- if (dicDeviceSort.ContainsKey(listdevice[0].CurrentGateWayId) == true &&
- dicDeviceSort[listdevice[0].CurrentGateWayId].Contains(info.DeviceAddr) == true)
- {
- //淇濆瓨椤哄簭
- dicDeviceSort[listdevice[0].CurrentGateWayId].Remove(info.DeviceAddr);
- UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
- }
//鍒犻櫎鏂囦欢
foreach (CommonDevice device in listdevice)
{
this.DeleteMemmoryDevice(device);
+ }
+ if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
+ {
+ //绉婚櫎鐪熷疄璁惧鐨勬埧闂寸储寮�
+ this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
+ this.SaveRealDeviceRoomId(null, null);
}
return true;
}
@@ -683,32 +672,14 @@
List<CommonDevice> list = new List<CommonDevice>();
lock (dicAllDevice)
{
- List<string> listSort = null;
- if (dicDeviceSort.ContainsKey(gwId) == false)
- {
- dicDeviceSort[gwId] = new List<string>();
- }
- listSort = dicDeviceSort[gwId];
-
//鍚勭綉鍏崇殑鎵�鏈夎澶�
foreach (CommonDevice device in this.dicAllDevice.Values)
{
if (gwId == device.CurrentGateWayId)
{
- if (listSort.Contains(device.DeviceAddr) == false)
- {
- listSort.Add(device.DeviceAddr);
- }
+ list.Add(device);
}
}
- //鎺掑簭
- foreach (var strMac in listSort)
- {
- var listTemp = this.GetDevicesByMac(strMac);
- list.AddRange(listTemp);
- }
- //淇濆瓨椤哄簭
- UserCenterLogic.SaveFileContent(UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile), dicDeviceSort);
}
return list;
@@ -776,6 +747,20 @@
}
/// <summary>
+ /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勬暟閲�
+ /// </summary>
+ /// <param name="DeviceAddr">Mac鍦板潃</param>
+ /// <returns></returns>
+ public int GetDevicesCountByMac(string DeviceAddr)
+ {
+ if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
+ {
+ return 0;
+ }
+ return dicDeviceEpoint[DeviceAddr].Count;
+ }
+
+ /// <summary>
/// 鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠�
/// </summary>
/// <returns></returns>
@@ -783,9 +768,10 @@
{
List<string> listDeviceFile = new List<string>();
List<string> listAllFile = Global.FileListByHomeId();
+
foreach (string file in listAllFile)
{
- if (file.StartsWith(deviceFirstName) == false)
+ if (file.StartsWith("Device_") == false)
{
//濡傛灉涓嶆槸璁惧鏂囦欢
continue;
@@ -1000,6 +986,11 @@
/// <returns></returns>
public void SetDeviceIconToControl(Button btnIcon, CommonDevice device)
{
+ if (device == null)
+ {
+ btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png";
+ return;
+ }
string unSelectFilePath = string.Empty;
string selectFilePath = string.Empty;
@@ -1406,7 +1397,7 @@
temperatrue = true;
}
//婀垮害浼犳劅鍣�
- else if(((TemperatureSensor)device).SensorDiv == 2)
+ else if (((TemperatureSensor)device).SensorDiv == 2)
{
humidity = true;
}
@@ -1512,89 +1503,82 @@
#endregion
- #region 鈻� 璁惧鎺掑簭___________________________
+ #region 鈻� 鐗╃悊璁惧鎵�灞炴埧闂確__________________
/// <summary>
- /// 鍒濆鍖栬澶囬『搴�
+ /// 鍒濆鍖栫墿鐞嗚澶囨墍灞炴埧闂寸殑璁板綍
/// </summary>
- private void InitDeviceSort()
+ private void InitRealDeviceRoomId()
{
- //璇诲彇璁惧椤哄簭
- this.dicDeviceSort = new Dictionary<string, List<string>>();
- string fullName = UserCenterLogic.CombinePath(DirNameResourse.LocalMemoryDirectory, DirNameResourse.DeviceSortFile);
+ this.dicDeviceRoomId = new Dictionary<string, string>();
+ string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
var strData = UserCenterLogic.LoadFileContent(fullName);
if (strData != null)
{
- this.dicDeviceSort = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(strData);
+ this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
}
- foreach (var device in dicAllDevice.Values)
- {
- if (dicDeviceSort.ContainsKey(device.CurrentGateWayId) == false)
- {
- dicDeviceSort[device.CurrentGateWayId] = new List<string>();
- }
- if (dicDeviceSort[device.CurrentGateWayId].Contains(device.DeviceAddr) == false)
- {
- //鏂版坊鍔犵殑璁惧
- dicDeviceSort[device.CurrentGateWayId].Add(device.DeviceAddr);
- }
- }
- foreach (var keys in dicDeviceSort.Keys)
- {
- var list = dicDeviceSort[keys];
- for (int i = 0; i < list.Count; i++)
- {
- if (this.dicDeviceEpoint.ContainsKey(list[i]) == false)
- {
- //杩欎釜涓滆タ鑾悕鐨勪笉瑙佷簡锛熷拰璁惧鍒楄〃鍖归厤涓嶄笂?
- list.RemoveAt(i);
- i--;
- }
- }
- }
-
- //淇濆瓨椤哄簭
- UserCenterLogic.SaveFileContent(fullName, dicDeviceEpoint);
}
/// <summary>
- /// 璁惧鎺掑簭
+ /// 淇濆瓨鐗╃悊璁惧鎵�灞炴埧闂寸殑璁板綍
/// </summary>
- /// <param name="listDevice">闇�瑕佹帓搴忕殑璁惧鍒楄〃</param>
- /// <returns></returns>
- public List<CommonDevice> SortDevice(List<CommonDevice> listDevice)
+ /// <param name="listDevice">闇�瑕佷繚瀛樼殑璁惧瀵硅薄</param>
+ /// <param name="roomId">闇�瑕佷繚瀛樼殑鍝釜璁惧鐨勬埧闂碔D</param>
+ /// <param name="saveRoadDevice">濡傛灉鍙湁涓�涓洖璺�,鏄惁鎶婂洖璺殑鎴块棿涓�璧蜂慨鏀�</param>
+ public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
{
- var dic = new Dictionary<string, List<CommonDevice>>();
- for (int i = 0; i < listDevice.Count; i++)
+ if (listDevice != null)
{
- if (dic.ContainsKey(listDevice[i].DeviceAddr) == false)
- {
- dic[listDevice[i].DeviceAddr] = new List<CommonDevice>();
- }
- dic[listDevice[i].DeviceAddr].Add(listDevice[i]);
+ this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
}
- var list = new List<CommonDevice>();
- var listCheck = new HashSet<string>();
- foreach (var listSort in this.dicDeviceSort.Values)
+
+ //淇濆瓨璁板綍
+ string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
+ UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
+
+ //娣诲姞鑷姩澶囦唤
+ HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
+
+ //濡傛灉璁惧鍙湁涓�涓洖璺紝濡傛灉鏀瑰彉浜嗙湡瀹炶澶囧尯鍩燂紝鍒欏畠鐨勫洖璺殑鍖哄煙涔熶竴璧锋敼浜�
+ if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
{
- for (int i = 0; i < listSort.Count; i++)
- {
- if (dic.ContainsKey(listSort[i]) == true && listCheck.Contains(listSort[i]) == false)
- {
- listCheck.Add(listSort[i]);
- dic[listSort[i]].Sort((obj1, obj2) =>
- {
- if (obj1.DeviceEpoint > obj2.DeviceEpoint)
- {
- return 1;
- }
- return -1;
- });
- list.AddRange(dic[listSort[i]]);
- }
- }
+ Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId, false);
}
- return list;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鐪熷疄鐗╃悊璁惧鐨勬埧闂村悕瀛�
+ /// </summary>
+ /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param>
+ /// <returns></returns>
+ public string GeteRealDeviceRoomName(CommonDevice device)
+ {
+ if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
+ {
+ //鏈垎閰嶅尯鍩�
+ return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
+ }
+ var room = Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
+ if (room != null)
+ {
+ return room.Name;
+ }
+ //鏈垎閰嶅尯鍩�
+ return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
+ }
+
+ /// <summary>
+ /// 鑾峰彇鐪熷疄鐗╃悊璁惧灞炰簬鍝釜鎴块棿
+ /// </summary>
+ /// <param name="device">璁惧鐨勬煇涓�涓洖璺�</param>
+ /// <returns></returns>
+ public Room GeteRealDeviceRoom(CommonDevice device)
+ {
+ if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
+ {
+ return null;
+ }
+ return Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
}
#endregion
@@ -1838,7 +1822,7 @@
string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail);
msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]";
msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false);
- this.ShowErrorMsg(msg);
+ this.ShowTipMsg(msg);
}
return null;
}
@@ -1959,7 +1943,7 @@
}
}
//濡傛灉鏄皟鍏夊櫒
- else if (mainDevice.Type == DeviceType.DimmableLight )
+ else if (mainDevice.Type == DeviceType.DimmableLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
if (mainDevice.IsCustomizeImage == false)
@@ -1968,7 +1952,7 @@
}
}
//濡傛灉鏄僵鐏殑璇�
- else if ( mainDevice.Type == DeviceType.ColorDimmableLight)
+ else if (mainDevice.Type == DeviceType.ColorDimmableLight)
{
mainDevice.DfunctionType = DeviceFunctionType.A鐏厜;
if (mainDevice.IsCustomizeImage == false)
--
Gitblit v1.8.0