From 404cdc88627f942df7944af04ee05b9d527752d6 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期一, 30 九月 2019 13:22:40 +0800 Subject: [PATCH] 合并了徐梅的按键面板绑定 --- ZigbeeApp/Shared/Common/Device.cs | 4752 +++++++++++++++++++++++----------------------------------- 1 files changed, 1,910 insertions(+), 2,842 deletions(-) diff --git a/ZigbeeApp/Shared/Common/Device.cs b/ZigbeeApp/Shared/Common/Device.cs index 0d5c065..3453f98 100755 --- a/ZigbeeApp/Shared/Common/Device.cs +++ b/ZigbeeApp/Shared/Common/Device.cs @@ -1,2867 +1,1935 @@ -锘縰sing Shared.Phone.UserCenter; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; -using ZigBee.Device; - -namespace Shared.Common -{ - /// <summary> - /// 鏈湴璁惧 - /// </summary> - public class LocalDevice - { - #region 鈻� 鍙橀噺澹版槑___________________________ - - /// <summary> - /// 鏈湴璁惧 +锘縰sing Shared.Phone.UserCenter; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using ZigBee.Device; + +namespace Shared.Common +{ + /// <summary> + /// 鏈湴璁惧 + /// </summary> + public class LocalDevice + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鏈湴璁惧 /// </summary> private static LocalDevice m_Current = null; - /// <summary> - /// 鏈湴璁惧 + /// <summary> + /// 鏈湴璁惧 /// </summary> - public static LocalDevice Current - { - get - { - if (m_Current == null) - { - m_Current = new LocalDevice(); - } - return m_Current; - } - set - { - m_Current = value; - } - } - /// <summary> - /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨 - /// </summary> - public List<CommonDevice> listAllDevice - { - get - { - var list = new List<CommonDevice>(); - foreach (var device in dicAllDevice.Values) - { - list.Add(device); - } - return list; - } - } - - /// <summary> - /// R鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D鐨勫墠缂� - /// </summary> - public const string deviceDefultNameFlag = "uDeviceDefultName"; - /// <summary> - /// R鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D - /// </summary> - public Dictionary<string, int> dicDeviceDefultNameID = null; - /// <summary> - /// 璁惧鐨勬ā鍧桰D鐨勬灇涓�(keys:妯″潡ID(宸茬炕璇�),value:璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互) - /// </summary> - private Dictionary<string, string> dicDeviceModelIdEnum = null; - /// <summary> - /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(闈炲叕寮�) - /// </summary> - private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>(); - /// <summary> - /// 鏈湴鎵�鏈夎澶嘦I鐨勭紦瀛�(闈炲叕寮�) - /// </summary> - private Dictionary<string, DeviceUI> dicAllDeviceUI = new Dictionary<string, DeviceUI>(); - /// <summary> - /// 鏈湴鎵�鏈夌殑椤剁偣鍗囩骇璁惧(闈炲叕寮�锛屼富閿槸MAC+200绔彛) - /// </summary> - private Dictionary<string, OTADevice> dicOTADevice = new Dictionary<string, OTADevice>(); - /// <summary> - /// 璁惧璁℃暟 - /// </summary> - private Dictionary<string, DeviceCountInfo> dicDeviceCount = new Dictionary<string, DeviceCountInfo>(); - /// <summary> - /// 璁惧鏂囦欢鐨勫墠缂�鍚嶅瓧 - /// </summary> - public const string deviceFirstName = "Device_"; - /// <summary> - /// 澶囩敤璁惧鏂囦欢鐨勫墠缂�鏍囪瘑鍚嶅瓧(涓鸿澶囧垹闄ゆ墍鐢�,杩欎釜鏂囦欢涓�鏃﹁澶囧垹闄ゅ悗灏变細涓�鐩村瓨鍦�) - /// </summary> - private string deviceBackupName = "Backup"; - /// <summary> - /// 閿� - /// </summary> - private object objLock = new object(); - - #endregion - - #region 鈻� 鍒锋柊璁惧___________________________ - + public static LocalDevice Current + { + get + { + if (m_Current == null) + { + m_Current = new LocalDevice(); + } + return m_Current; + } + set + { + m_Current = value; + } + } + /// <summary> + /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨 + /// </summary> + public List<CommonDevice> listAllDevice + { + get + { + var list = new List<CommonDevice>(); + foreach (var device in dicAllDevice.Values) + { + list.Add(device); + } + return list; + } + } + + /// <summary> + /// R鏂囦欢閲岄潰璁惧妯″潡ID鐨勭炕璇戝悕瀛楃殑鍓嶇紑 + /// </summary> + public const string deviceModelIdName = "uDeviceModelId"; + /// <summary> + /// R鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D + /// </summary> + public Dictionary<string, int> dicDeviceDefultNameID = null; + /// <summary> + /// 璁惧鐨勬ā鍧桰D鐨勬灇涓�(keys:妯″潡ID value:璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互) + /// </summary> + private Dictionary<string, string> dicDeviceModelIdEnum = null; + /// <summary> + /// 闇�瑕佽浆鎹㈢殑璁惧鐨勬ā鍧桰D(keys:鏃фā鍧桰D,value:鏂版ā鍧桰D) + /// </summary> + private Dictionary<string, string> dicDeviceModelIdChanged = null; + /// <summary> + /// 鏈湴鎵�鏈夎澶囩殑缂撳瓨(闈炲叕寮�) + /// </summary> + private Dictionary<string, CommonDevice> dicAllDevice = new Dictionary<string, CommonDevice>(); + /// <summary> + /// 鏈湴鎵�鏈夌殑椤剁偣鍗囩骇璁惧(闈炲叕寮�锛屼富閿槸MAC+200绔彛) + /// </summary> + private Dictionary<string, OTADevice> dicOTADevice = new Dictionary<string, OTADevice>(); + /// <summary> + /// 璁惧鐨勬�诲洖璺�(keys:Mac鍦板潃 value:鍏ㄩ儴绔彛鍙�) + /// </summary> + private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>(); + /// <summary> + /// 璁惧鏂囦欢鐨勫墠缂�鍚嶅瓧 + /// </summary> + public const string deviceFirstName = "Device_"; + /// <summary> + /// 閿� + /// </summary> + private object objLock = new object(); + + #endregion + + #region 鈻� 鍒锋柊璁惧___________________________ + /// <summary> /// 鍒锋柊鏈湴璁惧淇℃伅 /// </summary> public void ReFreshByLocal() { this.dicAllDevice.Clear(); - this.dicAllDeviceUI.Clear(); - this.dicDeviceCount.Clear(); + this.dicDeviceEpoint.Clear(); //鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D this.InitDeviceDefultNameIDList(); //鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� List<string> listFile = this.GetAllDeviceFile(); - foreach (string file in listFile) - { - //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞� - var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file); - if (device == null || device.CurrentGateWayId == null) - { - //澶辨晥鐨勬枃浠讹紝娌℃湁缃戝叧id鐨勯兘鍒犻櫎鎺� - Global.DeleteFilebyHomeId(file); - continue; - } - //濡傛灉杩欎釜璁惧鐨勭綉鍏矷D涓嶅瓨鍦ㄧ殑璇� - if (Common.LocalGateway.Current.IsGatewayExist(device.CurrentGateWayId) == false) - { - if (UserCenterResourse.UserInfo.AuthorityNo == 3) - { - //濡傛灉浠栨槸鎴愬憳鐨勮瘽,甯粬鏂板缓涓�涓綉鍏� - Common.LocalGateway.Current.AddVirtualGateway(device.CurrentGateWayId); - } - else - { - //濡傛灉鏄富浜�,鎴栬�呯鐞嗗憳,閭d箞杩欎釜鏂囦欢鏄潪娉曠殑,鐩存帴鍒犻櫎 - Global.DeleteFilebyHomeId(file); - continue; - } - } - - string mainKey = this.GetDeviceMainKeys(device); - if (device is OTADevice) - { - //200绔彛涓嶉渶瑕佸鐞� - this.dicOTADevice[mainKey] = (OTADevice)device; - continue; - } - //娣诲姞缂撳瓨 - this.dicAllDevice[mainKey] = device; - - //鍥炶矾璁℃暟 - if (this.dicDeviceCount.ContainsKey(device.DeviceAddr) == false) - { - this.dicDeviceCount[device.DeviceAddr] = new DeviceCountInfo(); - } - this.dicDeviceCount[device.DeviceAddr].Count += 1; - this.dicDeviceCount[device.DeviceAddr].hsEpoint.Add(device.DeviceEpoint); - - //妫�娴婾i鍥剧墖鏄惁姝g‘ - var deviceUi = this.GetDeviceUIFromLocalFile(device); - if (deviceUi == null) - { - deviceUi = new DeviceUI(); - deviceUi.DeviceFileName = device.FilePath; - deviceUi.Save(); - HdlAutoBackupLogic.AddOrEditorFile(deviceUi.FileName); - } - else - { - //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� - if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(deviceUi.IconPath)) == true) - { - //涓嶅瓨鍦ㄧ殑璇濓紝閲嶆柊鐢熸垚 - deviceUi.IconPath = string.Empty; - deviceUi.ReSave(); - HdlAutoBackupLogic.AddOrEditorFile(deviceUi.FileName); - } - } - //娣诲姞缂撳瓨 - this.dicAllDeviceUI[deviceUi.FileName] = deviceUi; + foreach (string file in listFile) + { + //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞� + var device = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(file); + if (device == null || device.CurrentGateWayId == null) + { +#if DEBUG + //璋冩煡,涓轰粈涔堝畠浼氭妸鍏ㄩ儴璁惧鍒犳帀锛� + string file1 = UserCenterLogic.CombinePath(file); + string file2 = UserCenterLogic.CombinePath("Back_" + file); + System.IO.File.Copy(file1, file2, true); +#endif + //澶辨晥鐨勬枃浠讹紝娌℃湁缃戝叧id鐨勯兘鍒犻櫎鎺� + Global.DeleteFilebyHomeId(file); + continue; + } + //濡傛灉杩欎釜璁惧鐨勭綉鍏矷D涓嶅瓨鍦ㄧ殑璇� + if (HdlGatewayLogic.Current.IsGatewayExist(device.CurrentGateWayId) == false) + { + if (UserCenterResourse.UserInfo.AuthorityNo == 3) + { + //濡傛灉浠栨槸鎴愬憳鐨勮瘽,甯粬鏂板缓涓�涓綉鍏� + HdlGatewayLogic.Current.AddVirtualGateway(device.CurrentGateWayId); + } + else + { +#if DEBUG + //璋冩煡,涓轰粈涔堝畠浼氭妸鍏ㄩ儴璁惧鍒犳帀锛� + string file1 = UserCenterLogic.CombinePath(file); + string file2 = UserCenterLogic.CombinePath("Back_" + file); + System.IO.File.Copy(file1, file2, true); +#endif + //濡傛灉鏄富浜�,鎴栬�呯鐞嗗憳,閭d箞杩欎釜鏂囦欢鏄潪娉曠殑,鐩存帴鍒犻櫎 + Global.DeleteFilebyHomeId(file); + continue; + } + } + + string mainKey = this.GetDeviceMainKeys(device); + if (device is OTADevice) + { + //200绔彛涓嶉渶瑕佸鐞� + this.dicOTADevice[mainKey] = (OTADevice)device; + continue; + } + //娣诲姞缂撳瓨 + this.dicAllDevice[mainKey] = device; + + //鍥炶矾鏀堕泦 + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false) + { + this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>(); + } + this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint); + + //妫�娴婾i鍥剧墖鏄惁姝g‘,杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true) + { + //涓嶅瓨鍦ㄧ殑璇濓紝閲嶆柊鐢熸垚 + device.IconPath = string.Empty; + device.ReSave(); + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } } //鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 this.DeleteGatewayFileByMemberModel(); - } - - /// <summary> - /// 鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 - /// </summary> - private void DeleteGatewayFileByMemberModel() - { - if (UserCenterResourse.UserInfo.AuthorityNo != 3) - { - return; - } - var listId = new HashSet<string>(); - foreach (var device in this.dicAllDevice.Values) - { - if (listId.Contains(device.CurrentGateWayId) == false) - { - listId.Add(device.CurrentGateWayId); - } - } - var listGateway = Common.LocalGateway.Current.GetAllLocalGateway(); - foreach (var gateway in listGateway) - { - string gwId = Common.LocalGateway.Current.GetGatewayId(gateway); - if (listId.Contains(gwId) == false) - { - //杩欎釜缃戝叧瀵逛簬褰撳墠杩欎釜鎴愬憳鏉ヨ鏄潪娉曠殑 - Common.LocalGateway.Current.DeleteGatewayFile(gwId); - } - } - } - - #endregion - - #region 鈻� 娣诲姞璁惧___________________________ - - /// <summary> - /// 灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚) - /// </summary> - /// <param name="zbGateway">缃戝叧瀵硅薄</param> - /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param> - /// <returns>涓�鐩磋繑鍥瀟rue</returns> - public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null) - { - //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧 - List<CommonDevice> listDevice = new List<CommonDevice>(); - List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, deviceComingAction); - - if (list == null) - { - return false; - } - listDevice.AddRange(list); - - //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶� - string gwID = Common.LocalGateway.Current.GetGatewayId(zbGateway); - List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID); - Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>(); - foreach (var device in listLocalDevices) - { - string maikey = this.GetDeviceMainKeys(device); - dicExist[maikey] = device; - } - - //娣诲姞璁惧鐨勭紦瀛� - for (int i = 0; i < listDevice.Count; i++) - { - var device = listDevice[i]; - if (device == null || device.DeviceAddr == null) - { - continue; - } - //娣诲姞缂撳瓨 - this.AddDeviceToMemory(ref device); - - //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� - string maikey = this.GetDeviceMainKeys(device); - if (dicExist.ContainsKey(maikey) == true) - { - dicExist.Remove(maikey); - } - } - - //濡傛灉鏈湴鍜岀綉鍏崇殑璁惧涓嶄竴鑷寸殑鏃跺�欙紝鏆傛椂鍒犻櫎鏈湴鐨勮澶� - //娉ㄦ剰锛氬彧鏄垹闄よ澶囨枃浠讹紝鎴块棿鍐呭浠�涔堢殑杩樺瓨鍦ㄧ潃 - foreach (var device in dicExist.Values) - { - this.DeleteMemmoryDevice(device, false); - } - - if (listDevice.Count > 0) - { - //绛夊緟涓�涓嬭澶囩殑纭欢淇℃伅 - await Task.Delay(1500); - //閲嶆柊鍙樻洿UI - foreach (var device in listDevice) - { - if (device == null || device.DeviceAddr == null || (device is OTADevice)) - { - continue; - } - var ui = this.GetDeviceUI(device); - if (ui.IsCustomizeImage == false) - { - ui.IconPath = string.Empty; - ui.ReSave(); - } - } - } - - return true; - } - - /// <summary> - /// 娣诲姞璁惧鍒扮紦瀛�,瀛樺湪鏃惰鐩� - /// </summary> - /// <param name="device">璁惧瀵硅薄(杩欎釜涓滆タ鏈夊彲鑳戒細琚洿鏀�)</param> - /// <param name="ResetImageType">鏄惁閲嶇疆闀滃儚绫诲瀷</param> - public void AddDeviceToMemory(ref CommonDevice device, bool ResetImageType = false) - { - //灏濊瘯鎭㈠鍒犻櫎浜嗙殑鏂囦欢 - bool backFile = this.RecoverBackupDeviceFile(ref device); - - string mainKeys = this.GetDeviceMainKeys(device); - //濡傛灉瀹冩槸鍗囩骇鐨勯《绔鐐�,鍒欎笉鑳借瀹冨姞鍏ュ埌缂撳瓨锛屼絾鏄彲浠ヨ浠栫敓鎴愭枃浠� - if (device is OTADevice) - { - //灏濊瘯鎭㈠鏂囦欢鎴愬姛,鎴栬�呮湰鍦伴兘娌℃湁杩欎釜璁惧 - if (backFile == true || this.dicOTADevice.ContainsKey(mainKeys) == false) - { - this.dicOTADevice[mainKeys] = (OTADevice)device; - } - else - { - //浜ゆ崲灞炴�� - var tempDevice = this.dicOTADevice[mainKeys]; - //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 - this.SetDeviceInfoToMain(tempDevice, device); - device = tempDevice; - } - - if (ResetImageType == true) - { - //ota璁惧鐨勯暅鍍忕被鍨嬪垵濮嬪�艰缃负-1 - device.ImgTypeId = -1; - device.ImgVersion = -1; - } - - bool exists = Global.IsExistsByHomeId(device.FilePath); - device.ReSave(); - - if (exists == false) - { - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); - } - - //璁剧疆璁惧鍏ㄩ儴鐨勯暅鍍忎俊鎭� - this.SetAllImageInfoToOtaDevice((OTADevice)device); - - return; - } - - if (this.dicAllDevice.ContainsKey(mainKeys) == true) - { - //浜ゆ崲灞炴�� - var tempDevice = this.dicAllDevice[mainKeys]; - //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 - this.SetDeviceInfoToMain(tempDevice, device); - device = tempDevice; - } - else - { - this.dicAllDevice[mainKeys] = device; - } - //鑾峰彇璁惧鐨勭‖浠朵俊鎭� - this.SetAllHardFirmwareInfoToDevice(device); - - //铏氭嫙璁惧鐨勮瘽锛岄檮鍔犲洖璺彿 - if (device.DriveCode > 0 && this.GetSimpleEpointName(device) == string.Empty) - { - //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О - var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); - //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� - dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; - this.SetEpointName(device, dName); - new System.Threading.Thread(async () => - { - //鍥犱负铏氭嫙璁惧涓嶄細缁忚繃璁惧鍏ョ綉杩欎竴姝ワ紝鎵�浠ョ洿鎺ョ粰瀹冧竴涓粯璁ゅ悕瀛� - await this.ReName(this.dicAllDevice[mainKeys], dName, ShowErrorMode.NO); - }) - { IsBackground = true }.Start(); - } - - //璁惧璁℃暟 - if (this.dicDeviceCount.ContainsKey(device.DeviceAddr) == false) - { - this.dicDeviceCount[device.DeviceAddr] = new DeviceCountInfo(); - } - if (this.dicDeviceCount[device.DeviceAddr].hsEpoint.Contains(device.DeviceEpoint) == false) - { - this.dicDeviceCount[device.DeviceAddr].Count += 1; - this.dicDeviceCount[device.DeviceAddr].hsEpoint.Add(device.DeviceEpoint); - } - - //娣诲姞璁惧鐨勬椂鍊欙紝鐩存帴鍒涘缓璁惧鐨刄I鍥� - DeviceUI deviceUI = new DeviceUI(); - deviceUI.DeviceFileName = device.FilePath; - - bool exists2 = Global.IsExistsByHomeId(deviceUI.FileName); - deviceUI.Save(); - if (exists2 == false) - { - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(deviceUI.FileName); - this.dicAllDeviceUI[deviceUI.FileName] = deviceUI; - } - - exists2 = Global.IsExistsByHomeId(device.FilePath); - device.ReSave(); - if (exists2 == false) - { - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); - } - } - - /// <summary> - /// 鎭㈠鍒犻櫎浜嗙殑鏂囦欢(浠呴檺娣诲姞璁惧鐨勬椂鍊�) - /// </summary> - /// <param name="device"></param> - private bool RecoverBackupDeviceFile(ref CommonDevice device) - { - //濡傛灉鏈湴瀛樺湪澶囩敤鐨勬枃浠跺す鐨勮瘽,鍒欎娇鐢ㄥ浠界殑鏂囦欢澶逛綔涓哄璞� - string backFile = deviceBackupName + device.FilePath; - if (Global.IsExistsByHomeId(device.FilePath) == true || Global.IsExistsByHomeId(backFile) == false) - { - //鍙湁鍦ㄦ湰鍦扮洰鏍囪澶囨枃浠朵笉瀛樺湪锛屽苟涓斿浠芥枃浠跺瓨鍦ㄧ殑鏃跺�欐墠澶勭悊 - return false; - } - - //鍙嶅簭鍒楀寲涓烘寚瀹氱殑绫伙紝涓嶇劧鏁版嵁浼氫涪澶辫�屽鑷存棤娉曞己杞�(鈽呰繖涓笢瑗夸繚瀛樼潃浠ュ墠鐨勭綉鍏冲浠芥暟鎹槄) - var tempDevice = ZigBee.Device.CommonDevice.CommonDeviceByFilePath(backFile); - if (tempDevice == null) - { - return false; - } - //涓嶆部鐢ㄥ悕瀛�,鍏堣繖鏍峰惂 - this.SetMacName(tempDevice, string.Empty); - this.SetEpointName(tempDevice, string.Empty); - - //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 - this.SetDeviceInfoToMain(tempDevice, device); - //鏇挎崲瀵硅薄 - device = tempDevice; - - //杩欓噷缁х画淇濈暀鐫�閭d釜澶囦唤鏂囦欢锛屽ソ鍍忎篃娌′粈涔堥棶棰樼殑鏍峰瓙 - - return true; - } - - #endregion - - #region 鈻� 淇敼璁惧___________________________ - - /// <summary> - /// 鏇存敼鍚嶅瓧骞朵笖鍒锋柊缂撳瓨(淇敼澶辫触鏃讹紝浼氭樉绀轰俊鎭�) - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="newName">鏂板悕瀛�</param> - /// <param name="mode">鏄惁鏄剧ず閿欒</param> - public async Task<bool> ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES) - { - //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� - //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� - if (UserCenterResourse.UserInfo.AuthorityNo != 3) - { - var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName); - if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1) - { - //璁惧鍚嶇О淇敼澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - if (mode == ShowErrorMode.YES) - { - this.ShowErrorMsg(msg); - } - return false; - } - //澶囦唤鏁版嵁 - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A绔偣鍚嶇О, newName); - } - - //鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 - this.SetEpointName(device, newName); - - this.BackupDeviceAfterReName(device); - - return true; - } - - /// <summary> - /// 鏇存敼Mac鍚嶅瓧骞朵笖鍒锋柊缂撳瓨(淇敼澶辫触鏃讹紝浼氭樉绀轰俊鎭�) - /// </summary> - /// <param name="listDevice">璁惧瀵硅薄</param> - /// <param name="newMacName">鏂板悕瀛�</param> - /// <param name="mode">鏄惁鏄剧ず閿欒</param> - public async Task<bool> ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES) - { - if (listDevice.Count == 0) - { - return true; - } - CommonDevice device = listDevice[0]; - - //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� - //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� - if (UserCenterResourse.UserInfo.AuthorityNo != 3) - { - //淇敼鐗╃悊鍚嶅瓧 - var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName); - if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result == 1) - { - //璁惧鍚嶇О淇敼澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - if (mode == ShowErrorMode.YES) - { - this.ShowErrorMsg(msg); - } - return false; - } - //澶囦唤鏁版嵁 - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac鍚嶇О, newMacName); - } - - //淇敼缂撳瓨 - for (int i = 0; i < listDevice.Count; i++) - { - var device2 = listDevice[i]; - //杩欎袱涓笢瑗垮緢鐗规畩 - this.SetMacName(device2, newMacName); - - //鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 - this.BackupDeviceAfterReName(device2); - } - return true; - } - - /// <summary> - /// 鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 - /// </summary> - /// <param name="device"></param> - private void BackupDeviceAfterReName(CommonDevice device) - { - string mainKeys = this.GetDeviceMainKeys(device); - if (this.dicAllDevice.ContainsKey(mainKeys) == false) - { - return; - } - this.dicAllDevice[mainKeys] = device; - device.ReSave(); - - //娣诲姞鑷姩澶囦唤 - HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); - } - - #endregion - - #region 鈻� 鍒犻櫎璁惧___________________________ - - /// <summary> - /// 鍒犻櫎璁惧骞朵笖鍒锋柊缂撳瓨(鍒犻櫎澶辫触鏃讹紝浼氭樉绀轰俊鎭�) - /// </summary> - /// <param name="listdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param> - public async Task<bool> DeleteDevice(List<CommonDevice> listdevice) - { - var data = new CommonDevice.RemoveDeviceData(); - var info = new CommonDevice.RemoveDeviceListInfo(); - info.DeviceAddr = listdevice[0].DeviceAddr; - data.DeviceAddrList.Add(info); - - //鍒犱竴娆$殑鏃跺�欙紝瀹冧細鎶奙AC鍦板潃涓嬮潰鍏ㄩ儴鐨勮澶囬兘鍒犻櫎 - var result = await listdevice[0].DeleteDeviceAsync(data); - if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0) - { - //璁惧鍒犻櫎澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return false; - } - - //鍒犻櫎鏂囦欢 - foreach (CommonDevice device in listdevice) - { - this.DeleteMemmoryDevice(device); - } - return true; - } - - /// <summary> - /// 鍒犻櫎缂撳瓨鐨勮澶� - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="deleteRoom">鏄惁浠庢埧闂村垹闄�</param> - public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true) - { - //鍒犻櫎缂撳瓨 - string mainKeys = this.GetDeviceMainKeys(device); - if (this.dicAllDevice.ContainsKey(mainKeys) == true) - { - this.dicAllDevice.Remove(mainKeys); - } - - //鍒犻櫎璁惧鏂囦欢 - string filePath = device.FilePath; - if (Global.IsExistsByHomeId(filePath) == true) - { - if (UserCenterResourse.UserInfo.AuthorityNo == 3) - { - //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� - Global.DeleteFilebyHomeId(filePath); - } - else - { - //涓嶅垹闄ゆ枃浠讹紝鐩存帴鏀瑰悕瀛� - string oldFile = UserCenterLogic.CombinePath(filePath); - string newFile = UserCenterLogic.CombinePath(deviceBackupName + filePath); - Global.MoveFileToDirectory(oldFile, newFile); - //鍒犻櫎鑷姩澶囦唤 - HdlAutoBackupLogic.DeleteFile(device.FilePath); - } - } - - //鍒犻櫎200绔彛鏂囦欢 - string otaKeys = this.GetDeviceMainKeys(device.DeviceAddr, 200); - if (this.dicOTADevice.ContainsKey(otaKeys) == true) - { - string otaFile = this.dicOTADevice[otaKeys].FilePath; - if (Global.IsExistsByHomeId(otaFile) == true) - { - if (UserCenterResourse.UserInfo.AuthorityNo == 3) - { - //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� - Global.DeleteFilebyHomeId(filePath); - } - else - { - //涓嶅垹闄ゆ枃浠讹紝鐩存帴鏀瑰悕瀛� - string oldFile = UserCenterLogic.CombinePath(otaFile); - string newFile = UserCenterLogic.CombinePath(deviceBackupName + otaFile); - Global.MoveFileToDirectory(oldFile, newFile); - //鍒犻櫎鑷姩澶囦唤 - HdlAutoBackupLogic.DeleteFile(otaFile); - } - } - this.dicOTADevice.Remove(otaKeys); - } - - if (deleteRoom == true && Room.CurrentRoom != null) - { - //浠庢埧闂翠腑鍒犻櫎 - Room.CurrentRoom.DeleteDevice(device); - } - } - - /// <summary> - /// 鍒犻櫎璁惧鐨勫浠芥枃浠�(搴旇鍙湁鍦ㄥ垹闄ょ綉鍏崇殑鏃跺�欎娇鐢ㄥ惂) - /// </summary> - /// <param name="device"></param> - public void DeleteDeviceBackupFile(CommonDevice device) - { - string backFile = deviceBackupName + device.FilePath; - if (Global.IsExistsByHomeId(backFile) == true) - { - Global.DeleteFilebyHomeId(backFile); - HdlAutoBackupLogic.DeleteFile(backFile); - } - } - - #endregion - - #region 鈻� 娴嬭瘯璁惧___________________________ - - /// <summary> - /// 鍙戦�佹祴璇曟寚浠ゅ埌璁惧 - /// </summary> - /// <param name="device"></param> - public void SetTestCommand(CommonDevice device) - { - device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5); - } - - /// <summary> - /// 妫�娴嬭澶囨槸鍚︽嫢鏈夋祴璇曠殑鍔熻兘 - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public bool DeviceIsCanTest(CommonDevice device) - { - foreach (var data in device.InClusterList) - { - //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� - if (data.InCluster == 3) - { - return true; - } - } - return false; - } - - /// <summary> - /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊紑鍏崇殑鍔熻兘(杈撳嚭绨�) - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public bool OutDeviceIsCanOnOff(CommonDevice device) - { - foreach (var data in device.OutClusterList) - { - //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� - if (data.OutCluster == 6) - { - return true; - } - } - return false; - } - - /// <summary> - /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊紑鍏崇殑鍔熻兘(杈撳叆绨�) - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public bool InDeviceIsCanOnOff(CommonDevice device) - { - foreach (var data in device.InClusterList) - { - //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� - if (data.InCluster == 6) - { - return true; - } - } - return false; - } - - #endregion - - #region 鈻� 鑾峰彇璁惧___________________________ - - /// <summary> - /// 鏍规嵁缃戝叧ID鑾峰彇鎵�鏈夌殑璁惧 - /// </summary> - /// <param name="gwId">缃戝叧ID</param> - /// <returns></returns> - public List<CommonDevice> GetDeviceByGatewayID(string gwId) - { - List<CommonDevice> list = new List<CommonDevice>(); - //鍚勭綉鍏崇殑鎵�鏈夎澶� - foreach (CommonDevice device in this.dicAllDevice.Values) - { - if (gwId == device.CurrentGateWayId) - { - list.Add(device); - } - } - - return list; - } - - /// <summary> - /// 鑾峰彇鎸囧畾璁惧(涓婚敭鏄細Mac鍦板潃+绔彛鍙�),涓嶅瓨鍦ㄦ椂锛岃繑鍥瀗ull - /// </summary> - /// <param name="mainKeys">Mac鍦板潃+绔彛鍙�</param> - /// <returns></returns> - public CommonDevice GetDevice(string mainKeys) - { - if (this.dicAllDevice.ContainsKey(mainKeys) == true) - { - return this.dicAllDevice[mainKeys]; - } - return null; - } - - /// <summary> - /// 鑾峰彇鎸囧畾璁惧,涓嶅瓨鍦ㄦ椂锛岃繑鍥瀗ull - /// </summary> - /// <param name="DeviceAddr">Mac鍦板潃</param> - /// <param name="DeviceEpoint">绔彛鍙�</param> - /// <returns></returns> - public CommonDevice GetDevice(string DeviceAddr, int DeviceEpoint) - { - string mainkeys = this.GetDeviceMainKeys(DeviceAddr, DeviceEpoint); - return this.GetDevice(mainkeys); - } - - /// <summary> - /// 鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� - /// </summary> - /// <returns></returns> - public List<string> GetAllDeviceFile() - { - List<string> listDeviceFile = new List<string>(); + } + + /// <summary> + /// 鎴愬憳韬唤鐨勬椂鍊�,鍒犻櫎鎺夐潪娉曠殑缃戝叧鏂囦欢 + /// </summary> + private void DeleteGatewayFileByMemberModel() + { + if (UserCenterResourse.UserInfo.AuthorityNo != 3) + { + return; + } + var listId = new HashSet<string>(); + foreach (var device in this.dicAllDevice.Values) + { + if (listId.Contains(device.CurrentGateWayId) == false) + { + listId.Add(device.CurrentGateWayId); + } + } + var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway(); + foreach (var gateway in listGateway) + { + string gwId = HdlGatewayLogic.Current.GetGatewayId(gateway); + if (listId.Contains(gwId) == false) + { + //杩欎釜缃戝叧瀵逛簬褰撳墠杩欎釜鎴愬憳鏉ヨ鏄潪娉曠殑 + HdlGatewayLogic.Current.DeleteGatewayFile(gwId); + } + } + } + + #endregion + + #region 鈻� 娣诲姞璁惧___________________________ + + /// <summary> + /// 灏嗘寚瀹氱綉鍏崇殑璁惧瀛樺叆缂撳瓨涓�(浠庢柊鑾峰彇闀滃儚) + /// </summary> + /// <param name="zbGateway">缃戝叧瀵硅薄</param> + /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param> + /// <returns>涓�鐩磋繑鍥瀟rue</returns> + public async Task<bool> SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null) + { + //浠庣綉鍏宠幏鍙栧叏閮ㄧ殑璁惧 + List<CommonDevice> listDevice = new List<CommonDevice>(); + List<CommonDevice> list = await this.GetDeviceListFromGateway(zbGateway, deviceComingAction); + + if (list == null) + { + return false; + } + listDevice.AddRange(list); + + //鑾峰彇杩欎釜缃戝叧鐨勬湰鍦版墍鏈夎澶� + string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway); + List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID); + Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>(); + foreach (var device in listLocalDevices) + { + string maikey = this.GetDeviceMainKeys(device); + dicExist[maikey] = device; + } + + //娣诲姞璁惧鐨勭紦瀛� + for (int i = 0; i < listDevice.Count; i++) + { + var device = listDevice[i]; + if (device == null || device.DeviceAddr == null) + { + continue; + } + //娣诲姞缂撳瓨 + this.AddDeviceToMemory(ref device); + + //绉婚櫎瀛樺湪鐨勮澶囧唴瀛� + string maikey = this.GetDeviceMainKeys(device); + if (dicExist.ContainsKey(maikey) == true) + { + dicExist.Remove(maikey); + } + //鑾峰彇璁惧鐨勫浐瀹氬睘鎬� + HdlDeviceFixedAttributeLogic.Current.SetAllFixedAttributeToDevice(device); + } + + for (int i = 0; i < listDevice.Count; i++) + { + var device = listDevice[i]; + //瀵规湭鍛藉悕鐨勮澶囬噸鏂板懡鍚� + if (this.GetSimpleEpointName(device) == string.Empty) + { + //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О + var dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); + //铏氭嫙璁惧鐨勮瘽锛岄檮鍔犲洖璺彿 + if (device.DriveCode > 0) + { + //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� + dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; + } + //澶氬洖璺澶囩殑璇濓紝闄勫姞鍥炶矾鍙� + else if (dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && dicDeviceEpoint[device.DeviceAddr].Count > 1) + { + var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); + dName = arry[0].Trim(); + //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� + dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; + } + + new System.Threading.Thread(async () => + { + await this.ReName(device, dName, ShowErrorMode.NO); + }) + { IsBackground = true }.Start(); + } + } + + //濡傛灉鏈湴鍜岀綉鍏崇殑璁惧涓嶄竴鑷寸殑鏃跺�欙紝鏆傛椂鍒犻櫎鏈湴鐨勮澶� + //娉ㄦ剰锛氬彧鏄垹闄よ澶囨枃浠讹紝鎴块棿鍐呭浠�涔堢殑杩樺瓨鍦ㄧ潃 + foreach (var device in dicExist.Values) + { + this.DeleteMemmoryDevice(device, false); + } + + return true; + } + + /// <summary> + /// 娣诲姞璁惧鍒扮紦瀛�,瀛樺湪鏃惰鐩� + /// </summary> + /// <param name="device">璁惧瀵硅薄(杩欎釜涓滆タ鏈夊彲鑳戒細琚洿鏀�)</param> + public void AddDeviceToMemory(ref CommonDevice device) + { + string mainKeys = this.GetDeviceMainKeys(device); + //濡傛灉瀹冩槸鍗囩骇鐨勯《绔鐐�,鍒欎笉鑳借瀹冨姞鍏ュ埌缂撳瓨锛屼絾鏄彲浠ヨ浠栫敓鎴愭枃浠� + if (device is OTADevice) + { + if (this.dicOTADevice.ContainsKey(mainKeys) == false) + { + this.dicOTADevice[mainKeys] = (OTADevice)device; + } + else + { + //浜ゆ崲灞炴�� + var tempDevice = this.dicOTADevice[mainKeys]; + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + this.SetDeviceInfoToMain(tempDevice, device); + device = tempDevice; + } + + bool exists = Global.IsExistsByHomeId(device.FilePath); + device.ReSave(); + if (exists == false) + { + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + return; + } + + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + //浜ゆ崲灞炴�� + var tempDevice = this.dicAllDevice[mainKeys]; + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + this.SetDeviceInfoToMain(tempDevice, device); + device = tempDevice; + } + else + { + this.dicAllDevice[mainKeys] = device; + } + + //璁惧鍥炶矾鏀堕泦 + if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == false) + { + this.dicDeviceEpoint[device.DeviceAddr] = new HashSet<int>(); + } + if (this.dicDeviceEpoint[device.DeviceAddr].Contains(device.DeviceEpoint) == false) + { + this.dicDeviceEpoint[device.DeviceAddr].Add(device.DeviceEpoint); + } + + bool exists2 = Global.IsExistsByHomeId(device.FilePath); + device.ReSave(); + if (exists2 == false) + { + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + } + + #endregion + + #region 鈻� 淇敼璁惧___________________________ + + /// <summary> + /// 鏇存敼鍚嶅瓧骞朵笖鍒锋柊缂撳瓨(淇敼澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="newName">鏂板悕瀛�</param> + /// <param name="mode">鏄惁鏄剧ず閿欒</param> + public async Task<bool> ReName(CommonDevice device, string newName, ShowErrorMode mode = ShowErrorMode.YES) + { + //鍏堝埆绠¢偅涔堝锛屾洿鏀瑰悕瀛楀悗锛屽埛鏂拌澶囩紦瀛� + this.SetEpointName(device, newName); + + this.BackupDeviceAfterReName(device); + + //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� + //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� + if (UserCenterResourse.UserInfo.AuthorityNo != 3) + { + var result = await device.RenameDeviceNameAsync(device.DeviceAddr, device.DeviceEpoint, newName); + if (result == null || result.deviceRenameData == null || result.deviceRenameData.Result == 1) + { + //璁惧鍚嶇О淇敼澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + + if (mode == ShowErrorMode.YES) + { + this.ShowErrorMsg(msg); + } + return false; + } + //澶囦唤鏁版嵁 + await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.A绔偣鍚嶇О, newName); + } + return true; + } + + /// <summary> + /// 鏇存敼Mac鍚嶅瓧骞朵笖鍒锋柊缂撳瓨(淇敼澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <param name="listDevice">璁惧瀵硅薄</param> + /// <param name="newMacName">鏂板悕瀛�</param> + /// <param name="mode">鏄惁鏄剧ず閿欒</param> + public async Task<bool> ReMacName(List<CommonDevice> listDevice, string newMacName, ShowErrorMode mode = ShowErrorMode.YES) + { + if (listDevice.Count == 0) + { + return true; + } + //鍏堝埆绠¢偅涔堝锛屽厛淇敼缂撳瓨 + for (int i = 0; i < listDevice.Count; i++) + { + var device2 = listDevice[i]; + //杩欎袱涓笢瑗垮緢鐗规畩 + this.SetMacName(device2, newMacName); + + //鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 + this.BackupDeviceAfterReName(device2); + } + + CommonDevice device = listDevice[0]; + //涓嶅啀妫�娴嬪悕瀛楁槸鍚︿竴鏍� + //鎴愬憳鍙兘淇敼鑷繁鏈湴鐨勫悕瀛� + if (UserCenterResourse.UserInfo.AuthorityNo != 3) + { + //淇敼鐗╃悊鍚嶅瓧 + var result = await device.RenameDeviceMacNameAsync(device.DeviceAddr, device.DeviceEpoint, newMacName); + if (result == null || result.renameDeviceMacNameData == null || result.renameDeviceMacNameData.Result != 0) + { + //璁惧鍚嶇О淇敼澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNameFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + if (mode == ShowErrorMode.YES) + { + this.ShowErrorMsg(msg); + } + return false; + } + //澶囦唤鏁版嵁 + await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(device, GatewayBackupEnum.AMac鍚嶇О, newMacName); + } + return true; + } + + /// <summary> + /// 鏇存敼鍚嶅瓧鍚庯紝鍒锋柊璁惧缂撳瓨 + /// </summary> + /// <param name="device"></param> + private void BackupDeviceAfterReName(CommonDevice device) + { + string mainKeys = this.GetDeviceMainKeys(device); + if (this.dicAllDevice.ContainsKey(mainKeys) == false) + { + return; + } + this.dicAllDevice[mainKeys] = device; + device.ReSave(); + + //娣诲姞鑷姩澶囦唤 + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + + #endregion + + #region 鈻� 鍒犻櫎璁惧___________________________ + + /// <summary> + /// 鍒犻櫎璁惧骞朵笖鍒锋柊缂撳瓨(鍒犻櫎澶辫触鏃讹紝浼氭樉绀轰俊鎭�) + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄(MAC鍦板潃蹇呴』瑕佺浉鍚�)</param> + public async Task<bool> DeleteDevice(List<CommonDevice> listdevice) + { + var data = new CommonDevice.RemoveDeviceData(); + var info = new CommonDevice.RemoveDeviceListInfo(); + info.DeviceAddr = listdevice[0].DeviceAddr; + data.DeviceAddrList.Add(info); + + //鍒犱竴娆$殑鏃跺�欙紝瀹冧細鎶奙AC鍦板潃涓嬮潰鍏ㄩ儴鐨勮澶囬兘鍒犻櫎 + var result = await listdevice[0].DeleteDeviceAsync(data); + if (result == null || result.removeDeviceResponseData == null || result.removeDeviceResponseData.Result != 0) + { + //璁惧鍒犻櫎澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uDeviceDeleteFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + + this.ShowErrorMsg(msg); + return false; + } + + //鍒犻櫎鏂囦欢 + foreach (CommonDevice device in listdevice) + { + this.DeleteMemmoryDevice(device); + } + return true; + } + + /// <summary> + /// 鍒犻櫎缂撳瓨鐨勮澶� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="deleteRoom">鏄惁浠庢埧闂村垹闄�</param> + public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true) + { + //鍒犻櫎缂撳瓨 + string mainKeys = this.GetDeviceMainKeys(device); + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + this.dicAllDevice.Remove(mainKeys); + } + + //鍒犻櫎璁惧鏂囦欢 + string filePath = device.FilePath; + if (Global.IsExistsByHomeId(filePath) == true) + { + if (UserCenterResourse.UserInfo.AuthorityNo == 3) + { + //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� + Global.DeleteFilebyHomeId(filePath); + } + else + { + //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� + Global.DeleteFilebyHomeId(filePath); + //鍒犻櫎鑷姩澶囦唤 + HdlAutoBackupLogic.DeleteFile(device.FilePath); + } + } + + //鍒犻櫎200绔彛鏂囦欢 + string otaKeys = this.GetDeviceMainKeys(device.DeviceAddr, 200); + if (this.dicOTADevice.ContainsKey(otaKeys) == true) + { + string otaFile = this.dicOTADevice[otaKeys].FilePath; + if (Global.IsExistsByHomeId(otaFile) == true) + { + if (UserCenterResourse.UserInfo.AuthorityNo == 3) + { + //鎴愬憳鐨勮瘽,鐩存帴鍒犻櫎,娌℃湁鍟嗛噺鐨勪綑鍦� + Global.DeleteFilebyHomeId(filePath); + } + else + { + //鍙樻洿锛氭悶鎺夊畠,涓嶇暀浜� + Global.DeleteFilebyHomeId(filePath); + //鍒犻櫎鑷姩澶囦唤 + HdlAutoBackupLogic.DeleteFile(otaFile); + } + } + this.dicOTADevice.Remove(otaKeys); + } + + if (deleteRoom == true && Room.CurrentRoom != null) + { + //浠庢埧闂翠腑鍒犻櫎 + Room.CurrentRoom.DeleteDevice(device); + } + } + + #endregion + + #region 鈻� 娴嬭瘯璁惧___________________________ + + /// <summary> + /// 鍙戦�佸畾浣嶆寚浠ゅ埌璁惧 + /// </summary> + /// <param name="device"></param> + public void SetFixedPositionCommand(CommonDevice device) + { + device.IdentifyControl(device.DeviceAddr, device.DeviceEpoint, 5); + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊畾浣嶇殑鍔熻兘 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool DeviceIsCanFixedPosition(CommonDevice device) + { + foreach (var data in device.InClusterList) + { + //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� + if (data.InCluster == 3) + { + return true; + } + } + return false; + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊紑鍏崇殑鍔熻兘(杈撳嚭绨�) + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool OutDeviceIsCanOnOff(CommonDevice device) + { + foreach (var data in device.OutClusterList) + { + //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� + if (data.OutCluster == 6) + { + return true; + } + } + return false; + } + + /// <summary> + /// 妫�娴嬭澶囨槸鍚︽嫢鏈夊紑鍏崇殑鍔熻兘(杈撳叆绨�) + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool InDeviceIsCanOnOff(CommonDevice device) + { + foreach (var data in device.InClusterList) + { + //鎷ユ湁on/off鍔熻兘鐨勶紝鎵嶆敮鎸佹祴璇� + if (data.InCluster == 6) + { + return true; + } + } + return false; + } + + #endregion + + #region 鈻� 鑾峰彇璁惧___________________________ + + /// <summary> + /// 鏍规嵁缃戝叧ID鑾峰彇鎵�鏈夌殑璁惧 + /// </summary> + /// <param name="gwId">缃戝叧ID</param> + /// <returns></returns> + public List<CommonDevice> GetDeviceByGatewayID(string gwId) + { + List<CommonDevice> list = new List<CommonDevice>(); + //鍚勭綉鍏崇殑鎵�鏈夎澶� + foreach (CommonDevice device in this.dicAllDevice.Values) + { + if (gwId == device.CurrentGateWayId) + { + list.Add(device); + } + } + + return list; + } + + /// <summary> + /// 鑾峰彇鎸囧畾璁惧(涓婚敭鏄細Mac鍦板潃+绔彛鍙�),涓嶅瓨鍦ㄦ椂锛岃繑鍥瀗ull + /// </summary> + /// <param name="mainKeys">Mac鍦板潃+绔彛鍙�</param> + /// <returns></returns> + public CommonDevice GetDevice(string mainKeys) + { + if (this.dicAllDevice.ContainsKey(mainKeys) == true) + { + return this.dicAllDevice[mainKeys]; + } + return null; + } + + /// <summary> + /// 鑾峰彇鎸囧畾璁惧,涓嶅瓨鍦ㄦ椂锛岃繑鍥瀗ull + /// </summary> + /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <param name="DeviceEpoint">绔彛鍙�</param> + /// <returns></returns> + public CommonDevice GetDevice(string DeviceAddr, int DeviceEpoint) + { + string mainkeys = this.GetDeviceMainKeys(DeviceAddr, DeviceEpoint); + return this.GetDevice(mainkeys); + } + + /// <summary> + /// 鏍规嵁MAC鍦板潃,鑾峰彇鍏ㄩ儴鍥炶矾鐨勮澶囧璞�(宸茬粡鎺掑簭) + /// </summary> + /// <param name="DeviceAddr">Mac鍦板潃</param> + /// <returns></returns> + public List<CommonDevice> GetDevicesByMac(string DeviceAddr) + { + var list = new List<CommonDevice>(); + if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false) + { + return list; + } + foreach (var point in dicDeviceEpoint[DeviceAddr]) + { + var device = this.GetDevice(DeviceAddr, point); + if (device != null) + { + list.Add(device); + } + } + //鎺掑簭 + list.Sort((obj1, obj2) => + { + if (obj1.DeviceEpoint > obj2.DeviceEpoint) + { + return 1; + } + return -1; + }); + return list; + } + + /// <summary> + /// 鑾峰彇鏈湴鍏ㄩ儴鐨勮澶囨枃浠� + /// </summary> + /// <returns></returns> + public List<string> GetAllDeviceFile() + { + List<string> listDeviceFile = new List<string>(); List<string> listAllFile = Global.FileListByHomeId(); - foreach (string file in listAllFile) - { - if (file.StartsWith(deviceFirstName) == false) - { - //濡傛灉涓嶆槸璁惧鏂囦欢 - continue; - } - listDeviceFile.Add(file); - } - return listDeviceFile; - } - - /// <summary> - /// 闄勫姞璁惧鐨勭増鏈唬鍙�(杩斿洖Ver.XXX) - /// </summary> - /// <param name="versionValue">鐗堟湰鍙�</param> + foreach (string file in listAllFile) + { + if (file.StartsWith(deviceFirstName) == false) + { + //濡傛灉涓嶆槸璁惧鏂囦欢 + continue; + } + listDeviceFile.Add(file); + } + return listDeviceFile; + } + + /// <summary> + /// 鑾峰彇OTA璁惧(200绔彛鐨�) + /// </summary> + /// <param name="macAdrr"></param> + /// <param name="ePoint"></param> + /// <returns></returns> + public OTADevice GetOTADevice(string macAdrr, int ePoint = 200) + { + string mainkeys = this.GetDeviceMainKeys(macAdrr, ePoint); + if (this.dicOTADevice.ContainsKey(mainkeys) == false) + { + return null; + } + return this.dicOTADevice[mainkeys]; + } + + #endregion + + #region 鈻� 鑾峰彇璁惧鍚嶇О_______________________ + + /// <summary> + /// 鑾峰彇璁惧绔偣鐨勫悕绉�(鏈夌壒鏁�) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetDeviceEpointName(CommonDevice device) + { + string dName = this.GetSimpleEpointName(device); + if (string.IsNullOrEmpty(dName) == false) + { + return dName; + } + //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О + dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); + //濡傛灉鏄櫄鎷熻澶� + if (device.DriveCode > 0 + || (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1)) + { + var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); + dName = arry[0].Trim(); + //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� + dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; + } + return dName; + } + + /// <summary> + /// 鑾峰彇璁惧MAC鍚嶇О + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetDeviceMacName(CommonDevice device) + { + string dName = this.GetSimpleMacName(device); + if (string.IsNullOrEmpty(dName) == false) + { + return dName; + } + + //鏄惁鎷ユ湁閰嶇疆鐨勬ā鍧桰D + if (this.dicDeviceModelIdEnum.ContainsKey(device.ModelIdentifier) == true) + { + //鑾峰彇妯″潡ID鍚嶅瓧 + return this.GetNameByModelId(device); + } + else + { + //鑾峰彇绗笁鏂硅澶囩殑缈昏瘧鍚嶅瓧 + var myDeviceType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); + return Language.StringByID(myDeviceType.ConcreteTextId); + } + } + + /// <summary> + /// 鏍规嵁妯″潡ID锛岃幏鍙栫炕璇戝悕瀛� + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + private string GetNameByModelId(CommonDevice device) + { + if (device.ModelIdentifier == string.Empty) + { + //鏈煡璁惧 + return Language.StringByID(R.MyInternationalizationString.UnknowDevice); + } + + string modelKeys = device.ModelIdentifier; + if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) + { + //鏈煡璁惧 + return Language.StringByID(R.MyInternationalizationString.UnknowDevice); + } + + string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); + int ConcreteValue = Convert.ToInt32(strValue[0]); + + string keyName = deviceModelIdName + ConcreteValue; + if (this.dicDeviceDefultNameID.ContainsKey(keyName) == true) + { + //R鏂囦欢閲岄潰璁剧疆鐨勫悕瀛� + return Language.StringByID(this.dicDeviceDefultNameID[keyName]); + } + + //鏈煡璁惧 + return Language.StringByID(R.MyInternationalizationString.UnknowDevice); + } + + /// <summary> + /// 闈炲叕寮�,璁剧疆璁惧鐨凪ac鍚嶅瓧(姝ゆ柟娉曞彧鏄崟瀛樼殑鍙樻洿缂撳瓨) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="macName">Mac鍚嶅瓧</param> + /// <returns></returns> + private void SetMacName(CommonDevice device, string macName) + { + device.DeviceName = macName; + } + + /// <summary> + /// 闈炲叕寮�,璁剧疆璁惧鐨勭鐐瑰悕瀛�(姝ゆ柟娉曞彧鏄崟瀛樼殑鍙樻洿缂撳瓨) + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="epointName">绔偣鍚嶅瓧</param> + /// <returns></returns> + private void SetEpointName(CommonDevice device, string epointName) + { + device.DeviceEpointName = epointName; + } + + /// <summary> + /// 鍗曠函鑾峰彇璁惧鐨凪ac鍚嶅瓧 + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetSimpleMacName(CommonDevice device) + { + return device.DeviceName; + } + + /// <summary> + /// 鍗曠函鑾峰彇璁惧鐨勭鐐瑰悕瀛� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public string GetSimpleEpointName(CommonDevice device) + { + return device.DeviceEpointName; + } + + /// <summary> + /// 鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D + /// </summary> + private void InitDeviceDefultNameIDList() + { + if (this.dicDeviceDefultNameID != null) + { + return; + } + this.dicDeviceDefultNameID = new Dictionary<string, int>(); + Type type = typeof(R.MyInternationalizationString); + + var PropertyList = type.GetFields(); + foreach (var item in PropertyList) + { + if (item.Name.StartsWith(deviceModelIdName) == true + || item.Name.StartsWith("uDeviceBelongId") == true) + { + this.dicDeviceDefultNameID[item.Name] = Convert.ToInt32(item.GetValue(null)); + } + } + + //鍒濆鍖栬澶囨灇涓� + this.InitDeviceModelIdEnum(); + } + + #endregion + + #region 鈻� 璁剧疆鍥炬爣___________________________ + + /// <summary> + /// 鍙樻洿璁惧鐨勫浘鏍� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="unSelPath">鍥剧墖鍦板潃(闈為�夋嫨)</param> + public void ChangedDeviceIcon(CommonDevice device, string unSelPath) + { + if (unSelPath == string.Empty) + { + return; + } + device.IconPath = unSelPath; + device.IsCustomizeImage = true; + device.ReSave(); + + HdlAutoBackupLogic.AddOrEditorFile(device.FilePath); + } + + /// <summary> + /// 璁剧疆璁惧銆愬浘鏍囥�戝埌鎸囧畾鐨勬帶浠� + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="device">璁惧瀵硅薄</param> + /// <returns></returns> + public void SetDeviceIconToControl(Button btnIcon, CommonDevice device) + { + string unSelectFilePath = string.Empty; + string selectFilePath = string.Empty; + + //鑾峰彇璁惧銆愬浘鏍囥�� + this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath); + + btnIcon.UnSelectedImagePath = unSelectFilePath; + } + + /// <summary> + /// 鑾峰彇璁惧銆愬浘鏍囥�� + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <param name="unSelectPath">鍥剧墖鍦板潃</param> + /// <param name="selectPath">鍥剧墖鍦板潃</param> + /// <returns></returns> + public void GetDeviceIcon(CommonDevice device, ref string unSelectPath, ref string selectPath) + { + if (string.IsNullOrEmpty(device.IconPath) == true) + { + return; + } + unSelectPath = device.IconPath; + + string selPath = device.OnlineIconPath; + if (string.IsNullOrEmpty(selPath) == false) + { + selectPath = selPath; + } + } + + /// <summary> + /// 璁剧疆璁惧鐨勭湡瀹炲浘鐗囧埌鎸囧畾鐨勬帶浠� + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="listdevice">璁惧瀵硅薄</param> + public void SetRealDeviceIconToControl(Button btnIcon, List<CommonDevice> listdevice) + { + //鑾峰彇瀹冨睘浜庝粈涔堢被鍨嬬殑璁惧 + var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); + string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType); + string strType = strConcrete.Replace("_", string.Empty); + //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� + string imageFilePath = "RealDevice/" + strType + ".png"; + //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� + string[] arry = strConcrete.Split(new string[] { "_" }, StringSplitOptions.None); + if (arry.Length == 1) + { + //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 + return; + } + imageFilePath = "RealDevice/" + arry[0] + ".png"; + } + btnIcon.UnSelectedImagePath = imageFilePath; + } + + /// <summary> + /// 璁剧疆銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣鍒版寚瀹氱殑鎺т欢 + /// </summary> + /// <param name="btnIcon">鎺т欢瀵硅薄</param> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <returns></returns> + public void SetDeviceBeloneIconToControl(Button btnIcon, List<CommonDevice> listdevice) + { + //鑾峰彇鑷畾涔夎澶囩被鍨� + var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); + + string imageUnSelectFilePath = string.Empty; + string imageSelectFilePath = string.Empty; + + //鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 + this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath); + + //璁剧疆鍥剧墖 + btnIcon.UnSelectedImagePath = imageUnSelectFilePath; + btnIcon.SelectedImagePath = imageSelectFilePath; + } + + /// <summary> + /// 鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <param name="unSelectPath">鍥剧墖鍦板潃</param> + /// <param name="selectPath">鍥剧墖鍦板潃</param> + /// <returns></returns> + public void GetDeviceBeloneIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath) + { + //鑾峰彇鑷畾涔夎澶囩被鍨� + var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); + + //鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 + this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath); + } + + /// <summary> + /// 鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 + /// </summary> + /// <param name="specificType">鑷畾涔夎澶囩被鍨�</param> + /// <param name="unSelectPath">鍥剧墖鍦板潃</param> + /// <param name="selectPath">鍥剧墖鍦板潃</param> + /// <returns></returns> + public void GetDeviceBeloneIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath) + { + //灏嗗叿浣撶被鍨嬭浆瀛楃涓� + string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType); + string strType = strSpecific.Replace("_", string.Empty); + //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� + string imageFilePath = "Device/" + strType + ".png"; + string imageSelectFilePath = "Device/" + strType + "Selected.png"; + + //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� + if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) + { + //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� + string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None); + if (arry.Length == 1) + { + //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 + return; + } + imageFilePath = "Device/" + arry[0] + ".png"; + imageSelectFilePath = "Device/" + arry[0] + "Selected.png"; + } + //璁剧疆鍥剧墖 + unSelectPath = imageFilePath; + selectPath = imageSelectFilePath; + } + + #endregion + + #region 鈻� 璁惧UI鐩稿叧_________________________ + + /// <summary> + /// 鑾峰彇璁惧鎵�鍖归厤鐨勮澶嘦I瀵硅薄 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public DeviceUI GetDeviceUI(CommonDevice device) + { + //鍒涘缓涓�涓柊鐨勪笢瑗跨粰杩囧幓 + var deviceUi = new DeviceUI(); + deviceUi.DeviceAddr = device.DeviceAddr; + deviceUi.DeviceEpoint = device.DeviceEpoint; + return deviceUi; + } + + /// <summary> + /// 鑾峰彇璁惧鎵�鍖归厤鐨勮澶嘦I瀵硅薄 + /// </summary> + /// <param name="filePath"></param> + /// <returns></returns> + public DeviceUI GetDeviceUI(string filePath) + { + string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries); + if (arry.Length != 5) + { + return null; + } + //鍒涘缓涓�涓柊鐨勪笢瑗跨粰杩囧幓 + var deviceUi = new DeviceUI(); + deviceUi.DeviceAddr = arry[3]; + deviceUi.DeviceEpoint = Convert.ToInt32(arry[4]); + return deviceUi; + } + + #endregion + + #region 鈻� 鑾峰彇鑷畾涔夌殑璁惧绫诲瀷_______________ + + /// <summary> + /// 鑾峰彇銆愯嚜瀹氫箟鐨勮澶囩被鍨嬨��,涓ょ绫诲瀷閮借缃簡 + /// </summary> + /// <param name="listdevice">璁惧瀵硅薄</param> + /// <returns></returns> + public DeviceEnumInfo GetMyDeviceEnumInfo(List<CommonDevice> listdevice) + { + CommonDevice checkDevice = listdevice[0]; + foreach (var temp in listdevice) + { + //鎷挎嫢鏈夋ā鍧桰D鐨勯偅涓洖璺潵鍒ゆ柇 + if (temp.ModelIdentifier != string.Empty) + { + checkDevice = temp; + } + } + + //鑾峰彇娌充笢璁惧鐨勮澶囩被鍨� + DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(checkDevice); + if (info != null) + { + return info; + } + //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� + return this.GetNotHdlMyDeviceEnumInfo(listdevice); + } + + /// <summary> + /// 鑾峰彇璁惧鐨勩�愯澶囩被鍨嬨�戠殑缈昏瘧鏂囨湰(浼樺厛闀滃儚) + /// </summary> + /// <param name="listDevice"></param> + /// <param name="ApendFalge">绗笁鏂规垨鑰呰櫄鎷熻澶囩殑鏃跺�欙紝鏄惁娣诲姞鏍囪瘑</param> + /// <returns></returns> + public string GetDeviceObjectText(List<CommonDevice> listDevice, bool ApendFalge = true) + { + CommonDevice checkDevice = listDevice[0]; + foreach (var temp in listDevice) + { + //鎷挎嫢鏈夋ā鍧桰D鐨勯偅涓洖璺潵鍒ゆ柇 + if (temp.ModelIdentifier != string.Empty) + { + checkDevice = temp; + } + } + + string strName = string.Empty; + if (this.dicDeviceModelIdEnum.ContainsKey(checkDevice.ModelIdentifier) == true) + { + //鏍规嵁妯″潡ID锛岃幏鍙栬澶囧悕瀛� + strName = this.GetNameByModelId(checkDevice); + } + else + { + //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� + var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice); + strName = Language.StringByID(myDeviceType.ConcreteTextId); + } + if (ApendFalge == true && listDevice[0].DriveCode > 0) + { + //铏氭嫙璁惧鍔犱釜鏍囪瘑 + strName += "鉁�"; + } + else if (ApendFalge == true && this.IsHdlDevice(checkDevice) == false) + { + //绗笁鏂硅澶囧姞涓爣璇� + strName += "鈽�"; + } + return strName; + } + + #endregion + + #region 鈻� 鑾峰彇娌充笢璁惧鐨勮澶囩被鍨媉____________ + + /// <summary> + /// 鑾峰彇Hdl璁惧鐨勩�愯嚜瀹氫箟鐨勮澶囩被鍨嬨�� + /// </summary> + /// <param name="device">闅忎究鏌愪竴鍥炶矾</param> + /// <returns></returns> + private DeviceEnumInfo GetHdlMyDeviceEnumInfo(CommonDevice device) + { + //璁惧鍏蜂綋绫诲瀷 + var info = new DeviceEnumInfo(); + info.IsHdlDevice = this.IsHdlDevice(device); + if (device.ModelIdentifier == string.Empty) + { + return null; + } + string modelKeys = device.ModelIdentifier; + if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) + { + //娌℃湁鍖归厤鍒版ā鍧桰D锛屽垯鐩存帴璧扮涓夋柟璁惧鐨勫垽鏂� + return null; + } + + string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); + int ConcreteValue = Convert.ToInt32(strValue[0]); + int BeloneValue = Convert.ToInt32(strValue[1]); + //璁剧疆璁惧鐨勩�愯澶囨墍灞炵被鍨嬨�� + info.BeloneType = (DeviceBeloneType)BeloneValue; + if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + BeloneValue) == true) + { + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + BeloneValue]; + } + + //璁惧鍏蜂綋绫诲瀷 + info.ConcreteType = (DeviceConcreteType)ConcreteValue; + if (info.ConcreteType.ToString() == ConcreteValue.ToString()) + { + info.ConcreteType = DeviceConcreteType.UnKownDevice; + } + return info; + } + + #endregion + + #region 鈻� 鑾峰彇绗笁鏂硅澶囩殑璁惧绫诲瀷___________ + + /// <summary> + /// 鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� + /// </summary> + /// <param name="listdevice"></param> + /// <returns></returns> + public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice) + { + var dicType = new Dictionary<DeviceType, CommonDevice>(); + foreach (CommonDevice device in listdevice) + { + if (dicType.ContainsKey(device.Type) == false) + { + dicType[device.Type] = device; + } + } + var info = new DeviceEnumInfo(); + info.IsHdlDevice = false; + //1鍖呭惈闈㈡澘鐨勮瘽,褰撻潰鏉垮鐞� + if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200; + info.BeloneType = DeviceBeloneType.A鎸夐敭闈㈡澘; + info.ConcreteType = DeviceConcreteType.ButtonPanel; + } + //3鍖呭惈绐楀笜鐨勮瘽,褰撶獥甯樺鐞� + else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId100; + info.BeloneType = DeviceBeloneType.A绐楀笜; + info.ConcreteType = DeviceConcreteType.Curtain; + } + //4绌烘皵寮�鍏� + else if (dicType.ContainsKey(DeviceType.AirSwitch) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4100; + info.BeloneType = DeviceBeloneType.A绌烘皵寮�鍏�; + info.ConcreteType = DeviceConcreteType.AirSwitch; + } + //5缁х數鍣� + else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300; + info.BeloneType = DeviceBeloneType.A缁х數鍣�; + info.ConcreteType = DeviceConcreteType.Relay; + } + //6璋冨厜鍣� + else if (dicType.ContainsKey(DeviceType.DimmableLight) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2500; + info.BeloneType = DeviceBeloneType.A璋冨厜鍣�; + info.ConcreteType = DeviceConcreteType.DimmableLight; + } + //7褰╃伅 + else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId9; + info.BeloneType = DeviceBeloneType.A褰╃伅; + info.ConcreteType = DeviceConcreteType.ColorDimmableLight; + } + //8绌鸿皟 + else if (dicType.ContainsKey(DeviceType.Thermostat) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3600; + info.BeloneType = DeviceBeloneType.A绌鸿皟; + info.ConcreteType = DeviceConcreteType.AirConditioner; + } + //9涓户鍣� + else if (dicType.ContainsKey(DeviceType.Repeater) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId3900; + info.BeloneType = DeviceBeloneType.A涓户鍣�; + info.ConcreteType = DeviceConcreteType.Repeater; + } + //10杞崲鍣� + else if (dicType.ContainsKey(DeviceType.Transverter) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId4200; + info.BeloneType = DeviceBeloneType.A杞崲鍣�; + info.ConcreteType = DeviceConcreteType.Converter; + } + //11鏅鸿兘闂ㄩ攣 + else if (dicType.ContainsKey(DeviceType.DoorLock) == true) + { + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2800; + info.BeloneType = DeviceBeloneType.A鏅鸿兘闂ㄩ攣; + info.ConcreteType = DeviceConcreteType.IntelligentLocks; + } + //2鍖呭惈浼犳劅鍣ㄧ殑璇�,褰撲紶鎰熷櫒澶勭悊 + else if (dicType.ContainsKey(DeviceType.IASZone) == true) + { + //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; + this.SetSensorDeviceSpecificType(ref info, listdevice); + } + int value = (int)info.BeloneType; + if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + value) == true) + { + //璁惧鎵�灞炵被鍨嬬殑缈昏瘧鍚嶅瓧 + info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + value]; + } + + return info; + } + + #endregion + + #region 鈻� 浼犳劅鍣ㄥ叿浣撶殑绫诲瀷___________________ + + /// <summary> + /// 璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 + /// </summary> + /// <param name="info">鑷畾涔夎澶囨灇涓句俊鎭�</param> + /// <param name="listdevice">璁惧瀵硅薄</param> + private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice) + { + //榛樿鍚嶅瓧:浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200; + + //濡傛灉杩欎釜璁惧鎷ユ湁澶氫釜鍥炶矾鐨勮瘽,鎴戜篃涓嶇煡閬撴�庝箞鍛藉悕,鍙兘缁欎釜榛樿鍚嶅瓧 + if (listdevice.Count > 1) + { + return; + } + var iasZone = (IASZone)listdevice[0]; + if (iasZone.IasDeviceType == 13) + { + //杩愬姩浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_Motion; + info.ConcreteTextId = R.MyInternationalizationString.uMotionSensor; + } + else if (iasZone.IasDeviceType == 40) + { + //鐑熼浘浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_Fire; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1302; + } + else if (iasZone.IasDeviceType == 42) + { + //姘翠镜浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_Water; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1304; + } + else if (iasZone.IasDeviceType == 43) + { + //鐕冩皵浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_CarbonMonoxide; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1300; + } + else if (iasZone.IasDeviceType == 44) + { + //绱ф�ユ寜閽� + info.ConcreteType = DeviceConcreteType.Sensor_EmergencyButton; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1305; + } + else if (iasZone.IasDeviceType == 277) + { + //閽ュ寵鎵� + info.ConcreteType = DeviceConcreteType.Sensor_Keyfob; + info.ConcreteTextId = R.MyInternationalizationString.uKeyfob; + } + else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22) + { + //闂ㄧ獥浼犳劅鍣� + info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow; + info.ConcreteTextId = R.MyInternationalizationString.uDeviceModelId1301; + } + } + + #endregion + + #region 鈻� 璁惧鎺掑簭___________________________ + + /// <summary> + /// 璁惧鎺掑簭 + /// </summary> + /// <param name="listDevice">璁惧瀵硅薄</param> + /// <returns></returns> + public List<CommonDevice> SortDeviceList(List<CommonDevice> listDevice) + { + List<CommonDevice> listSort = new List<CommonDevice>(); + var list = this.SortDeviceListByRule(listDevice); + listSort.AddRange(list); + + return listSort; + } + + /// <summary> + /// + /// </summary> + /// <param name="listDevice">璁惧瀵硅薄</param> + /// <returns></returns> + private List<CommonDevice> SortDeviceListByRule(List<CommonDevice> listDevice) + { + //璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType) value锛氬瓨鏀捐澶囩殑瀹瑰櫒) + var dic = this.GetDeviceSortRule(); + foreach (CommonDevice device in listDevice) + { + if (device is IASZone) + { + //浼犳劅鍣ㄦ湁寰堝绉� + var strType = ((IASZone)device).DeviceInfo.DeviceType.ToString(); + if (dic.ContainsKey(strType) == false || dic[strType] == null) + { + dic[strType] = new List<CommonDevice>(); + } + dic[strType].Add(device); + continue; + } + string checkKeys = device.Type.ToString(); + if (dic.ContainsKey(checkKeys) == false || dic[checkKeys] == null) + { + dic[checkKeys] = new List<CommonDevice>(); + } + dic[checkKeys].Add(device); + } + + List<CommonDevice> lstSort = new List<CommonDevice>(); + foreach (var list in dic.Values) + { + if (list != null && list.Count > 0) + { + lstSort.AddRange(list); + } + } + return lstSort; + } + + /// <summary> + /// 鑾峰彇璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType) value锛氬瓨鏀捐澶囩殑瀹瑰櫒) + /// </summary> /// <returns></returns> - public string AppendVersion(int versionValue) - { - //杞负16杩涘埗 - string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0'); - //杩欎釜鏄皬鏁扮偣鍓嶉潰鐨勫�� - int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16); - //杩欎釜鏄皬鏁扮偣鍚庨潰鐨勫�� - int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16); - - //Ver. - string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation); - return ver + value1 + "." + value2.ToString().PadLeft(3, '0'); - } - - /// <summary> - /// 鑾峰彇OTA璁惧(200绔彛鐨�) - /// </summary> - /// <param name="macAdrr"></param> - /// <returns></returns> - public OTADevice GetOTADevice(string macAdrr) - { - string mainkeys = this.GetDeviceMainKeys(macAdrr, 200); - if (this.dicOTADevice.ContainsKey(mainkeys) == false) - { - return null; - } - return this.dicOTADevice[mainkeys]; - } - - #endregion - - #region 鈻� 璁惧闀滃儚(绉佹湁绫诲瀷)_________________ - - /// <summary> - /// OTA璁惧鑾峰彇闀滃儚鍚庣殑鍥炶皟鍑芥暟 - /// </summary> - private Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>> dicOtaBackAction = new Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>>(); - - /// <summary> - /// 璁剧疆璁惧鍏ㄩ儴鐨勯暅鍍忎俊鎭�(鍙嶅璋冪敤璇蜂娇鐢ㄣ�怐eviceAttributeLogic.Current.SetFirmwareVersionComand銆戝嚱鏁�) - /// </summary> - /// <param name="tADevice"></param> - /// <param name="backAction"></param> - public void SetAllImageInfoToOtaDevice(OTADevice tADevice, Action<CommonDevice, CommonDevice.DeviceStatusReportData> backAction = null) - { - if (tADevice == null) - { - return; - } - lock (objLock) - { - if (backAction != null) - { - this.dicOtaBackAction[tADevice.DeviceAddr] = backAction; - } - //璁剧疆璁惧鐨勫浐浠剁増鏈彿(闇�瑕佺瓑寰呮帹閫佸悗鎵嶄細鏇存敼) - this.SetFirmwareVersionToOtaDevice(tADevice); - } - } - - /// <summary> - /// 璁剧疆璁惧鐨勫浐浠剁増鏈彿(闇�瑕佺瓑寰呮帹閫佸悗鎵嶄細鏇存敼) - /// </summary> - /// <param name="tADevice"></param> - private void SetFirmwareVersionToOtaDevice(OTADevice tADevice) - { - if (DeviceAttributeLogic.Current.IsEsixt("DeviceAutoGetFirmwareVersion") == false) - { - //娣诲姞浜嬩欢 - DeviceAttributeLogic.Current.AddFirmwareVersionEvent("DeviceAutoGetFirmwareVersion", this.SetFirmwareVersionByInterfaceResult); - } - //鍙戦�佸懡浠� - DeviceAttributeLogic.Current.SetFirmwareVersionComand(tADevice); - } - - /// <summary> - /// 鏍规嵁鎺ュ彛鎺ㄩ�佺殑淇℃伅锛岃缃浐浠剁増鏈彿 - /// </summary> - /// <param name="device"></param> - private void SetFirmwareVersionByInterfaceResult(CommonDevice device) - { - string mainKeys = this.GetDeviceMainKeys(device); - if (this.dicOTADevice.ContainsKey(mainKeys) == false) - { - return; - } - - //璁剧疆鍥轰欢鐗堟湰淇℃伅 - DeviceAttributeLogic.Current.SetFirmwareVersion(device.DeviceStatusReport, this.dicOTADevice[mainKeys]); - this.dicOTADevice[mainKeys].ReSave(); - - lock (objLock) - { - if (this.dicOtaBackAction.ContainsKey(device.DeviceAddr) == true) - { - //璋冪敤鍥炶皟鍑芥暟 - this.dicOtaBackAction[device.DeviceAddr](device, device.DeviceStatusReport); - //鐒跺悗绉婚櫎 - this.dicOtaBackAction.Remove(device.DeviceAddr); - } - } - } - - #endregion - - #region 鈻� 璇诲彇浠ュ強璁剧疆璁惧纭欢淇℃伅___________ - - /// <summary> - /// 璁惧鑾峰彇纭欢淇℃伅鍚庣殑鍥炶皟鍑芥暟 - /// </summary> - private Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>> dicDeviceHardInfoBackAction = new Dictionary<string, Action<CommonDevice, CommonDevice.DeviceStatusReportData>>(); - /// 鑾峰彇纭欢淇℃伅鐨勫璞¤澶� - /// </summary> - private HashSet<string> hsGetHardInfoDevice = new HashSet<string>(); - - /// <summary> - /// 璇诲彇浠ュ強璁剧疆璁惧纭欢淇℃伅 - /// </summary> - /// <param name="device">璁惧鍥炶矾</param> - /// <param name="Reset">鏄惁閲嶇疆(涓嶉噸缃殑鎯呭喌鏃讹紝濡傛灉宸茬粡鏈夊�间簡锛屽垯涓嶅啀鑾峰彇)</param> - /// <param name="backAction">鍥炶皟鍑芥暟</param> - public void SetAllHardFirmwareInfoToDevice(CommonDevice device, bool Reset = false, Action<CommonDevice, CommonDevice.DeviceStatusReportData> backAction = null) - { - if (device == null) - { - return; - } - if (Reset == false) - { - if (device.ModelIdentifier != string.Empty) - { - return; - } - } - - lock (objLock) - { - string mainkeys = this.GetDeviceMainKeys(device); - this.hsGetHardInfoDevice.Add(mainkeys); - - if (backAction != null) - { - this.dicDeviceHardInfoBackAction[mainkeys] = backAction; - } - //璁剧疆璁惧鐨勭‖浠朵俊鎭�(闇�瑕佺瓑寰呮帹閫佸悗鎵嶄細鏇存敼) - this.SetHardFirmwareInfoToDevice(device); - } - } - - /// <summary> - /// 璁剧疆璁惧鐨勭‖浠朵俊鎭�(闇�瑕佺瓑寰呮帹閫佸悗鎵嶄細鏇存敼) - /// </summary> - /// <param name="device"></param> - private void SetHardFirmwareInfoToDevice(CommonDevice device) - { - if (DeviceAttributeLogic.Current.IsEsixt("DeviceGetHardFirmwareInfo") == false) - { - //娣诲姞浜嬩欢 - DeviceAttributeLogic.Current.AddFirmwareVersionEvent("DeviceGetHardFirmwareInfo", this.SetHardFirmwareInfoByInterfaceResult); - } - //鍙戦�佸懡浠� - DeviceAttributeLogic.Current.SetHardFirmwareInfoComand(device); - } - - /// <summary> - /// 鏍规嵁鎺ュ彛鎺ㄩ�佺殑淇℃伅锛岃缃澶囩‖浠朵俊鎭� - /// </summary> - /// <param name="device"></param> - private void SetHardFirmwareInfoByInterfaceResult(CommonDevice device) - { - string mainKeys = this.GetDeviceMainKeys(device); - if (this.hsGetHardInfoDevice.Contains(mainKeys) == false) - { - return; - } - //璁剧疆璁惧纭欢淇℃伅 - var localDevice = this.GetDevice(mainKeys); - if (localDevice == null) - { - return; - } - lock (objLock) - { - DeviceAttributeLogic.Current.SetHardFirmwareInfo(device.DeviceStatusReport, localDevice); - localDevice.ReSave(); - - this.hsGetHardInfoDevice.Remove(mainKeys); - if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true) - { - //璋冪敤鍥炶皟鍑芥暟 - this.dicDeviceHardInfoBackAction[mainKeys](device, device.DeviceStatusReport); - //鐒跺悗绉婚櫎 - this.dicDeviceHardInfoBackAction.Remove(mainKeys); - } - } - } - - /// <summary> - /// 绉婚櫎鑾峰彇璁惧纭欢淇℃伅鐨勭洃鍚嚎绋� - /// </summary> - /// <param name="device"></param> - public void RemoveDeviceHardInfoThread(CommonDevice device) - { - lock (objLock) - { - string mainKeys = this.GetDeviceMainKeys(device); - this.hsGetHardInfoDevice.Remove(mainKeys); - if (this.dicDeviceHardInfoBackAction.ContainsKey(mainKeys) == true) - { - //鐒跺悗绉婚櫎 - this.dicDeviceHardInfoBackAction.Remove(mainKeys); - } - } - } - - #endregion - - #region 鈻� 璁剧疆鍥炬爣___________________________ - - /// <summary> - /// 鍙樻洿璁惧鐨勫浘鏍� - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="unSelPath">鍥剧墖鍦板潃(闈為�夋嫨)</param> - public void ChangedDeviceIcon(CommonDevice device, string unSelPath) - { - if (unSelPath == string.Empty) - { - return; - } - DeviceUI deviceUI = this.GetDeviceUI(device); - deviceUI.IconPath = unSelPath; - deviceUI.IsCustomizeImage = true; - deviceUI.ReSave(); - - HdlAutoBackupLogic.AddOrEditorFile(deviceUI.FileName); - } - - /// <summary> - /// 璁剧疆璁惧銆愬浘鏍囥�戝埌鎸囧畾鐨勬帶浠� - /// </summary> - /// <param name="btnIcon">鎺т欢瀵硅薄</param> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - public void SetDeviceIconToControl(ButtonCommon btnIcon, CommonDevice device) - { - //鑾峰彇杩欎釜璁惧鐨刄I鏂囦欢 - DeviceUI deviceUI = this.GetDeviceUI(device); - if (deviceUI == null) - { - return; - } - if (string.IsNullOrEmpty(deviceUI.IconPath) == true) - { - return; - } - btnIcon.UnSelectedImagePath = deviceUI.IconPath; - - string selPath = deviceUI.OnlineIconPath; - if (string.IsNullOrEmpty(selPath) == false) - { - btnIcon.SelectedImagePath = selPath; - } - } - - /// <summary> - /// 璁剧疆璁惧鐨勩�愬ぇ鍥炬爣銆戝埌鎸囧畾鐨勬帶浠� - /// </summary> - /// <param name="btnIcon">鎺т欢瀵硅薄</param> - /// <param name="device">璁惧瀵硅薄</param> - public void SetDeviceBigIconToControl(ButtonCommon btnIcon, CommonDevice device) - { - //鑾峰彇杩欎釜璁惧鐨刄I鏂囦欢 - DeviceUI deviceUI = this.GetDeviceUI(device); - if (deviceUI == null) - { - return; - } - string deviceIcon = deviceUI.OnlineIconPath; - if (string.IsNullOrEmpty(deviceIcon) == true) - { - return; - } - - //鎸夐敭闈㈡澘鐨勫洖璺浘鏍� - if (deviceIcon == "Device/DryContactSelected.png") - { - //鍥犱负鎸夐敭闈㈡澘鏄竴涓偣锛屾墍浠ラ渶瑕佺壒娈婂鐞� - this.SetDeviceBeloneIconToControl(btnIcon, new List<CommonDevice>() { device }); - btnIcon.UnSelectedImagePath = btnIcon.SelectedImagePath; - btnIcon.SelectedImagePath = null; - } - else - { - //杩欓噷鏄嚜瀹氫箟鍥炬爣 - btnIcon.UnSelectedImagePath = deviceIcon; - } - } - - /// <summary> - /// 璁剧疆璁惧鐨勭湡瀹炲浘鐗囧埌鎸囧畾鐨勬帶浠� - /// </summary> - /// <param name="btnIcon">鎺т欢瀵硅薄</param> - /// <param name="listdevice">璁惧瀵硅薄</param> - public void SetRealDeviceIconToControl(ButtonCommon btnIcon, List<CommonDevice> listdevice) - { - //鑾峰彇瀹冨睘浜庝粈涔堢被鍨嬬殑璁惧 - var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); - string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType); - string strType = strConcrete.Replace("_", string.Empty); - //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� - string imageFilePath = "RealDevice/" + strType + ".png"; - //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� - if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) - { - //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� - string[] arry = strConcrete.Split(new string[] { "_" }, StringSplitOptions.None); - if (arry.Length == 1) - { - //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 - return; - } - imageFilePath = "RealDevice/" + arry[1] + ".png"; - } - btnIcon.UnSelectedImagePath = imageFilePath; - } - - /// <summary> - /// 璁剧疆銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣鍒版寚瀹氱殑鎺т欢 - /// </summary> - /// <param name="btnIcon">鎺т欢瀵硅薄</param> - /// <param name="listdevice">璁惧瀵硅薄</param> - /// <returns></returns> - public void SetDeviceBeloneIconToControl(ButtonCommon btnIcon, List<CommonDevice> listdevice) - { - //鑾峰彇鑷畾涔夎澶囩被鍨� - var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); - - string imageUnSelectFilePath = string.Empty; - string imageSelectFilePath = string.Empty; - - //鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 - this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref imageUnSelectFilePath, ref imageSelectFilePath); - - //璁剧疆鍥剧墖 - btnIcon.UnSelectedImagePath = imageUnSelectFilePath; - btnIcon.SelectedImagePath = imageSelectFilePath; - } - - /// <summary> - /// 鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 - /// </summary> - /// <param name="listdevice">璁惧瀵硅薄</param> - /// <param name="unSelectPath">鍥剧墖鍦板潃</param> - /// <param name="selectPath">鍥剧墖鍦板潃</param> - /// <returns></returns> - public void GetDeviceBeloneIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath) - { - //鑾峰彇鑷畾涔夎澶囩被鍨� - var myDeviceType = this.GetMyDeviceEnumInfo(listdevice); - - //鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 - this.GetDeviceBeloneIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath); - } - - /// <summary> - /// 鑾峰彇銆愯澶囨墍灞炵被鍨嬨�戠殑鍥炬爣 - /// </summary> - /// <param name="specificType">鑷畾涔夎澶囩被鍨�</param> - /// <param name="unSelectPath">鍥剧墖鍦板潃</param> - /// <param name="selectPath">鍥剧墖鍦板潃</param> - /// <returns></returns> - private void GetDeviceBeloneIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath) - { - //灏嗗叿浣撶被鍨嬭浆瀛楃涓� - string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType); - string strType = strSpecific.Replace("_", string.Empty); - //灏嗙被鍨嬭浆涓哄浘鐗囧湴鍧� - string imageFilePath = "Device/" + strType + ".png"; - string imageSelectFilePath = "Device/" + strType + "Selected.png"; - - //杩欎釜鍥剧墖鏈湴鏄惁瀛樺湪锛� - if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true) - { - //涓嶅瓨鍦ㄥ垯浣跨敤鍏遍�氬浘鐗� - string[] arry = strSpecific.Split(new string[] { "_" }, StringSplitOptions.None); - if (arry.Length == 1) - { - //濡傛灉瀹冭嚜宸卞氨鏄叡閫氬浘鐗囩殑璇濓紝涓嶅啀澶勭悊 - return; - } - imageFilePath = "Device/" + arry[1] + ".png"; - imageSelectFilePath = "Device/" + arry[1] + "Selected.png"; - } - //璁剧疆鍥剧墖 - unSelectPath = imageFilePath; - selectPath = imageSelectFilePath; - } - - #endregion - - #region 鈻� 璁惧UI鐩稿叧_________________________ - - /// <summary> - /// 鑾峰彇璁惧鎵�鍖归厤鐨勮澶嘦I瀵硅薄 - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public DeviceUI GetDeviceUI(CommonDevice device) - { - return this.GetDeviceUI("DeviceUI_" + device.FilePath); - } - - /// <summary> - /// 鑾峰彇璁惧鎵�鍖归厤鐨勮澶嘦I瀵硅薄 - /// </summary> - /// <param name="filePath"></param> - /// <returns></returns> - public DeviceUI GetDeviceUI(string filePath) - { - if (this.dicAllDeviceUI.ContainsKey(filePath) == true) - { - return this.dicAllDeviceUI[filePath]; - } - - var deviceUi = new DeviceUI(); - deviceUi.DeviceFileName = filePath.Replace("DeviceUI_", string.Empty); - deviceUi.ReSave(); - this.dicAllDeviceUI[filePath] = deviceUi; - return deviceUi; - } - - /// <summary> - /// 浠庢枃浠朵腑鑾峰彇鎸囧畾璁惧鐨刄I瀵硅薄(鏈夊彲鑳借繑鍥瀗ull) - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - private DeviceUI GetDeviceUIFromLocalFile(CommonDevice device) - { - DeviceUI deviceUI = new DeviceUI(); - deviceUI.DeviceFileName = device.FilePath; - - if (Global.IsExistsByHomeId(deviceUI.FileName) == false) - { - return null; - } - var jsonInfo = Encoding.UTF8.GetString(Global.ReadFileByHomeId(deviceUI.FileName)); - var tempCommon = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceUI>(jsonInfo); - return tempCommon; - } - - #endregion - - #region 鈻� 鑾峰彇鑷畾涔夌殑璁惧绫诲瀷_______________ - - /// <summary> - /// 鑾峰彇銆愯嚜瀹氫箟鐨勮澶囩被鍨嬨��,涓ょ绫诲瀷閮借缃簡 - /// </summary> - /// <param name="listdevice">璁惧瀵硅薄</param> - /// <returns></returns> - public DeviceEnumInfo GetMyDeviceEnumInfo(List<CommonDevice> listdevice) - { - //鑾峰彇娌充笢璁惧鐨勮澶囩被鍨� - DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(listdevice[0]); - if (info != null) - { - return info; - } - //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� - return this.GetNotHdlMyDeviceEnumInfo(listdevice); - } - - /// <summary> - /// 鑾峰彇璁惧鐨勩�愯澶囩被鍨嬨�戠殑缈昏瘧鏂囨湰(浼樺厛闀滃儚) - /// </summary> - /// <param name="listDevice"></param> - /// <param name="ApendFalge">绗笁鏂规垨鑰呰櫄鎷熻澶囩殑鏃跺�欙紝鏄惁娣诲姞鏍囪瘑</param> - /// <returns></returns> - public string GetDeviceObjectText(List<CommonDevice> listDevice, bool ApendFalge = true) - { - string strName = string.Empty; - if (this.dicDeviceModelIdEnum.ContainsKey(listDevice[0].ModelIdentifier) == true) - { - //鏍规嵁妯″潡ID锛岃幏鍙栬澶囧悕瀛� - strName = this.GetNameByModelId(listDevice[0]); - } - else - { - //鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� - var myDeviceType = this.GetNotHdlMyDeviceEnumInfo(listDevice); - strName = Language.StringByID(myDeviceType.TextId); - } - if (ApendFalge == true && listDevice[0].DriveCode > 0) - { - //铏氭嫙璁惧鍔犱釜鏍囪瘑 - strName += "鉁�"; - } - else if (ApendFalge == true && this.IsHdlDevice(listDevice[0]) == false) - { - //绗笁鏂硅澶囧姞涓爣璇� - strName += "鈽�"; - } - return strName; - } - - #endregion - - #region 鈻� 鑾峰彇娌充笢璁惧鐨勮澶囩被鍨媉____________ - - /// <summary> - /// 鑾峰彇Hdl璁惧鐨勩�愯嚜瀹氫箟鐨勮澶囩被鍨嬨�� - /// </summary> - /// <param name="device">闅忎究鏌愪竴鍥炶矾</param> - /// <returns></returns> - private DeviceEnumInfo GetHdlMyDeviceEnumInfo(CommonDevice device) - { - //璁惧鍏蜂綋绫诲瀷 - var info = new DeviceEnumInfo(); - info.IsHdlDevice = this.IsHdlDevice(device); - if (device.ModelIdentifier == string.Empty) - { - return null; - } - string modelKeys = device.ModelIdentifier; - if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) - { - //娌℃湁鍖归厤鍒版ā鍧桰D锛屽垯鐩存帴璧扮涓夋柟璁惧鐨勫垽鏂� - return null; - } - - string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); - int ConcreteValue = Convert.ToInt32(strValue[0]); - int BeloneValue = Convert.ToInt32(strValue[1]); - - //璁惧鍏蜂綋绫诲瀷 - info.ConcreteType = (DeviceConcreteType)ConcreteValue; - if (info.ConcreteType.ToString() == ConcreteValue.ToString()) - { - info.ConcreteType = DeviceConcreteType.UnKownDevice; - return info; - } - - //璁剧疆璁惧鐨勩�愯澶囨墍灞炵被鍨嬨�� - info.BeloneType = (DeviceBeloneType)BeloneValue; - - return info; - } - - #endregion - - #region 鈻� 鑾峰彇绗笁鏂硅澶囩殑璁惧绫诲瀷___________ - - /// <summary> - /// 鑾峰彇绗笁鏂硅澶囩殑銆愯澶囩被鍨嬨�� - /// </summary> - /// <param name="listdevice"></param> - /// <returns></returns> - private DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice) - { - var dicType = new Dictionary<DeviceType, CommonDevice>(); - foreach (CommonDevice device in listdevice) - { - if (dicType.ContainsKey(device.Type) == false) - { - dicType[device.Type] = device; - } - } - var info = new DeviceEnumInfo(); - info.IsHdlDevice = false; - //1鍖呭惈闈㈡澘鐨勮瘽,褰撻潰鏉垮鐞� - if (dicType.ContainsKey(DeviceType.OnOffSwitch) == true) - { - info.TextId = R.MyInternationalizationString.uButtonControl; - info.BeloneType = DeviceBeloneType.A鎸夐敭闈㈡澘; - info.ConcreteType = DeviceConcreteType.ButtonPanel; - } - //2鍖呭惈浼犳劅鍣ㄧ殑璇�,褰撲紶鎰熷櫒澶勭悊 - else if (dicType.ContainsKey(DeviceType.IASZone) == true) - { - //璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 - info.BeloneType = DeviceBeloneType.A浼犳劅鍣�; - this.SetSensorDeviceSpecificType(ref info, listdevice); - } - //3鍖呭惈绐楀笜鐨勮瘽,褰撶獥甯樺鐞� - else if (dicType.ContainsKey(DeviceType.WindowCoveringDevice) == true) - { - info.TextId = R.MyInternationalizationString.uCurtain; - info.BeloneType = DeviceBeloneType.A绐楀笜; - info.ConcreteType = DeviceConcreteType.Curtain; - } - //4绌烘皵寮�鍏� - else if (dicType.ContainsKey(DeviceType.AirSwitch) == true) - { - info.TextId = R.MyInternationalizationString.uAirSwitch; - info.BeloneType = DeviceBeloneType.A绌烘皵寮�鍏�; - info.ConcreteType = DeviceConcreteType.AirSwitch; - } - //5缁х數鍣� - else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true) - { - info.TextId = R.MyInternationalizationString.uRelay; - info.BeloneType = DeviceBeloneType.A缁х數鍣�; - info.ConcreteType = DeviceConcreteType.Relay; - } - //6璋冨厜鍣� - else if (dicType.ContainsKey(DeviceType.DimmableLight) == true) - { - info.TextId = R.MyInternationalizationString.uDimmableLight; - info.BeloneType = DeviceBeloneType.A璋冨厜鍣�; - info.ConcreteType = DeviceConcreteType.DimmableLight; - } - //7褰╃伅 - else if (dicType.ContainsKey(DeviceType.ColorDimmableLight) == true) - { - info.TextId = R.MyInternationalizationString.uColorDimmableLight; - info.BeloneType = DeviceBeloneType.A褰╃伅; - info.ConcreteType = DeviceConcreteType.ColorDimmableLight; - } - //8绌鸿皟 - else if (dicType.ContainsKey(DeviceType.Thermostat) == true) - { - info.TextId = R.MyInternationalizationString.Thermostat; - info.BeloneType = DeviceBeloneType.A绌鸿皟; - info.ConcreteType = DeviceConcreteType.AirConditioner; - } - //9涓户鍣� - else if (dicType.ContainsKey(DeviceType.Repeater) == true) - { - info.TextId = R.MyInternationalizationString.Repeater; - info.BeloneType = DeviceBeloneType.A涓户鍣�; - info.ConcreteType = DeviceConcreteType.Repeater; - } - //10杞崲鍣� - else if (dicType.ContainsKey(DeviceType.Transverter) == true) - { - info.TextId = R.MyInternationalizationString.uConverter; - info.BeloneType = DeviceBeloneType.A杞崲鍣�; - info.ConcreteType = DeviceConcreteType.Converter; - } - return info; - } - - #endregion - - #region 鈻� 浼犳劅鍣ㄥ叿浣撶殑绫诲瀷___________________ - - /// <summary> - /// 璁剧疆浼犳劅鍣ㄥ叿浣撶殑绫诲瀷 - /// </summary> - /// <param name="info">鑷畾涔夎澶囨灇涓句俊鎭�</param> - /// <param name="listdevice">璁惧瀵硅薄</param> - private void SetSensorDeviceSpecificType(ref DeviceEnumInfo info, List<CommonDevice> listdevice) - { - //榛樿鍚嶅瓧:浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.Sensor; - info.TextId = R.MyInternationalizationString.uSensor; - - //濡傛灉杩欎釜璁惧鎷ユ湁澶氫釜鍥炶矾鐨勮瘽,鎴戜篃涓嶇煡閬撴�庝箞鍛藉悕,鍙兘缁欎釜榛樿鍚嶅瓧 - if (listdevice.Count > 1) - { - return; - } - var iasZone = (IASZone)listdevice[0]; - if (iasZone.IasDeviceType == 13) - { - //杩愬姩浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.Motion_Sensor; - info.TextId = R.MyInternationalizationString.uMotionSensor; - } - else if (iasZone.IasDeviceType == 40) - { - //鐑熼浘浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.Fire_Sensor; - info.TextId = R.MyInternationalizationString.uDeviceDefultName1302; - } - else if (iasZone.IasDeviceType == 42) - { - //姘翠镜浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.Water_Sensor; - info.TextId = R.MyInternationalizationString.uDeviceDefultName1304; - } - else if (iasZone.IasDeviceType == 43) - { - //鐕冩皵浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.CarbonMonoxide_Sensor; - info.TextId = R.MyInternationalizationString.uDeviceDefultName1300; - } - else if (iasZone.IasDeviceType == 44) - { - //绱ф�ユ寜閽� - info.ConcreteType = DeviceConcreteType.EmergencyButton_Sensor; - info.TextId = R.MyInternationalizationString.uDeviceDefultName1305; - } - else if (iasZone.IasDeviceType == 277) - { - //閽ュ寵鎵� - info.ConcreteType = DeviceConcreteType.Keyfob_Sensor; - info.TextId = R.MyInternationalizationString.uKeyfob; - } - else if (iasZone.IasDeviceType == 21 || iasZone.IasDeviceType == 22) - { - //闂ㄧ獥浼犳劅鍣� - info.ConcreteType = DeviceConcreteType.DoorWindowSensor_Sensor; - info.TextId = R.MyInternationalizationString.uDeviceDefultName1301; - } - } - - #endregion - - #region 鈻� 鑾峰彇璁惧鍚嶇О_______________________ - - /// <summary> - /// 鑾峰彇璁惧绔偣鐨勫悕绉�(鏈夌壒鏁�) - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - public string GetDeviceEpointName(CommonDevice device) - { - string dName = this.GetSimpleEpointName(device); - if (string.IsNullOrEmpty(dName) == false) - { - return dName; - } - //鏍规嵁璁惧绫诲瀷鑾峰彇鍚嶇О - dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false); - //濡傛灉鏄櫄鎷熻澶� - if (device.DriveCode > 0 - || (this.dicDeviceCount.ContainsKey(device.DeviceAddr) == true && this.dicDeviceCount[device.DeviceAddr].Count > 1)) - { - var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries); - dName = arry[0].Trim(); - //鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍� - dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")"; - } - return dName; - } - - /// <summary> - /// 鑾峰彇璁惧MAC鍚嶇О - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - public string GetDeviceMacName(CommonDevice device) - { - string dName = this.GetSimpleMacName(device); - if (string.IsNullOrEmpty(dName) == false) - { - return dName; - } - - //鏄惁鎷ユ湁閰嶇疆鐨勬ā鍧桰D - if (this.dicDeviceModelIdEnum.ContainsKey(device.ModelIdentifier) == true) - { - //鑾峰彇妯″潡ID鍚嶅瓧 - return this.GetNameByModelId(device); - } - else - { - //鑾峰彇绗笁鏂硅澶囩殑缈昏瘧鍚嶅瓧 - var myDeviceType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device }); - return Language.StringByID(myDeviceType.TextId); - } - } - - /// <summary> - /// 鍦ㄧ鐐瑰悕瀛楃殑鍚庨潰闄勫姞銆愬洖璺�戝瓧鏍�,杩斿洖鏍煎紡锛歑XXX(NN鍥炶矾),濡傛灉娌℃湁鍚嶅瓧锛屽垯杩斿洖锛歂N鍥炶矾 - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - public string AppendRoadTextToEpointName(CommonDevice device) - { - string pName = this.GetSimpleEpointName(device); - //鍥炶矾 - string txtValue = Language.StringByID(R.MyInternationalizationString.uDeviceCircuit); - if (string.IsNullOrEmpty(pName) == true) - { - //NN鍥炶矾 - return device.DeviceEpoint + txtValue; - } - else if (pName.Trim().EndsWith(txtValue) == true) - { - return pName; - } - //XXXX(NN鍥炶矾) - return pName + "(" + device.DeviceEpoint + txtValue + ")"; - } - - /// <summary> - /// 鏍规嵁妯″潡ID锛岃幏鍙栫炕璇戝悕瀛� - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public string GetNameByModelId(CommonDevice device) - { - if (device.ModelIdentifier == string.Empty) - { - //鏈煡璁惧 - return Language.StringByID(R.MyInternationalizationString.UnknowDevice); - } - - string modelKeys = device.ModelIdentifier; - if (this.dicDeviceModelIdEnum.ContainsKey(modelKeys) == false) - { - //鏈煡璁惧 - return Language.StringByID(R.MyInternationalizationString.UnknowDevice); - } - - string[] strValue = this.dicDeviceModelIdEnum[modelKeys].Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); - int ConcreteValue = Convert.ToInt32(strValue[0]); - - string keyName = deviceDefultNameFlag + ConcreteValue; - if (this.dicDeviceDefultNameID.ContainsKey(keyName) == true) - { - //R鏂囦欢閲岄潰璁剧疆鐨勫悕瀛� - return Language.StringByID(this.dicDeviceDefultNameID[keyName]); - } - - //鏈煡璁惧 - return Language.StringByID(R.MyInternationalizationString.UnknowDevice); - } - - /// <summary> - /// 闈炲叕寮�,璁剧疆璁惧鐨凪ac鍚嶅瓧(姝ゆ柟娉曞彧鏄崟瀛樼殑鍙樻洿缂撳瓨) - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="macName">Mac鍚嶅瓧</param> - /// <returns></returns> - private void SetMacName(CommonDevice device, string macName) - { - device.DeviceName = macName; - } - - /// <summary> - /// 闈炲叕寮�,璁剧疆璁惧鐨勭鐐瑰悕瀛�(姝ゆ柟娉曞彧鏄崟瀛樼殑鍙樻洿缂撳瓨) - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="epointName">绔偣鍚嶅瓧</param> - /// <returns></returns> - private void SetEpointName(CommonDevice device, string epointName) - { - device.DeviceEpointName = epointName; - } - - /// <summary> - /// 鍗曠函鑾峰彇璁惧鐨凪ac鍚嶅瓧 - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - public string GetSimpleMacName(CommonDevice device) - { - return device.DeviceName; - } - - /// <summary> - /// 鍗曠函鑾峰彇璁惧鐨勭鐐瑰悕瀛� - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <returns></returns> - public string GetSimpleEpointName(CommonDevice device) - { - return device.DeviceEpointName; - } - - /// <summary> - /// 鍒濆鍖朢鏂囦欢閲岄潰璁惧榛樿鍚嶅瓧鐨処D - /// </summary> - private void InitDeviceDefultNameIDList() - { - if (this.dicDeviceDefultNameID != null) - { - return; - } - this.dicDeviceDefultNameID = new Dictionary<string, int>(); - Type type = typeof(R.MyInternationalizationString); - - var PropertyList = type.GetFields(); - foreach (var item in PropertyList) - { - if (item.Name.StartsWith(deviceDefultNameFlag) == true) - { - this.dicDeviceDefultNameID[item.Name] = Convert.ToInt32(item.GetValue(null)); - } - } - - //鍒濆鍖栬澶囨灇涓� - this.InitDeviceModelIdEnum(); - } - - #endregion - - #region 鈻� 璁惧鎺掑簭___________________________ - - /// <summary> - /// 璁惧鎺掑簭 - /// </summary> - /// <param name="listDevice">璁惧瀵硅薄</param> - /// <returns></returns> - public List<CommonDevice> SortDeviceList(List<CommonDevice> listDevice) - { - List<CommonDevice> listSort = new List<CommonDevice>(); - var list = this.SortDeviceListByRule(listDevice); - listSort.AddRange(list); - - return listSort; - } - - /// <summary> - /// - /// </summary> - /// <param name="listDevice">璁惧瀵硅薄</param> - /// <returns></returns> - private List<CommonDevice> SortDeviceListByRule(List<CommonDevice> listDevice) - { - //璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType) value锛氬瓨鏀捐澶囩殑瀹瑰櫒) - var dic = this.GetDeviceSortRule(); - dic["瀵硅薄澶�"] = new List<CommonDevice>(); - foreach (CommonDevice device in listDevice) - { - if (device is IASZone) - { - var iasZone = (IASZone)device; - //杩愬姩浼犳劅鍣� - if (iasZone.DeviceInfo.DeviceType == 13) - { - dic["杩愬姩浼犳劅鍣�"].Add(device); - } - //涓�姘у寲纰充紶鎰熷櫒 - else if (iasZone.DeviceInfo.DeviceType == 43) - { - dic["涓�姘у寲纰充紶鎰熷櫒"].Add(device); - } - //绱ф�ユ寜閽� - else if (iasZone.DeviceInfo.DeviceType == 44) - { - dic["绱ф�ユ寜閽�"].Add(device); - } - else - { - dic[DeviceType.IASZone.ToString()].Add(device); - } - continue; - } - - string checkKeys = device.Type.ToString(); - if (dic.ContainsKey(checkKeys) == true) - { - dic[checkKeys].Add(device); - } - else - { - dic["瀵硅薄澶�"].Add(device); - } - } - List<CommonDevice> lstSort = new List<CommonDevice>(); - foreach (var list in dic.Values) - { - lstSort.AddRange(list); - } - return lstSort; - } - - /// <summary> - /// 鑾峰彇璁惧鎺掑簭鐨勮鍒�(Keys锛氳澶囩被鍨�(DeviceType) value锛氬瓨鏀捐澶囩殑瀹瑰櫒) - /// </summary> - /// <returns></returns> - private Dictionary<string, List<CommonDevice>> GetDeviceSortRule() - { - var dic = new Dictionary<string, List<CommonDevice>>(); - //涓�姘у寲纰充紶鎰熷櫒 - dic["涓�姘у寲纰充紶鎰熷櫒"] = new List<CommonDevice>(); - //绱ф�ユ寜閽� - dic["绱ф�ユ寜閽�"] = new List<CommonDevice>(); - //杩愬姩浼犳劅鍣� - dic["杩愬姩浼犳劅鍣�"] = new List<CommonDevice>(); - //浼犳劅鍣� - dic[DeviceType.IASZone.ToString()] = new List<CommonDevice>(); - //鎺у埗闈㈡澘 - dic[DeviceType.OnOffSwitch.ToString()] = new List<CommonDevice>(); - //缁х數鍣� - dic[DeviceType.OnOffOutput.ToString()] = new List<CommonDevice>(); - //鍗峰笜 - dic[DeviceType.WindowCoveringDevice.ToString()] = new List<CommonDevice>(); - //璋冨厜鐏� - dic[DeviceType.ColorDimmableLight.ToString()] = new List<CommonDevice>(); - //绌烘皵寮�鍏� - dic[DeviceType.AirSwitch.ToString()] = new List<CommonDevice>(); - - return dic; - } - - #endregion - - #region 鈻� 璁惧鐩爣缁戝畾_______________________ - - /// <summary> - /// 鑾峰彇璁惧涓嬮潰缁戝畾鐨勮澶�(閿欒鏃惰繑鍥瀗ull) - /// </summary> - /// <param name="mainDevice">璁惧瀵硅薄</param> - /// <returns></returns> - public async Task<List<CommonDevice>> GetBindTargetDevice(CommonDevice mainDevice) - { - var result = (BindObj.GetDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "GetDeviceBindAsync"); - if (result == null || result.getAllBindResponseData == null) - { - //鑾峰彇璁惧鐨勭粦瀹氱洰鏍囧け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceBindTargetFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return null; - } - var listDevice = new List<CommonDevice>(); - foreach (var data in result.getAllBindResponseData.BindList) - { - CommonDevice deviceTemp = this.GetDevice(data.BindMacAddr, data.BindEpoint); - if (deviceTemp == null) - { - continue; - } - listDevice.Add(deviceTemp); - } - return listDevice; - } - - /// <summary> - /// 缁戝畾璁惧鐨勭洰鏍�(杩斿洖鎴愬姛璁剧疆鐨勮澶�,閿欒鏃讹紝杩斿洖null) - /// </summary> - /// <param name="mainDevice">璁惧瀵硅薄</param> - /// <param name="listDevice">瑕佺粦瀹氱殑鐩爣璁惧</param> - /// <param name="BindCluster">瑕佺粦瀹氱殑鐩爣璁惧</param> - /// <returns></returns> - public async Task<List<CommonDevice>> BindDeviceTarget(CommonDevice mainDevice, List<CommonDevice> listDevice, int BindCluster = 6) - { - if (listDevice.Count == 0) - { - return new List<CommonDevice>(); - } - - var dicDevice = new Dictionary<string, CommonDevice>(); - - //缁勮鏁版嵁 - var addData = new IASZone.AddBindData(); - addData.DeviceAddr = mainDevice.DeviceAddr; - addData.Epoint = mainDevice.DeviceEpoint; - foreach (var device in listDevice) - { - var info = new IASZone.AddBindListObj(); - info.BindCluster = BindCluster; - info.BindMacAddr = device.DeviceAddr; - info.BindEpoint = device.DeviceEpoint; - info.BindType = 0; - - addData.BindList.Add(info); - - //杩斿洖鎴愬姛璁惧鐨勬椂鍊欎娇鐢� - string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device); - dicDevice[mainkeys] = device; - } - - var result = (BindObj.AddedDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "AddDeviceBindAsync", addData); - if (result == null || result.addedDeviceBindResponseData == null) - { - //缁戝畾鐩爣璁剧疆澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uSetBindTargetsFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return null; - } - - var listSuccess = new List<CommonDevice>(); - foreach (var data in result.addedDeviceBindResponseData.BindList) - { - string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.BindMacAddr, data.BindEpoint); - //0:娣诲姞鎴愬姛 3:宸茬粡瀛樺湪锛屼篃鍙互浠h〃鎴愬姛 - if (data.Result == 0 || data.Result == 3) - { - if (dicDevice.ContainsKey(mainkeys) == true) - { - listSuccess.Add(dicDevice[mainkeys]); - } - } - //1锛氬け璐ワ紝鑺傜偣璁惧鎴栧満鏅笉瀛樺湪 - else if (data.Result == 1) - { - if (dicDevice.ContainsKey(mainkeys) == true) - { - //璁惧鍚嶇О 缁戝畾澶辫触 - string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; - msg += Language.StringByID(R.MyInternationalizationString.BindFailed); - this.ShowTipMsg(msg); - } - } - //2锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔� - else if (data.Result == 2) - { - if (result.addBindResultResponseData == null) - { - //璁惧鍚嶇О 缁戝畾澶辫触 - string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; - msg += Language.StringByID(R.MyInternationalizationString.BindFailed); - this.ShowTipMsg(msg); - } - else - { - //娣诲姞鎴愬姛 - if (result.addBindResultResponseData.Result == 0) - { - if (dicDevice.ContainsKey(mainkeys) == true) - { - listSuccess.Add(dicDevice[mainkeys]); - } - } - //璁惧鍚嶇О 缁戝畾鍒楄〃宸叉弧 - else if (result.addBindResultResponseData.Result == 140) - { - string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; - msg += Language.StringByID(R.MyInternationalizationString.uBindListIsFull); - this.ShowTipMsg(msg); - } - else - { - //璁惧鍚嶇О 缁戝畾澶辫触 - string msg = this.GetDeviceEpointName(dicDevice[mainkeys]) + "\r\n"; - msg += Language.StringByID(R.MyInternationalizationString.BindFailed); - this.ShowTipMsg(msg); - } - } - } - } - - return listSuccess; - } - - /// <summary> - /// 鍒犻櫎璁惧缁戝畾鐨勭洰鏍� - /// </summary> - /// <param name="mainDevice">璁惧瀵硅薄</param> - /// <param name="deleteDevice">瑕佸垹闄ょ殑缁戝畾鐩爣璁惧</param> - /// <param name="BindCluster">瑕佺粦瀹氱殑鐩爣璁惧</param> - /// <returns></returns> - public async Task<bool> DeleteDeviceTarget(CommonDevice mainDevice, CommonDevice deleteDevice, int BindCluster = 6) - { - //缁勮鏁版嵁 - var deleteData = new IASZone.DelDeviceBindData(); - deleteData.DeviceAddr = mainDevice.DeviceAddr; - deleteData.Epoint = mainDevice.DeviceEpoint; - - var info = new IASZone.RemoveBindListObj(); - info.BindCluster = 6; - info.BindMacAddr = deleteDevice.DeviceAddr; - info.BindEpoint = deleteDevice.DeviceEpoint; - info.BindType = 0; - - deleteData.RemoveBindList.Add(info); - - var result = (BindObj.DelDeviceBindResponseAllData)await this.LoadDeviceMethodByNameAsync(mainDevice, "DelDeviceBindAsync", deleteData); - if (result == null || result.delDeviceBindResponseData == null) - { - //鍒犻櫎缁戝畾鐩爣澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return false; - } - - foreach (var data in result.delDeviceBindResponseData.RemoveBindList) - { - //0:鎴愬姛 1:璁惧涓嶅湪缁戝畾鍒楄〃涓� 锛屼篃鍙互浠h〃鎴愬姛 - if (data.Result == 0 || data.Result == 1) - { - return true; - } - //3:澶辫触锛屽湪绛夊緟鑺傜偣璁惧纭鏄惁瑙i櫎缁戝畾鎴愬姛 - else if (data.Result == 3) - { - //鍏朵粬缁戝畾鐩爣姝e湪鍒犻櫎涓紝璇风◢鍚庡啀璇� - string msg = Language.StringByID(R.MyInternationalizationString.uOtherBindTargetsIsDelettingPleaseWait); - this.ShowErrorMsg(msg); - return false; - } - //4锛氭湭鐭ワ紝鐢辫妭鐐硅澶囧弽棣堝彂閫佲�淏ind/BindResult鈥濅富棰樻秷鎭‘瀹氭槸鍚︽垚鍔� - else if (data.Result == 4) - { - if (result.removeBindResultResponseData == null) - { - //鍒犻櫎缁戝畾鐩爣澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); - this.ShowErrorMsg(msg); - return false; - } - else - { - //鎴愬姛 - if (result.removeBindResultResponseData.Result == 0) - { - return true; - } - //136锛氭帶鍒惰澶囨湰鍦扮粦瀹氬垪琛ㄤ腑鏃犳缁戝畾 - else if (result.removeBindResultResponseData.Result == 136) - { - //杩欎釜鍙互褰撳仛鎴愬姛 - return true; - } - else - { - //鍒犻櫎缁戝畾鐩爣澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uDeleteBindTargetsFail); - this.ShowErrorMsg(msg); - return false; - } - } - } - } - return false; - } - - /// <summary> - /// 鎵ц鎸囧畾璁惧瀵硅薄绫婚噷闈㈢殑鏂规硶(娉ㄦ剰锛氳繖涓槸涓撻棬璋冪敤寮傛锛屽苟涓旂瓑寰呭紓姝ュ畬鎴愮殑楂樼鎶�鍑芥暟,涓嶈皟鐢ㄥ紓姝ョ殑鎯呭喌锛屽埆浣跨敤姝ゅ嚱鏁�) - /// </summary> - /// <param name="device">闇�瑕佹墽琛岀殑璁惧鐨勮澶囧璞�</param> - /// <param name="method">鎸囧畾瑕佸姞杞界殑鏂规硶鍚�</param> - /// <param name="parameter">鍚姩鍙傛暟</param> - private async Task<object> LoadDeviceMethodByNameAsync(CommonDevice device, string method, params object[] parameter) - { - var task = device.GetType().InvokeMember(method, System.Reflection.BindingFlags.InvokeMethod, null, device, parameter) as Task; - await task; - - var result = task.GetType().GetProperty("Result").GetValue(task, null); - return result; - } - - #endregion - - #region 鈻� PIR浼犳劅鍣╛_________________________ - - /// <summary> - /// 鑾峰彇PIR浼犳劅鍣ㄧ殑銆愬厜鎰熺瓑绾ф�诲埢搴︺�戯紝閿欒鏃惰繑鍥�-1 - /// </summary> - /// <param name="iASZone"></param> - /// <returns></returns> - public async Task<int> GetPirLightAbilitySize(IASZone iASZone) - { - var data = await iASZone.GetPIRLightAbilitySizeAsync(); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(data); - if (error != null) - { - this.ShowErrorMsg(error); - return -1; - } - - if (data == null || data.errorMessageBase != null || data.LightLevelCount == -1) - { - //鑾峰彇浼犳劅鍣ㄥ厜鎰熺瓑绾уけ璐� - string msg = Language.StringByID(R.MyInternationalizationString.uGetPirSensorLightPerceptionRegulationFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, data.errorMessageBase); - - this.ShowErrorMsg(msg); - return -1; - } - - return data.LightLevelCount; - } - - /// <summary> - /// 鑾峰彇PIR浼犳劅鍣ㄧ殑銆愮伅鍏夐厤缃�戯紝閿欒鏃惰繑鍥瀗ull - /// </summary> - /// <param name="iASZone"></param> - /// <returns></returns> - public async Task<IASZone.ConfigureParamates> GetPirSensorLightSettion(IASZone iASZone) - { - var data = await iASZone.GetPIRSensorParamateAsync(); - if (data == null || data.configureParamates == null) - { - //鑾峰彇浼犳劅鍣ㄧ伅鍏夎缃俊鎭け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uGetPirSensorLightSettionFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, data.errorMessageBase); - - this.ShowErrorMsg(msg); - return null; - } - return data.configureParamates; - } - - /// <summary> - /// 璁剧疆PIR浼犳劅鍣ㄧ殑銆愮伅鍏夐厤缃�� - /// </summary> - /// <param name="iASZone">浼犳劅鍣ㄥ璞�</param> - /// <param name="configure">鐏厜閰嶇疆</param> - /// <returns></returns> - public async Task<bool> SetPirSensorLightSettion(IASZone iASZone, IASZone.ConfigureParamates configure) - { - var result = await iASZone.SetPIRSensorParamateAsync(configure); - if (result == null || result.responseData == null) - { - //璁剧疆浼犳劅鍣ㄧ伅鍏夐厤缃け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uSetPirSensorLightSettionFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return false; - } - if (result.responseData.status != 0) - { - //璁剧疆浼犳劅鍣ㄧ伅鍏夐厤缃け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uSetPirSensorLightSettionFail); - this.ShowErrorMsg(msg); - return false; - } - //澶囦唤璁剧疆 - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(iASZone, GatewayBackupEnum.APir鐏厜閰嶇疆, configure); - - return true; - } - - #endregion - - #region 鈻� 鎸夐敭闈㈡澘鍔熻兘绯籣____________________ - - #region 棰滆壊璋冭妭 - - /// <summary> - /// 鑾峰彇鎸夐敭闈㈡澘鎸囧畾绔偣鐨勩�愭寚绀虹伅寮�鍏抽鑹层�戠殑淇℃伅(鍑洪敊浼氳繑鍥瀗ull) - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <returns></returns> - public async Task<Panel.KeyColorData> GetPanelEpointColorInfo(Panel panel) - { - Panel.KeyNum keyNum = (Panel.KeyNum)panel.DeviceEpoint; - var result = await panel.GetPanelColorInfoAsync(keyNum); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(result); - if (error != null) - { - this.ShowErrorMsg(error); - return null; - } - - if (result == null || result.keyColorData == null) - { - //鑾峰彇鎸夐敭闈㈡澘棰滆壊璋冭妭淇℃伅澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelColorRegulationInfoFail); - this.ShowErrorMsg(msg); - return null; - } - return result.keyColorData; - } - - /// <summary> - /// 璁剧疆鎸夐敭闈㈡澘鎸囧畾绔偣鐨勩�愭寚绀虹伅寮�鍏抽鑹层�戠殑淇℃伅 - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <param name="colorData">寮�鍜屽叧鐨勯鑹查兘闇�瑕佷竴璧疯缃�</param> - /// <returns></returns> - public async Task<bool> SetPanelEpointColorInfo(Panel panel, Panel.KeyColorData colorData) - { - var keyNum = new Panel.KeyNumStatus(); - Type type = keyNum.GetType(); - type.InvokeMember("Key" + panel.DeviceEpoint, System.Reflection.BindingFlags.SetField, null, keyNum, new object[] { true }); - - var result = await panel.SetPanelColorInfoAsync(colorData, keyNum); - if (result == null || result.responseData == null) - { - //璁剧疆鎸夐敭闈㈡澘鎸囩ず鐏鑹插け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uSetPanelPilolightSettionFail); - this.ShowErrorMsg(msg); - return false; - } - if (result.responseData.status != 0) - { - //璁剧疆鎸夐敭闈㈡澘鎸囩ず鐏鑹插け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uSetPanelPilolightSettionFail); - this.ShowErrorMsg(msg); - return false; - } - //澶囦唤璁惧 - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A鎸夐敭闈㈡澘棰滆壊璋冭妭, colorData); - return true; - } - - #endregion - - #region 浜害璋冭妭 - /// <summary> - /// 鑾峰彇鎸夐敭闈㈡澘浜害閰嶇疆锛坲i鍙寒搴﹁皟鑺�,浣跨敤杩斿洖鍊肩殑panelDirectionsLevel锛� - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <returns></returns> - public async Task<Panel.PanelSwitchLevelInfo> GetPanelSwitchLightSettion(Panel panel) - { - var result = await panel.GetPanelSwitchLevelAsync(); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(result); - if (error != null) - { - this.ShowErrorMsg(error); - return null; - } - - if (result == null || string.IsNullOrEmpty(result.errorMessageBase) == false) - { - //鑾峰彇鎸夐敭闈㈡澘浜害璋冭妭淇℃伅澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelLightRegulationInfoFail); - this.ShowErrorMsg(msg); - return null; - } - return result; - } - - /// <summary> - /// 璁剧疆鎸夐敭闈㈡澘浜害锛坲i鍙寒搴﹁皟鑺傦級 - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <param name="directionsLevel">鎸囩ず鐏寒搴� 0-100(鐜伴樁娈典笉鐢ㄨ繖涓�)</param> - /// <param name="backlightLevel">鑳屽厜鐏寒搴� 0-100(ui鍙寒搴﹁皟鑺�)</param> - /// <returns></returns> - public async Task<bool> SetPanelSwitchLightSettion(Panel panel, int directionsLevel, int backlightLevel) - { - var result = await panel.SetKeyLevelAsync(directionsLevel, backlightLevel); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(result); - if (error != null) - { - this.ShowTipMsg(error); - return false; - } - - if (result == null || result.responseData == null) - { - //璁剧疆浜害璋冭妭澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uSetLightRegulationFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowTipMsg(msg); - return false; - } - - if (result.responseData.status != 0) - { - //璁剧疆浜害璋冭妭澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uSetLightRegulationFail); - this.ShowTipMsg(msg); - return false; - } - //澶囦唤璁惧 - var backData = new Newtonsoft.Json.Linq.JObject - { - { "directionsLevel",directionsLevel }, - { "backlightLevel", backlightLevel } - }; - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A鎸夐敭闈㈡澘浜害璋冭妭, backData); - return true; - } - - #endregion - - #region 鑺傝兘妯″紡 - /// <summary> - /// 鑾峰彇鎸夐敭闈㈡澘鑺傝兘妯″紡鐨勯厤缃姸鎬�(ui鍙妭鑳芥ā寮�) - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <returns></returns> - public async Task<Panel.PanelSaveEnergyModeInfo> GetPanelEnergyConservationMode(Panel panel) - { - var result = await panel.GetPanelSaveEnergyModeAsync(); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(result); - if (error != null) - { - this.ShowErrorMsg(error); - return null; - } - - if (result == null || result.panelSaveEnergyModeInfo == null) - { - //鑾峰彇鎸夐敭闈㈡澘鑺傝兘妯″紡淇℃伅澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelEnergyConservationInfoFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return null; - } - return result.panelSaveEnergyModeInfo; - } - - /// <summary> - /// 璁剧疆鎸夐敭闈㈡澘鐨勮妭鑳芥ā寮�(ui鍙妭鑳芥ā寮�) - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <param name="modeEnable">鑺傝兘妯″紡鏄惁鏈夋晥</param> - /// <param name="modeTime">鏃犳搷浣滆繘鍏ヨ妭鑳芥ā寮忔椂闂� 0-255</param> - /// <param name="level">鑺傝兘妯″紡浜害:0-100</param> - /// <returns></returns> - public async Task<bool> SetPanelEnergyConservationMode(Panel panel, bool modeEnable, int modeTime, int level) - { - var result = await panel.SetKeyModeAsync(modeEnable, modeTime, level); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(result); - if (error != null) - { - this.ShowErrorMsg(error); - return false; - } - - if (result == null || result.responseData == null) - { - //鑺傝兘妯″紡閰嶇疆澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uSetEnergyConservationFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowTipMsg(msg); - return false; - } - - if (result.responseData.status != 0) - { - //鑺傝兘妯″紡閰嶇疆澶辫触 - string msg = Language.StringByID(R.MyInternationalizationString.uSetEnergyConservationFail); - this.ShowTipMsg(msg); - return false; - } - //澶囦唤璁惧 - var backData = new Newtonsoft.Json.Linq.JObject - { - { "modeEnable",modeEnable }, - { "modeTime", modeTime }, - { "level", level } - }; - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(panel, GatewayBackupEnum.A鎸夐敭闈㈡澘鑺傝兘妯″紡, backData); - - return true; - } - - #endregion - - /// <summary> - /// 妫�娴嬫帶鍒堕潰鏉�(鐏被)鎵�鎷ユ湁鐨勫姛鑳�,鐜版敮鎸佺殑鏈変互涓嬪嚑绉�(蹇呭畾瀛樺湪閿��,鍑洪敊浼氳繑鍥瀗ull) - /// <para>閿��1:浜害璋冭妭(ui鍙寒搴﹁皟鑺�,閽堝鏁翠釜璁惧) -> true:鎷ユ湁姝ゅ姛鑳� false:鏃犳鍔熻兘</para> - /// <para>閿��2:鑺傝兘妯″紡(ui鍙妭鑳芥ā寮�,閽堝鏁翠釜璁惧) -> true:鎷ユ湁姝ゅ姛鑳� false:鏃犳鍔熻兘</para> - /// <para>閿��3:棰滆壊璋冭妭(ui鍙鑹茶皟鑺�,鍙兘鍗曞洖璺厤缃�) -> true:鎷ユ湁姝ゅ姛鑳� false:鏃犳鍔熻兘</para> - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <returns></returns> - public async Task<Dictionary<string, bool>> CheckPanelLightFunctionLevel2(Panel panel) - { - var dicCheck = new Dictionary<string, bool>(); - dicCheck["浜害璋冭妭"] = false; - dicCheck["鑺傝兘妯″紡"] = false; - dicCheck["棰滆壊璋冭妭"] = false; - - //鑾峰彇绗竴绾у姛鑳� - var result = await this.GetPanelDeviceFunctionLevel1(panel); - if (result == null) - { - return null; - } - - if (result.Contains(1024) == false) - { - //姝ゆ帶鍒堕潰鏉挎病鏈夌伅杩欎釜涓滆タ - return dicCheck; - } - - //鑾峰彇绗簩绾у姛鑳� - result = await this.GetPanelDeviceFunctionLevel2(panel, 1024); - if (result == null) - { - return null; - } - - if (result.Contains(102) == true) - { - //浜害璋冭妭锛�102 - dicCheck["浜害璋冭妭"] = true; - } - if (result.Contains(101) == true) - { - //棰滆壊璋冭妭锛�101 - dicCheck["棰滆壊璋冭妭"] = true; - } - if (result.Contains(0) == true) - { - //鑺傝兘妯″紡锛�0 - dicCheck["鑺傝兘妯″紡"] = true; - } - return dicCheck; - } - - /// <summary> - /// 鑾峰彇鎸夐敭闈㈡澘鐨勭涓�绾у埆鍔熻兘鍔熻兘绯�(1024:鐏被锛�256:鎸夐敭绫伙紝768:PIR绫�) - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <returns></returns> - public async Task<List<int>> GetPanelDeviceFunctionLevel1(Panel panel) - { - var result = await this.GetPanelDeviceFunction(panel); - if (result == null) - { - return null; - } - return result.privateFuncTypeLevelFirstList; - } - - /// <summary> - /// <para>鑾峰彇鎸夐敭闈㈡澘鐨勭浜岀骇鍒姛鑳藉姛鑳界郴(浠ヤ笅涓鸿繑鍥炲��)</para> - /// <para>100:Switch,寮�鍏筹紙鎸夐敭绫伙級</para> - /// <para>200:Dimmer,璋冨厜锛堟寜閿被锛�</para> - /// <para>300:Curtain,绐楀笜锛堟寜閿被锛�</para> - /// <para>0:EnergySavingMode,鑺傝兘妯″紡锛堢伅绫伙級</para> - /// <para>1:SleepMode,鐫$湢妯″紡锛堢伅绫伙級</para> - /// <para>100:WhiteBalance,鐧藉钩琛★紙鐏被锛�</para> - /// <para>101:RGBColor,RGB鎸囩ず鐏鑹诧紙鐏被锛�</para> - /// <para>102:RGBLevel,RGB鎸囩ず鐏寒搴︼紙鐏被锛�</para> - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <param name="levelNo">绗竴绾у埆鐨処D(1024:鐏被锛�256:鎸夐敭绫伙紝768:PIR绫�)</param> - /// <returns></returns> - public async Task<List<int>> GetPanelDeviceFunctionLevel2(Panel panel, int levelNo) - { - var result = await this.GetPanelDeviceFunction(panel, new int[] { levelNo }); - if (result == null) - { - return null; - } - return result.privateFuncTypeLevelSecondList; - } - - /// <summary> - /// 鑾峰彇鎸夐敭闈㈡澘鐨勫姛鑳� - /// </summary> - /// <param name="panel">鎸夐敭闈㈡澘鐨勬煇涓�涓洖璺�</param> - /// <param name="parameter"> - /// <para>鏂规硶1锛氬綋int[]浼犵┖锛岃繑鍥炲�兼槸鈥滈潰鏉垮叿鏈夌殑鍔熻兘澶х被,鍗宠繑鍥炩�滅涓�绾у埆銆�1024:鐏被锛�256:鎸夐敭绫伙紝768:PIR绫�</para> - /// <para>鏂规硶2锛氥�佸綋int[]鍊间负绗竴绾у埆PrivateFuncTypeFir涓�夋嫨涓�涓��</para> - /// <para>杩斿洖鍊兼槸鈥滈潰鎸夐敭鍙戦�佸姛鑳界被鈥濓紝鍗宠繑鍥炩�滅浜岀骇鍒��</para> - /// <para>100:Switch,寮�鍏筹紙鎸夐敭绫伙級;200:Dimmer,璋冨厜锛堟寜閿被锛�;300:Curtain,绐楀笜锛堟寜閿被锛�</para> - /// <para>0:EnergySavingMode,鑺傝兘妯″紡锛堢伅绫伙級;1:SleepMode,鐫$湢妯″紡锛堢伅绫伙級;100:WhiteBalance,鐧藉钩琛★紙鐏被锛�;101:RGBColor,RGB鎸囩ず鐏鑹诧紙鐏被锛�;102:RGBLevel,RGB鎸囩ず鐏寒搴︼紙鐏被锛�</para> - /// <para>鏂规硶3锛氬綋int[]鍊间负绗竴绾у埆PrivateFuncTypeFir涓�夋嫨涓�涓紝鎺ョ潃鍐嶉�夌浜岀骇鍒玃rivateFunTypeSec涓�夋嫨涓�涓� </para> - /// <para>杩斿洖鍊兼槸鈥滈潰鎸夐敭鍏蜂綋鍔熻兘閰嶇疆鈥濓紝鍗宠繑鍥炩�滅浜岀骇鍒��</para> - /// <para>100:SwitchOpen,寮�鍏冲紑锛堟寜閿被锛�;101:SwitchClose,寮�鍏冲叧锛堟寜閿被锛�;102:SwitchChange,寮�鍏冲垏鎹紙鎸夐敭绫伙級</para> - /// <para>200:DimmerStepUp,澧炲ぇ璋冨厜锛堟寜閿被锛�;201:DimmerStepDown,闄嶄綆璋冨厜锛堟寜閿被锛�;202:DimmerStepChange,璋冨厜鍒囨崲锛堟寜閿被锛�</para> - /// <para>300:CurtainOpen,绐楀笜寮�锛堟寜閿被锛�;301:CurtainClose,绐楀笜鍏筹紙鎸夐敭绫伙級;302:CurtainStop,绐楀笜鍋�;303:CurtainUpStop,绐楀笜涓婂崌鍋�;304:CurtainDownstop,绐楀笜涓嬮檷鍋�</para> - /// </param> - /// <returns></returns> - private async Task<Panel.PanelPrivateFunctionsResponseInfo> GetPanelDeviceFunction(Panel panel, params int[] parameter) - { - var result = await panel.GetPanelPrivateFunctionsAsync(parameter); - //鍏遍�氶敊璇娴� - string error = UserCenterLogic.CheckCommonErrorCode(result); - if (error != null) - { - this.ShowErrorMsg(error); - return null; - } - - if (result == null || result.panelPrivateFunctionsResponseInfo == null) - { - //鑾峰彇鎸夐敭闈㈡澘鍔熻兘绫讳俊鎭け璐� - string msg = Language.StringByID(R.MyInternationalizationString.uGetPanelFunctionInfoFail); - //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result.errorMessageBase); - - this.ShowErrorMsg(msg); - return null; - } - - return result.panelPrivateFunctionsResponseInfo; - } - - #endregion - - #region 鈻� 涓�鑸柟娉昣__________________________ - - /// <summary> - /// 鍒ゆ柇鏄笉鏄渤涓滅殑璁惧 - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public bool IsHdlDevice(CommonDevice device) - { - return device.ManufacturerName == "HDL"; - } - - /// <summary> - /// 鑾峰彇璁惧鐨勫敮涓�涓婚敭 - /// </summary> - /// <param name="device"></param> - /// <returns></returns> - public string GetDeviceMainKeys(CommonDevice device) - { - return device.DeviceAddr + device.DeviceEpoint; - } - - /// <summary> - /// 鑾峰彇璁惧鐨勫敮涓�涓婚敭 - /// </summary> - /// <param name="DeviceAddr">MAC鍦板潃</param> - /// <param name="DeviceEpoint">绔彛鍙�</param> - /// <returns></returns> - public string GetDeviceMainKeys(string DeviceAddr, int DeviceEpoint) - { - return DeviceAddr + DeviceEpoint; - } - - /// <summary> - /// 鏄剧ず閿欒淇℃伅绐楀彛 - /// </summary> - /// <param name="msg"></param> - private void ShowErrorMsg(string msg) - { - Application.RunOnMainThread(() => - { - var contr = new Phone.UserCenter.ErrorMsgControl(msg); - contr.Show(); - }); - } - - /// <summary> - /// 鏄剧ずTip淇℃伅绐楀彛 - /// </summary> - /// <param name="msg"></param> - private void ShowTipMsg(string msg) - { - Application.RunOnMainThread(() => - { - var contr = new Phone.UserCenter.TipViewControl(msg); - contr.ShowView(); - }); - } - - #endregion - - #region 鈻� 缁撴瀯浣揰____________________________ - - /// <summary> - /// 璁惧璁℃暟鐨勪俊鎭� - /// </summary> - private class DeviceCountInfo - { - /// <summary> - /// 璁℃暟 - /// </summary> - public int Count = 0; - /// <summary> - /// 绔彛鍙� - /// </summary> - public HashSet<int> hsEpoint = new HashSet<int>(); - } - - #endregion - - //----------------------------------鍒嗗壊绾�(鑷畾涔夋帴鍙�)--------------------------------------------- - - #region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________ - - /// <summary> - /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚鈽呪槄鈽呪槄鈽呪槄鈽�) - /// </summary> - /// <param name="zbGateway">缃戝叧瀵硅薄</param> - /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param> - /// <param name="mode">鏄惁鏄剧ず閿欒</param> + private Dictionary<string, List<CommonDevice>> GetDeviceSortRule() + { + var dic = new Dictionary<string, List<CommonDevice>>(); + //鎺у埗闈㈡澘 + dic[DeviceType.OnOffSwitch.ToString()] = null; + //鍗峰笜 + dic[DeviceType.WindowCoveringDevice.ToString()] = null; + //璋冨厜鐏� + dic[DeviceType.ColorDimmableLight.ToString()] = null; + //缁х數鍣� + dic[DeviceType.OnOffOutput.ToString()] = null; + //绌烘皵寮�鍏� + dic[DeviceType.AirSwitch.ToString()] = null; + //闂ㄧ獥纾佷紶鎰熷櫒 + dic["21"] = null; + dic["22"] = null; + //姘存蹈浼犳劅鍣� + dic["42"] = null; + //鐑熼浘浼犳劅鍣� + dic["40"] = null; + //绱ф�ユ寜閽� + dic["44"] = null; + //鐕冩皵浼犳劅鍣� + dic["43"] = null; + //杩愬姩浼犳劅鍣� + dic["13"] = null; + //閽ュ寵鎵� + dic["277"] = null; + + return dic; + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鍒ゆ柇鏄笉鏄渤涓滅殑璁惧 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public bool IsHdlDevice(CommonDevice device) + { + return device.ManufacturerName == "HDL"; + } + + /// <summary> + /// 鑾峰彇璁惧鐨勫敮涓�涓婚敭 + /// </summary> + /// <param name="device"></param> + /// <returns></returns> + public string GetDeviceMainKeys(CommonDevice device) + { + return device.DeviceAddr + device.DeviceEpoint; + } + + /// <summary> + /// 鑾峰彇璁惧鐨勫敮涓�涓婚敭 + /// </summary> + /// <param name="DeviceAddr">MAC鍦板潃</param> + /// <param name="DeviceEpoint">绔彛鍙�</param> + /// <returns></returns> + public string GetDeviceMainKeys(string DeviceAddr, int DeviceEpoint) + { + return DeviceAddr + DeviceEpoint; + } + + /// <summary> + /// 浜ゆ崲璁惧鐨勬ā鍧桰D + /// </summary> + /// <param name="modeId">妯″潡ID</param> + /// <returns></returns> + public bool ChangedDeviceModeId(ref string modeId) + { + if (this.dicDeviceModelIdChanged.ContainsKey(modeId) == false) + { + return false; + } + modeId = this.dicDeviceModelIdChanged[modeId]; + + return true; + } + + /// <summary> + /// 闄勫姞璁惧鐨勭増鏈唬鍙�(杩斿洖Ver.XXX) + /// </summary> + /// <param name="versionValue">鐗堟湰鍙�</param> + /// <returns></returns> + public string AppendVersion(int versionValue) + { + //杞负16杩涘埗 + string txt64 = Convert.ToString(versionValue, 16).PadLeft(4, '0'); + //杩欎釜鏄皬鏁扮偣鍓嶉潰鐨勫�� + int value1 = Convert.ToInt32(txt64.Substring(0, 2), 16); + //杩欎釜鏄皬鏁扮偣鍚庨潰鐨勫�� + int value2 = Convert.ToInt32(txt64.Substring(2, 2), 16); + + //Ver. + string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation); + return ver + value1 + "." + value2.ToString().PadLeft(3, '0'); + } + + /// <summary> + /// 鏄剧ず閿欒淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowErrorMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Error, msg); + contr.Show(); + }); + } + + /// <summary> + /// 鏄剧ずTip淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowTipMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, msg); + contr.Show(); + }); + } + + #endregion + + //----------------------------------鍒嗗壊绾�(鑷畾涔夋帴鍙�)--------------------------------------------- + + #region 鈻� 鑾峰彇璁惧鍒楄〃鐨勬帴鍙________________ + + /// <summary> + /// 浠庣綉鍏抽噸鏂拌幏鍙栬澶囧垪琛�(鈽呪槄鈽呪槄鈽呪槄鈽呮帴鏀跺埌璁惧鏃剁殑浜嬩欢,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚鈽呪槄鈽呪槄鈽呪槄鈽�) + /// </summary> + /// <param name="zbGateway">缃戝叧瀵硅薄</param> + /// <param name="deviceComingAction">鎺ユ敹鍒拌澶囨椂鐨勪簨浠�,璁惧瀵硅薄涓簄ull鏃�,浠h〃鎺ユ敹瀹屾垚</param> + /// <param name="mode">鏄惁鏄剧ず閿欒</param> /// <returns></returns> public async Task<List<CommonDevice>> GetDeviceListFromGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES) - { - //濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭� - string nowFormId = UserCenterResourse.NowActionFormID; - - ZbGateway realWay = null; - if (Common.LocalGateway.Current.GetRealGateway(ref realWay, zbGateway) == false) - { - if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) - { - //閿欒:缃戝叧瀵硅薄涓㈠け - string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg); - this.ShowTipMsg(msg); - } - return null; - } - - //鏄惁杈炬垚涓柇鐨勬椂鏈� - bool canBreak = false; - - //缃戝叧ID - string gatewayID = Common.LocalGateway.Current.GetGatewayId(zbGateway); - //瓒呮椂鏃堕棿 - int TimeOut = 0; - //璁惧鍒楄〃 - var listDevice = new List<CommonDevice>(); - - Action<string, string> getDeviceAction = (topic, message) => - { - try - { - if (topic == gatewayID + "/" + "DeviceInfoRespon") - { - TimeOut = 0; - var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); - var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString()); - if (totalNum == 0) - { - //杩欎釜缃戝叧娌℃湁璁惧 - canBreak = true; - return; - } - var deviceID = (DeviceType)jobject.Value<int>("Device_ID"); - //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� - var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway); - if (device != null) - { - //鍥炶皟鍑芥暟 - deviceComingAction?.Invoke(device); - - listDevice.Add(device); - } - } - else if (topic == gatewayID + "/" + "DeviceInfoResponEnd") - { - canBreak = true; - } - } - catch { } - }; - - realWay.Actions += getDeviceAction; - try - { - var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } }; - await realWay.Send("GetDeviceInfo", jObject.ToString()); - } - catch { canBreak = true; } - - while (canBreak == false && TimeOut < 60) - { - await Task.Delay(100); - TimeOut++; - } - - realWay.Actions -= getDeviceAction; - if (TimeOut >= 60) - { - if (listDevice.Count == 0) - { - if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) - { - //鑾峰彇璁惧鍒楄〃澶辫触 - //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇� - string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail); - msg += "\r\n[" + Common.LocalGateway.Current.GetGatewayName(zbGateway).ToString() + "]"; - msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, "鍥炲瓒呮椂", false); - this.ShowErrorMsg(msg); - } - return null; - } - else - { - if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) - { - //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯 - string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull); - this.ShowTipMsg(msg); - } - } - } - - //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚) + { + //濡傛灉鍒囨崲鍒颁簡鍒殑鐣岄潰锛屽垯涓嶆樉绀洪敊璇俊鎭� + string nowFormId = UserCenterResourse.NowActionFormID; + + ZbGateway realWay = null; + if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, zbGateway) == false) + { + if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) + { + //閿欒:缃戝叧瀵硅薄涓㈠け + string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg); + this.ShowTipMsg(msg); + } + return null; + } + + //鏄惁杈炬垚涓柇鐨勬椂鏈� + bool canBreak = false; + //缃戝叧ID + string gatewayID = HdlGatewayLogic.Current.GetGatewayId(zbGateway); + //瓒呮椂鏃堕棿 + int TimeOut = 0; + //璁惧鎬绘暟 + int deviceCount = -1; + //鎺ユ敹鏁� + int receiveCount = 0; + //璁惧鍒楄〃 + var listDevice = new List<CommonDevice>(); + + Action<string, string> getDeviceAction = (topic, message) => + { + try + { + if (topic == gatewayID + "/" + "DeviceInfoRespon") + { + TimeOut = 0; + var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); + var totalNum = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["TotalNum"].ToString()); + if (totalNum == 0) + { + //杩欎釜缃戝叧娌℃湁璁惧 + canBreak = true; + return; + } + if (deviceCount == -1) + { + //璁剧疆闇�瑕佹帴鏀跺灏戜釜璁惧 + deviceCount = totalNum; + } + //璁惧鎺ユ敹鏁� + receiveCount++; + + var deviceID = (DeviceType)jobject.Value<int>("Device_ID"); + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway); + if (device != null) + { + //鍥炶皟鍑芥暟 + deviceComingAction?.Invoke(device); + + listDevice.Add(device); + } + if (deviceCount == receiveCount) + { + //璁惧鍏ㄩ儴鎺ユ敹瀹屾垚 + canBreak = true; + } + } + } + catch { } + }; + + realWay.Actions += getDeviceAction; + try + { + var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } }; + await realWay.Send("GetDeviceInfo", jObject.ToString()); + } + catch { canBreak = true; } + + while (canBreak == false && TimeOut < 60) + { + await Task.Delay(100); + TimeOut++; + } + + realWay.Actions -= getDeviceAction; + getDeviceAction = null; + + if (TimeOut >= 60) + { + if (listDevice.Count == 0) + { + if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) + { + //鑾峰彇璁惧鍒楄〃澶辫触 + //[XXXX]缃戝叧鍥炲瓒呮椂,璇风◢鍚庡啀璇� + string msg = Language.StringByID(R.MyInternationalizationString.uGetDeviceListFail); + msg += "\r\n[" + HdlGatewayLogic.Current.GetGatewayName(zbGateway).ToString() + "]"; + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "鍥炲瓒呮椂", false); + this.ShowErrorMsg(msg); + } + return null; + } + else + { + if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES) + { + //缃戠粶涓嶇ǔ瀹氾紝璁惧鍒楄〃淇℃伅缂烘崯 + string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull); + this.ShowTipMsg(msg); + } + } + } + + //鍥炶皟鍑芥暟(鎺ユ敹瀹屾垚) deviceComingAction?.Invoke(null); + deviceComingAction = null; return listDevice; - } - - #endregion - - #region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________ - - /// <summary> - /// 鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� - /// </summary> - /// <param name="deviceType">璁惧绫诲瀷</param> - /// <param name="jobject">涓婚Data</param> - /// <param name="zbGateway">缃戝叧瀵硅薄</param> - /// <returns></returns> - private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway) - { - string gwId = Common.LocalGateway.Current.GetGatewayId(zbGateway); - - //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� - CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType); - if (device == null) - { - return null; - } - - //璁剧疆璁惧灞炴�х被 - device.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString()); - if (device.DeviceInfo == null) - { - return null; - } - this.SetMacName(device, string.Empty); - this.SetEpointName(device, string.Empty); - - //璁剧疆璁惧涓婚敭绫� - this.SetNewDeviceMainKeys(device, jobject); - device.CurrentGateWayId = gwId; - - //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 - this.SetDeviceInfoToMain(device, device); - - return device; - } - - /// <summary> - /// 灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 - /// </summary> - /// <param name="mainDevice">涓昏澶囧璞�</param> - /// <param name="device">璁剧疆婧愯澶囧璞�</param> - public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device) - { - if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false) - { - mainDevice.DeviceName = device.DeviceInfo.MacName; - } - if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false) - { - mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName; - } - mainDevice.CurrentGateWayId = device.CurrentGateWayId; - mainDevice.ImgVersion = device.DeviceInfo.ImgVersion; - mainDevice.HwVersion = device.DeviceInfo.HwVersion; - mainDevice.IsOnline = device.DeviceInfo.IsOnline; - mainDevice.DriveCode = device.DeviceInfo.DriveCode; - mainDevice.IasDeviceType = device.DeviceInfo.DeviceType; - mainDevice.Profile = device.DeviceInfo.Profile; - mainDevice.ImgTypeId = device.DeviceInfo.ImgTypeId; - mainDevice.InClusterList = device.DeviceInfo.InClusterList; - mainDevice.OutClusterList = device.DeviceInfo.OutClusterList; - mainDevice.AttributeStatus = device.DeviceInfo.AttributeStatus; - } - - /// <summary> - /// 鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞� - /// </summary> - /// <param name="deviceType">璁惧Type</param> - /// <returns></returns> - public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType) - { - CommonDevice device = null; - - //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� - if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); } - else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); } - else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); } - else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); } - else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); } - else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); } - else if (deviceType == DeviceType.IASZone) { device = new IASZone(); } - else if (deviceType == DeviceType.Repeater) { device = new Repeater(); } - else if (deviceType == DeviceType.Thermostat) { device = new AC(); } - else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); } - else { return null; } - - device.DeviceEpointName = string.Empty; - device.DeviceName = string.Empty; - - return device; - } - - /// <summary> - /// 缁欐柊璁惧璁剧疆涓婚敭灞炴�� - /// </summary> - /// <param name="device">璁惧瀵硅薄</param> - /// <param name="jobject">涓婚Data</param> - public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject) - { - //璁剧疆璁惧涓婚敭绫� - device.Time = jobject.Value<int>("Time"); - device.DeviceID = jobject.Value<int>("Device_ID"); - device.DeviceAddr = jobject.Value<string>("DeviceAddr"); - device.DeviceEpoint = jobject.Value<int>("Epoint"); - device.DataID = jobject.Value<int>("Data_ID"); - } - - #endregion - - //----------------------------------鍒嗗壊绾�(璁惧妯″潡ID)--------------------------------------------- - - #region 鈻� 鑷畾涔夎澶囨ā鍧桰D___________________ - - /// <summary> - /// 鍒濆鍖栬澶囩殑妯″潡ID鐨勬灇涓� - /// </summary> - private void InitDeviceModelIdEnum() - { - if (this.dicDeviceModelIdEnum != null) - { - return; - } - this.dicDeviceModelIdEnum = new Dictionary<string, string>(); - - //瀹氫箟瑙勫垯锛氭ā鍧桰D(宸茬炕璇�)=璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互) - //绗竴涓�兼槸:DeviceConcreteType 绗簩涓�兼槸:DeviceBeloneType - - //=========鈽呪槄寮�鍚堝笜绫�(100-199)鈽呪槄========= - this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//鏅鸿兘寮�鍚堝笜鐢垫満 - this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//鏅鸿兘绠$姸鐢垫満 - - //=========鈽呪槄鎸夐敭闈㈡澘绫�(200-1199)鈽呪槄========= - this.dicDeviceModelIdEnum["MPT4/R4-ZB.18"] = "200-200";//4鎸夐敭瑙︽懜闈㈡澘(甯�4璺户鐢靛櫒搴曞骇) - this.dicDeviceModelIdEnum["MPT3/R3-ZB.18"] = "201-200";//3鎸夐敭瑙︽懜闈㈡澘 - this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200";//2鎸夐敭瑙︽懜闈㈡澘 - this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200";//12鎸夐敭瑙︽懜闈㈡澘 - this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200";//4鎸夐敭瑙︽懜闈㈡澘(鍙甫鐢垫簮搴曞骇) - - //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= - this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir浼犳劅鍣�220 - - //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄========= - this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1300";//鐕冩皵浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1300";//闂ㄧ獥纾佷紶鎰熷櫒 - this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1300";//鐑熼浘浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1300";//绾㈠浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1300";//姘存蹈浼犳劅鍣� - this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1300";//绱ф�ユ寜閿� - - //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄========= - this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300";//3璺户鐢靛櫒灏忔ā鍧� - - //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄========= - this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500";//1璺皟鍏夊櫒灏忔ā鍧� - - //=========鈽呪槄绌鸿皟绫�(3600-3899)鈽呪槄========= - this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee绌鸿皟缃戝叧妯″潡 - - //=========鈽呪槄涓户鍣ㄧ被(3900-3999)鈽呪槄========= - this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee涓户鍣� - - //=========鈽呪槄绌烘皵寮�鍏崇被(4100-4199)鈽呪槄========= - this.dicDeviceModelIdEnum["MBCI01-ZB.10"] = "4100-4100";//zigbee寰柇浜戞帶鍒跺櫒 - - //=========鈽呪槄杞崲鍣ㄧ被(4200-4699)鈽呪槄========= - this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee杞�485鍗忚杞崲鍣� - this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee杞琤uspro鍗忚杞崲鍣� - } - - #endregion - } -} \ No newline at end of file + } + + #endregion + + #region 鈻� 鍒涘缓鏂拌澶囧璞$浉鍏砡________________ + + /// <summary> + /// 鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + /// </summary> + /// <param name="deviceType">璁惧绫诲瀷</param> + /// <param name="jobject">涓婚Data</param> + /// <param name="zbGateway">缃戝叧瀵硅薄</param> + /// <returns></returns> + private CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType, Newtonsoft.Json.Linq.JObject jobject, ZbGateway zbGateway) + { + string gwId = HdlGatewayLogic.Current.GetGatewayId(zbGateway); + + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + CommonDevice device = this.NewDeviceObjectByDeviceId(deviceType); + if (device == null) + { + return null; + } + + //璁剧疆璁惧灞炴�х被 + device.DeviceInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.DeviceInfoData>(jobject["Data"].ToString()); + if (device.DeviceInfo == null) + { + return null; + } + this.SetMacName(device, string.Empty); + this.SetEpointName(device, string.Empty); + + //璁剧疆璁惧涓婚敭绫� + this.SetNewDeviceMainKeys(device, jobject); + device.CurrentGateWayId = gwId; + + //灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + this.SetDeviceInfoToMain(device, device); + + return device; + } + + /// <summary> + /// 灏咲eviceInfo鐨勫睘鎬ц缃埌涓诲睘鎬т腑 + /// </summary> + /// <param name="mainDevice">涓昏澶囧璞�</param> + /// <param name="device">璁剧疆婧愯澶囧璞�</param> + public void SetDeviceInfoToMain(CommonDevice mainDevice, CommonDevice device) + { + if (string.IsNullOrEmpty(device.DeviceInfo.MacName) == false) + { + mainDevice.DeviceName = device.DeviceInfo.MacName; + } + if (string.IsNullOrEmpty(device.DeviceInfo.DeviceName) == false) + { + mainDevice.DeviceEpointName = device.DeviceInfo.DeviceName; + } + mainDevice.CurrentGateWayId = device.CurrentGateWayId; + mainDevice.IsOnline = device.DeviceInfo.IsOnline; + mainDevice.DriveCode = device.DeviceInfo.DriveCode; + mainDevice.IasDeviceType = device.DeviceInfo.DeviceType; + mainDevice.Profile = device.DeviceInfo.Profile; + + //鍥轰欢鐗堟湰 + mainDevice.ImgVersion = device.DeviceInfo.ImgVersion; + //纭欢鐗堟湰 + mainDevice.HwVersion = device.DeviceInfo.HwVersion; + //闀滃儚ID + mainDevice.ImgTypeId = device.DeviceInfo.ImgTypeId; + //鍘傚晢鍚嶇О + mainDevice.ManufacturerName = device.DeviceInfo.ManufacturerName; + //妯″潡ID + mainDevice.ModelIdentifier = device.DeviceInfo.ModelIdentifier; + //搴忓垪鍙� + mainDevice.SerialNumber = device.DeviceInfo.ProductCode; + + mainDevice.InClusterList.Clear(); + mainDevice.InClusterList.AddRange(device.DeviceInfo.InClusterList); + mainDevice.OutClusterList.Clear(); + mainDevice.OutClusterList.AddRange(device.DeviceInfo.OutClusterList); + mainDevice.AttributeStatus.Clear(); + mainDevice.AttributeStatus.AddRange(device.DeviceInfo.AttributeStatus); + } + + /// <summary> + /// 鏍规嵁璁惧Type鍒涘缓瀵瑰簲鐨勮澶囧璞� + /// </summary> + /// <param name="deviceType">璁惧Type</param> + /// <returns></returns> + public CommonDevice NewDeviceObjectByDeviceId(DeviceType deviceType) + { + CommonDevice device = null; + + //鏍规嵁璁惧绫诲瀷鍒涘缓璁惧瀵硅薄鐨勫疄渚� + if (deviceType == DeviceType.ColorDimmableLight) { device = new ColorDimmableLight(); } + else if (deviceType == DeviceType.DimmableLight) { device = new DimmableLight(); } + else if (deviceType == DeviceType.OnOffSwitch) { device = new Panel(); } + else if (deviceType == DeviceType.OnOffOutput) { device = new ToggleLight(); } + else if (deviceType == DeviceType.AirSwitch) { device = new AirSwitch(); } + else if (deviceType == DeviceType.WindowCoveringDevice) { device = new Rollershade(); } + else if (deviceType == DeviceType.IASZone) { device = new IASZone(); } + else if (deviceType == DeviceType.Repeater) { device = new Repeater(); } + else if (deviceType == DeviceType.Thermostat) { device = new AC(); } + else if (deviceType == DeviceType.DoorLock) { device = new DoorLock(); } + else if (deviceType == DeviceType.OtaDevice || deviceType == DeviceType.OtaPanelDevice) { device = new OTADevice(); } + else { return null; } + + device.DeviceEpointName = string.Empty; + device.DeviceName = string.Empty; + + return device; + } + + /// <summary> + /// 缁欐柊璁惧璁剧疆涓婚敭灞炴�� + /// </summary> + /// <param name="device">璁惧瀵硅薄</param> + /// <param name="jobject">涓婚Data</param> + public void SetNewDeviceMainKeys(CommonDevice device, Newtonsoft.Json.Linq.JObject jobject) + { + //璁剧疆璁惧涓婚敭绫� + device.Time = jobject.Value<int>("Time"); + device.DeviceID = jobject.Value<int>("Device_ID"); + device.DeviceAddr = jobject.Value<string>("DeviceAddr"); + device.DeviceEpoint = jobject.Value<int>("Epoint"); + device.DataID = jobject.Value<int>("Data_ID"); + } + + #endregion + + //----------------------------------鍒嗗壊绾�(璁惧妯″潡ID)--------------------------------------------- + + #region 鈻� 鑷畾涔夎澶囨ā鍧桰D___________________ + + /// <summary> + /// 鍒濆鍖栬澶囩殑妯″潡ID鐨勬灇涓� + /// </summary> + private void InitDeviceModelIdEnum() + { + if (this.dicDeviceModelIdEnum != null) + { + return; + } + this.dicDeviceModelIdEnum = new Dictionary<string, string>(); + + //瀹氫箟瑙勫垯锛氭ā鍧桰D(宸茬炕璇�)=璁惧鍏蜂綋绫诲瀷鍊�-璁惧鎵�灞炵被鍨嬪��(鑷畾涔夌殑鍊�,鍢�,鍙涓嶉噸澶嶅氨鍙互) + //绗竴涓�兼槸:DeviceConcreteType 绗簩涓�兼槸:DeviceBeloneType + + //=========鈽呪槄寮�鍚堝笜绫�(100-199)鈽呪槄========= + this.dicDeviceModelIdEnum["MWM65B-ZB.20"] = "100-100";//鏅鸿兘寮�鍚堝笜鐢垫満 + this.dicDeviceModelIdEnum["MVSM35B-ZB.20"] = "101-100";//鏅鸿兘绠$姸鐢垫満 + + //=========鈽呪槄鎸夐敭闈㈡澘绫�(200-1199)鈽呪槄========= + this.dicDeviceModelIdEnum["MPT4/R4-ZB.18"] = "200-200";//4鎸夐敭瑙︽懜闈㈡澘(甯�4璺户鐢靛櫒搴曞骇) + this.dicDeviceModelIdEnum["MPT3/R3-ZB.18"] = "201-200";//3鎸夐敭瑙︽懜闈㈡澘 + this.dicDeviceModelIdEnum["MPT2/R2-ZB.18"] = "202-200";//2鎸夐敭瑙︽懜闈㈡澘 + this.dicDeviceModelIdEnum["MPT1/R1-ZB.18"] = "203-200";//12鎸夐敭瑙︽懜闈㈡澘 + this.dicDeviceModelIdEnum["MPT4-ZB.18"] = "210-200";//4鎸夐敭瑙︽懜闈㈡澘(鍙甫鐢垫簮搴曞骇) + + //=========鈽呪槄PIR浼犳劅鍣ㄧ被(1200-1299)鈽呪槄========= + this.dicDeviceModelIdEnum["MSPIR01-ZB.10"] = "1200-1200";//pir浼犳劅鍣�220 + + //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫�(1300-2299)鈽呪槄========= + this.dicDeviceModelIdEnum["MULTI-GASE--EA07"] = "1300-1300";//鐕冩皵浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-MECI--EA01"] = "1301-1300";//闂ㄧ獥纾佷紶鎰熷櫒 + this.dicDeviceModelIdEnum["MULTI-FIRE--EA05"] = "1302-1300";//鐑熼浘浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-MOTI--EA04"] = "1303-1300";//绾㈠浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-WATE--EA02"] = "1304-1300";//姘存蹈浼犳劅鍣� + this.dicDeviceModelIdEnum["MULTI-BURO--EA06"] = "1305-1300";//绱ф�ユ寜閿� + + //=========鈽呪槄缁х數鍣ㄧ被(2300-2499)鈽呪槄========= + this.dicDeviceModelIdEnum["MPR0310-ZB.10"] = "2300-2300";//3璺户鐢靛櫒灏忔ā鍧� + + //=========鈽呪槄璋冨厜鍣ㄧ被(2500-2799)鈽呪槄========= + this.dicDeviceModelIdEnum["MPD0101-ZB.10"] = "2500-2500";//1璺皟鍏夊櫒灏忔ā鍧� + + //=========鈽呪槄鏅鸿兘闂ㄩ攣绫�(2800-????)鈽呪槄========= + this.dicDeviceModelIdEnum["H06C"] = "2800-2800";//鏅鸿兘闂ㄩ攣(H06C) + + //=========鈽呪槄绌鸿皟绫�(3600-3899)鈽呪槄========= + this.dicDeviceModelIdEnum["MAC/GW-ZB.431"] = "3600-3600";//zigbee绌鸿皟缃戝叧妯″潡 + + //=========鈽呪槄涓户鍣ㄧ被(3900-3999)鈽呪槄========= + this.dicDeviceModelIdEnum["MSR-ZB.10"] = "3900-3900"; //zigbee涓户鍣� + + //=========鈽呪槄绌烘皵寮�鍏崇被(4100-4199)鈽呪槄========= + this.dicDeviceModelIdEnum["MBCI01-ZB.10"] = "4100-4100";//zigbee寰柇浜戞帶鍒跺櫒 + + //=========鈽呪槄杞崲鍣ㄧ被(4200-4699)鈽呪槄========= + this.dicDeviceModelIdEnum["MBUS/GW-ZB.10"] = "4200-4200";//zigbee杞琤uspro鍗忚杞崲鍣� + this.dicDeviceModelIdEnum["M485/GW-ZB.10"] = "4201-4200";//zigbee杞�485鍗忚杞崲鍣� + + //闇�瑕佷氦鎹㈢殑妯″潡ID + this.dicDeviceModelIdChanged = new Dictionary<string, string>(); + //=========鈽呪槄瀹夐槻绫讳紶鎰熷櫒绫烩槄鈽�========= + this.dicDeviceModelIdChanged["MULTI-GASE--EA07"] = "MSG01/M-ZB.10";//鐕冩皵浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-MECI--EA01"] = "MSDC01/M-ZB.10";//闂ㄧ獥纾佷紶鎰熷櫒 + this.dicDeviceModelIdChanged["MULTI-FIRE--EA05"] = "MSS01/M-ZB.10";//鐑熼浘浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-MOTI--EA04"] = "MSPIR01/M-ZB.10";//绾㈠浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-WATE--EA02"] = "MSW01/M-ZB.10";//姘存蹈浼犳劅鍣� + this.dicDeviceModelIdChanged["MULTI-BURO--EA06"] = "MBU01/M-ZB.10";//绱ф�ユ寜閿� + } + + #endregion + } +} -- Gitblit v1.8.0