gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Common/Device.cs
@@ -1,2345 +1,2650 @@
using 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>
        /// 本地设备
using 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
            {
                lock (dicAllDevice)
                {
                    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文件里面设备默认名字的ID
        /// </summary>
        public Dictionary<string, int> dicDeviceDefultNameID = null;
        /// <summary>
        /// 设备的模块ID的枚举(keys:模块ID  value:设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
        /// </summary>
        private Dictionary<string, string> dicDeviceModelIdEnum = null;
        /// <summary>
        /// 需要转换的设备的模块ID(keys:旧模块ID,value:新模块ID)
        /// </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>
        private Dictionary<string, string> dicDeviceRoomId = null;
        #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
            {
                lock (dicAllDevice)
                {
                    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文件里面设备默认名字的ID
        /// </summary>
        public Dictionary<string, int> dicDeviceDefultNameID = null;
        /// <summary>
        /// 设备的模块ID的枚举(keys:模块ID  value:设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
        /// </summary>
        private Dictionary<string, string> dicDeviceModelIdEnum = null;
        /// <summary>
        /// 需要转换的设备的模块ID(keys:旧模块ID,value:新模块ID)
        /// </summary>
        private Dictionary<string, string> dicDeviceModelIdChanged = null;
        /// <summary>
        /// 图片共有(keys:指定设备的具体类型 value:指定共有对象的具体类型)
        /// </summary>
        private Dictionary<string, string> dicPictrueShard = 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>
        private Dictionary<string, string> dicDeviceRoomId = null;
        #endregion
        #region ■ 刷新设备___________________________
        /// <summary>
        /// 刷新本地设备信息
        /// </summary>
        public void ReFreshByLocal()
        {
            this.dicAllDevice.Clear();
            this.dicDeviceEpoint.Clear();
            this.dicDeviceEpoint.Clear();
            //初始化R文件里面设备默认名字的ID
            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)
                {
#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;
                }
                //如果这个设备的网关ID不存在的话
                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
                        //如果是主人,或者管理员,那么这个文件是非法的,直接删除
                        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);
                //检测Ui图片是否正确,这个图片本地是否存在?
                if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true)
                {
                    //不存在的话,重新生成
                    device.IconPath = string.Empty;
                    device.ReSave();
                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                }
            foreach (string file in listFile)
            {
                CommonDevice device = null;
                //反序列化为指定的类,不然数据会丢失而导致无法强转
                try
                {
                    device = CommonDevice.CommonDeviceByFilePath(file);
                }
                catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                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;
                }
                //如果这个设备的网关ID不存在的话
                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
                        //如果是主人,或者管理员,那么这个文件是非法的,直接删除
                        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);
                //检测Ui图片是否正确,这个图片本地是否存在?
                if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(device.IconPath)) == true)
                {
                    //不存在的话,重新生成
                    device.IconPath = string.Empty;
                    device.ReSave();
                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                }
            }
            //成员身份的时候,删除掉非法的网关文件
            this.DeleteGatewayFileByMemberModel();
            //初始化物理设备所属房间的记录
            this.InitRealDeviceRoomId();
        }
        /// <summary>
        /// 成员身份的时候,删除掉非法的网关文件
        /// </summary>
        private void DeleteGatewayFileByMemberModel()
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 3)
            {
                return;
            }
            var listId = new HashSet<string>();
            lock (dicAllDevice)
            {
                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">接收到设备时的事件,设备对象为null时,代表接收完成</param>
        /// <returns>一直返回true</returns>
        public bool SetDeviceToMemmoryByGateway(ZbGateway zbGateway, Action<CommonDevice> deviceComingAction = null)
        {
            //从网关获取全部的设备
            List<CommonDevice> listDevice = new List<CommonDevice>();
            List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, true, 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) + ")";
                    }
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        await this.ReName(device, dName, ShowErrorMode.NO);
                    });
                }
            }
            //如果本地和网关的设备不一致的时候,暂时删除本地的设备
            //注意:只是删除设备文件,房间内容什么的还存在着
            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];
                    //将DeviceInfo的属性设置到主属性中
                    this.SetDeviceInfoToMain(tempDevice, device);
                    device = tempDevice;
                }
                bool exists = Global.IsExistsByHomeId(device.FilePath);
                device.ReSave();
                if (exists == false)
                {
                    //添加自动备份
                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                }
                return;
            }
            lock (dicAllDevice)
            {
                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
                {
                    //交换属性
                    var tempDevice = this.dicAllDevice[mainKeys];
                    //将DeviceInfo的属性设置到主属性中
                    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);
                //如果它只有一个回路,则更改端点名字
                if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count == 1)
                {
                    return await this.ReName(device, newMacName);
                }
            }
            return true;
        }
        /// <summary>
        /// 更改名字后,刷新设备缓存
        /// </summary>
        /// <param name="device"></param>
        private void BackupDeviceAfterReName(CommonDevice device)
        {
            lock (dicAllDevice)
            {
                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);
            //删一次的时候,它会把MAC地址下面全部的设备都删除
            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);
            }
            if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
            {
                //移除真实设备的房间索引
                this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
                this.SaveRealDeviceRoomId(null, null);
            }
            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);
            lock (dicAllDevice)
            {
                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>();
            lock (dicAllDevice)
            {
                //各网关的所有设备
                foreach (CommonDevice device in this.dicAllDevice.Values)
                {
                    if (gwId == device.CurrentGateWayId)
                    {
                        list.Add(device);
                    }
                }
            }
            return list;
        }
        /// <summary>
        /// 获取指定设备(主键是:Mac地址+端口号),不存在时,返回null
        /// </summary>
        /// <param name="mainKeys">Mac地址+端口号</param>
        /// <returns></returns>
        public CommonDevice GetDevice(string mainKeys)
        {
            lock (dicAllDevice)
            {
                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
                {
                    return this.dicAllDevice[mainKeys];
                }
            }
            return null;
        }
        /// <summary>
        /// 获取指定设备,不存在时,返回null
        /// </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>
        /// 根据MAC地址,获取全部回路的数量
        /// </summary>
        /// <param name="DeviceAddr">Mac地址</param>
        /// <returns></returns>
        public int GetDevicesCountByMac(string DeviceAddr)
        {
            if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
            {
                return 0;
            }
            return dicDeviceEpoint[DeviceAddr].Count;
        }
        /// <summary>
        /// 获取本地全部的设备文件
        /// </summary>
        /// <returns></returns>
        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>();
            lock (dicAllDevice)
            {
                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>
        /// <para>将指定网关的设备存入缓存中(从新获取镜像)</para>
        /// <para>-1:异常 1:正常 2:设备信息缺损</para>
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        public int SetDeviceToMemmoryByGateway(ZbGateway zbGateway)
        {
            //从网关获取全部的设备
            int statu = 0;
            List<CommonDevice> listDevice = new List<CommonDevice>();
            List<CommonDevice> list = this.GetDeviceListFromGateway(zbGateway, ref statu, true);
            if (list == null)
            {
                return -1;
            }
            listDevice.AddRange(list);
            //获取这个网关的本地所有设备
            string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
            List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID, true);
            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 (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) + ")";
                    HdlThreadLogic.Current.RunThread(async () =>
                    {
                        await this.ReName(device, dName, ShowErrorMode.NO);
                    });
                }
            }
            //只有完全获取的时候,才会去处理删除的问题
            if (statu != 1)
            {
                return statu;
            }
            //如果本地和网关的设备不一致的时候,删除本地的设备
            foreach (var device in dicExist.Values)
            {
                if (device is OTADevice)
                {
                    this.DeleteMemmoryOtaDevice(device.DeviceAddr);
                }
                else
                {
                    this.DeleteMemmoryDevice(device, true);
                }
            }
            return statu;
        }
        /// <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];
                    //将DeviceInfo的属性设置到主属性中
                    this.SetDeviceInfoToMain(tempDevice, device);
                    device = tempDevice;
                }
                bool exists = Global.IsExistsByHomeId(device.FilePath);
                device.ReSave();
                if (exists == false)
                {
                    //添加自动备份
                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                }
                return;
            }
            lock (dicAllDevice)
            {
                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
                {
                    //交换属性
                    var tempDevice = this.dicAllDevice[mainKeys];
                    //将DeviceInfo的属性设置到主属性中
                    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);
                //如果它只有一个回路,则更改端点名字
                if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count == 1)
                {
                    return await this.ReName(device, newMacName);
                }
            }
            return true;
        }
        /// <summary>
        /// 更改名字后,刷新设备缓存
        /// </summary>
        /// <param name="device"></param>
        private void BackupDeviceAfterReName(CommonDevice device)
        {
            lock (dicAllDevice)
            {
                string mainKeys = this.GetDeviceMainKeys(device);
                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
                {
                    //一般设备
                    this.dicAllDevice[mainKeys] = device;
                    device.ReSave();
                    //添加自动备份
                    HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
                }
                else if (this.dicOTADevice.ContainsKey(mainKeys) == true)
                {
                    //Ota设备
                    this.dicOTADevice[mainKeys] = (OTADevice)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);
            //删一次的时候,它会把MAC地址下面全部的设备都删除
            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;
            }
            //删除缓存的Ota设备
            this.DeleteMemmoryOtaDevice(listdevice[0].DeviceAddr);
            //删除一般设备文件
            foreach (CommonDevice device in listdevice)
            {
                this.DeleteMemmoryDevice(device);
            }
            if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
            {
                //移除真实设备的房间索引
                this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
                this.SaveRealDeviceRoomId(null, null);
            }
            return true;
        }
        /// <summary>
        /// 删除缓存的一般设备
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="deleteRoom">是否从房间删除</param>
        public void DeleteMemmoryDevice(CommonDevice device, bool deleteRoom = true)
        {
            if (deleteRoom == true && Room.CurrentRoom != null)
            {
                //从房间中删除
                Room.CurrentRoom.DeleteDevice(device);
                //删除我的喜爱的设备
                Room.CurrentRoom.DeleteLoveDevice(device);
            }
            //删除缓存
            string mainKeys = this.GetDeviceMainKeys(device);
            lock (dicAllDevice)
            {
                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
                {
                    this.dicAllDevice.Remove(mainKeys);
                }
                if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true)
                {
                    //变更端点数
                    this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
                }
            }
            //删除设备文件
            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);
                }
            }
        }
        /// <summary>
        /// 删除缓存的Ota设备
        /// </summary>
        /// <param name="macAdrr"></param>
        /// <param name="ePoint"></param>
        public void DeleteMemmoryOtaDevice(string macAdrr, int ePoint = 200)
        {
            //删除200端口文件
            string otaKeys = this.GetDeviceMainKeys(macAdrr, ePoint);
            if (this.dicOTADevice.ContainsKey(otaKeys) == true)
            {
                string otaFile = this.dicOTADevice[otaKeys].FilePath;
                if (Global.IsExistsByHomeId(otaFile) == true)
                {
                    if (UserCenterResourse.UserInfo.AuthorityNo == 3)
                    {
                        //成员的话,直接删除,没有商量的余地
                        Global.DeleteFilebyHomeId(otaFile);
                    }
                    else
                    {
                        //变更:搞掉它,不留了
                        Global.DeleteFilebyHomeId(otaFile);
                        //删除自动备份
                        HdlAutoBackupLogic.DeleteFile(otaFile);
                    }
                }
                this.dicOTADevice.Remove(otaKeys);
            }
        }
        #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>
        /// <param name="getOtaDevice">是否获取ota设备</param>
        /// <returns></returns>
        public List<CommonDevice> GetDeviceByGatewayID(string gwId, bool getOtaDevice = false)
        {
            List<CommonDevice> list = new List<CommonDevice>();
            lock (dicAllDevice)
            {
                //各网关的所有设备
                foreach (CommonDevice device in this.dicAllDevice.Values)
                {
                    if (gwId == device.CurrentGateWayId)
                    {
                        list.Add(device);
                    }
                }
                if (getOtaDevice == true)
                {
                    //获取ota设备
                    foreach (var ota in this.dicOTADevice.Values)
                    {
                        if (ota.CurrentGateWayId == gwId)
                        {
                            list.Add(ota);
                        }
                    }
                }
            }
            return list;
        }
        /// <summary>
        /// 获取指定设备(主键是:Mac地址+端口号),不存在时,返回null
        /// </summary>
        /// <param name="mainKeys">Mac地址+端口号</param>
        /// <returns></returns>
        public CommonDevice GetDevice(string mainKeys)
        {
            lock (dicAllDevice)
            {
                if (this.dicAllDevice.ContainsKey(mainKeys) == true)
                {
                    return this.dicAllDevice[mainKeys];
                }
            }
            return null;
        }
        /// <summary>
        /// 获取指定设备,不存在时,返回null
        /// </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>
        /// <param name="sort">是否排序</param>
        /// <returns></returns>
        public List<CommonDevice> GetDevicesByMac(string DeviceAddr, bool sort = true)
        {
            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);
                }
            }
            if (sort == false)
            {
                return list;
            }
            //排序
            list.Sort((obj1, obj2) =>
            {
                if (obj1.DeviceEpoint > obj2.DeviceEpoint)
                {
                    return 1;
                }
                return -1;
            });
            return list;
        }
        /// <summary>
        /// 根据MAC地址,获取全部回路的数量
        /// </summary>
        /// <param name="DeviceAddr">Mac地址</param>
        /// <returns></returns>
        public int GetDevicesCountByMac(string DeviceAddr)
        {
            if (dicDeviceEpoint.ContainsKey(DeviceAddr) == false)
            {
                return 0;
            }
            return dicDeviceEpoint[DeviceAddr].Count;
        }
        /// <summary>
        /// 获取本地全部的设备文件
        /// </summary>
        /// <returns></returns>
        public List<string> GetAllDeviceFile()
        {
            List<string> listDeviceFile = new List<string>();
            List<string> listAllFile = Global.FileListByHomeId();
            foreach (string file in listAllFile)
            {
                if (file.StartsWith("Device_") == false)
                {
                    //如果不是设备文件
                    continue;
                }
                listDeviceFile.Add(file);
            }
            return listDeviceFile;
        }
        /// <summary>
        /// 获取OTA设备(200端口的)
        /// </summary>
        /// <param name="macAdrr"></param>
        /// <param name="ePoint"></param>
            foreach (string file in listAllFile)
            {
                if (file.StartsWith("Device_") == 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];
        }
        /// <summary>
        /// 获取特殊的,没有其他回路,单纯只有200端点的OTA设备
        /// </summary>
        /// <param name="gwId">网关ID</param>
        /// <returns></returns>
        public List<OTADevice> GetSpecialOtaDevice(string gwId)
        {
            var list = new List<OTADevice>();
            foreach (var ota in this.dicOTADevice.Values)
            {
                if (ota.CurrentGateWayId != gwId)
                {
                    //不是同一个网关
                    continue;
                }
                if (dicDeviceEpoint.ContainsKey(ota.DeviceAddr) == false
                    || dicDeviceEpoint[ota.DeviceAddr].Count == 0)
                {
                    list.Add(ota);
                }
            }
            return list;
        }
        #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;
            }
            //根据设备类型获取名称
            var tempValue = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
            var arry = tempValue.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
            dName = arry[0].Trim();
            //如果是虚拟设备
            if (device.DriveCode > 0)
            {
                //在端点名字的后面附加【回路】字样
                dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
                return dName;
            }
            //获取设备类型
            var deviceInfoType = this.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
            if (deviceInfoType.BeloneType == Common.DeviceBeloneType.A按键面板 && device.Type == DeviceType.TemperatureSensor)
            {
                //面板的最后一个回路是温度传感器
                dName += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId11);
            }
            else if (deviceInfoType.ConcreteType == Common.DeviceConcreteType.Sensor_Pir)
            {
                //pir传感器,它又搞特殊东西,传感器自身用自己的名字,继电器回路的话……
                if (device.Type == DeviceType.OnOffOutput)
                {
                    dName += Language.StringByID(R.MyInternationalizationString.uDeviceBelongId2300);
                }
            }
            else if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1)
            {
                //XXXXX(N回路)
                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;
            }
            //是否拥有配置的模块ID
            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>
        /// 非公开,设置设备的Mac名字(此方法只是单存的变更缓存)
        /// </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>
        /// 单纯获取设备的Mac名字
        /// </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>
        /// 初始化R文件里面设备默认名字的ID
        /// </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)
        {
            if (device == null)
            {
                btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png";
                return;
            }
            string unSelectFilePath = string.Empty;
            string selectFilePath = string.Empty;
            //获取设备【图标】
            this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
            btnIcon.UnSelectedImagePath = unSelectFilePath;
            btnIcon.SelectedImagePath = selectFilePath;
        }
        /// <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)
        {
            //获取设备的真实图片
            string imagePath = this.GetRealDeviceIcon(listdevice);
            btnIcon.UnSelectedImagePath = imagePath;
        }
        /// <summary>
        /// 获取设备的真实图片
        /// </summary>
        /// <param name="listdevice">设备对象</param>
        public string GetRealDeviceIcon(List<CommonDevice> listdevice)
        {
            //获取它属于什么类型的设备
            var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
            string strConcrete = Enum.GetName(typeof(DeviceConcreteType), myDeviceType.ConcreteType);
            //图片共有
            if (this.dicPictrueShard.ContainsKey(strConcrete) == true)
            {
                strConcrete = this.dicPictrueShard[strConcrete];
            }
            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 "RealDevice/CommonDevice.png";
                }
                imageFilePath = "RealDevice/" + arry[0] + ".png";
                //如果它自己的共通图片还是不存在的话,则直接使用所有设备的共通图片
                if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
                {
                    imageFilePath = "RealDevice/CommonDevice.png";
                }
            }
            return imageFilePath;
        }
        /// <summary>
        /// 设置【设备类型】的图标到指定的控件
        /// </summary>
        /// <param name="btnIcon">控件对象</param>
        /// <param name="listdevice">设备对象</param>
        /// <returns></returns>
        public void SetDeviceObjectIconToControl(Button btnIcon, List<CommonDevice> listdevice)
        {
            //获取自定义设备类型
            var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
            string imageUnSelectFilePath = string.Empty;
            string imageSelectFilePath = string.Empty;
            //获取【设备类型】的图标
            this.GetDeviceObjectIcon(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 GetDeviceObjectIcon(List<CommonDevice> listdevice, ref string unSelectPath, ref string selectPath)
        {
            //获取自定义设备类型
            var myDeviceType = this.GetMyDeviceEnumInfo(listdevice);
            //获取【设备类型】的图标
            this.GetDeviceObjectIcon(myDeviceType.ConcreteType, ref unSelectPath, ref selectPath);
        }
        /// <summary>
        /// 获取【设备类型】的图标
        /// </summary>
        /// <param name="specificType">自定义设备类型</param>
        /// <param name="unSelectPath">图片地址</param>
        /// <param name="selectPath">图片地址</param>
        /// <returns></returns>
        public void GetDeviceObjectIcon(DeviceConcreteType specificType, ref string unSelectPath, ref string selectPath)
        {
            //将具体类型转字符串
            string strSpecific = Enum.GetName(typeof(DeviceConcreteType), specificType);
            //图片共有
            if (this.dicPictrueShard.ContainsKey(strSpecific) == true)
            {
                strSpecific = this.dicPictrueShard[strSpecific];
            }
            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)
                {
                    imageFilePath = "Device/" + arry[0] + ".png";
                    imageSelectFilePath = "Device/" + arry[0] + "Selected.png";
                }
            }
            //如果那款设备连共通图片都没有的话
            if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
            {
                imageFilePath = "Device/ThirdPartyDevice.png";
                imageSelectFilePath = "Device/ThirdPartyDeviceSelected.png";
            }
            //设置图片
            unSelectPath = imageFilePath;
            selectPath = imageSelectFilePath;
        }
        #endregion
        #region ■ 设备UI相关_________________________
        /// <summary>
        /// 获取设备所匹配的设备UI对象
        /// </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>
        /// 获取设备所匹配的设备UI对象
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public DeviceUI GetDeviceUI(string filePath)
        {
            string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
            if (arry.Length != 4)
            {
                return null;
            }
            //创建一个新的东西给过去
            var deviceUi = new DeviceUI();
            deviceUi.DeviceAddr = arry[2];
            deviceUi.DeviceEpoint = Convert.ToInt32(arry[3]);
            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)
            {
                //拿拥有模块ID的那个回路来判断
                if (temp.ModelIdentifier != string.Empty)
                {
                    checkDevice = temp;
                }
            }
            //获取河东设备的设备类型
            DeviceEnumInfo info = this.GetHdlMyDeviceEnumInfo(checkDevice);
            if (info != null)
            {
                return info;
            }
            //获取第三方设备的【设备类型】
            return this.GetNotHdlMyDeviceEnumInfo(listdevice, false);
        }
        /// <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)
            {
                //拿拥有模块ID的那个回路来判断
                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, false);
                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)
            {
                //没有匹配到模块ID,则直接走第三方设备的判断
                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="device">设备回路</param>
        /// <returns></returns>
        public DeviceEnumInfo GetDeviceBelongEnumInfo(CommonDevice device)
        {
            var info = this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device });
            if (info.BeloneType == DeviceBeloneType.A调光器
                || info.BeloneType == DeviceBeloneType.A彩灯)
            {
                //归为灯光
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
                info.BeloneType = DeviceBeloneType.A灯光;
                info.ConcreteType = DeviceConcreteType.Light;
                int value = (int)info.BeloneType;
                if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + value) == true)
                {
                    //设备所属类型的翻译名字
                    info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + value];
                }
            }
            else if (info.BeloneType == DeviceBeloneType.A传感器
                || device.Type == DeviceType.TemperatureSensor)
            {
                //传感器合并
                info.BeloneType = DeviceBeloneType.A传感器;
                info.ConcreteType = DeviceConcreteType.Sensor;
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
                int value = (int)info.BeloneType;
                if (dicDeviceDefultNameID.ContainsKey("uDeviceBelongId" + value) == true)
                {
                    //设备所属类型的翻译名字
                    info.BeloneTextId = dicDeviceDefultNameID["uDeviceBelongId" + value];
                }
            }
            return info;
        }
        /// <summary>
        /// 获取第三方设备的【设备类型】(不建议使用)
        /// </summary>
        /// <param name="listdevice">Mac都一样的设备列表</param>
        /// <returns></returns>
        public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(CommonDevice device, bool margeSensor = true)
        {
            return this.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device }, margeSensor);
        }
        /// <summary>
        /// 获取第三方设备的【设备类型】(不建议使用)
        /// </summary>
        /// <param name="listdevice">Mac都一样的设备列表</param>
        /// <param name="margeSensor">
        /// <para>是否将所有类型的传感器都归为【传感器】,</para>
        /// <para>false的时候:【ConcreteType】和【ConcreteTextId】可能会有不同的值</para>
        /// <para>true的时候:【ConcreteType】统一为Sensor,【ConcreteTextId】统一为传感器</para>
        /// </param>
        /// <returns></returns>
        public DeviceEnumInfo GetNotHdlMyDeviceEnumInfo(List<CommonDevice> listdevice, bool margeSensor = true)
        {
            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)
            {
                if (listdevice.Count > 1)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId200;
                    info.BeloneType = DeviceBeloneType.A按键面板;
                    info.ConcreteType = DeviceConcreteType.ButtonPanel;
                }
                else
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId16;
                    info.BeloneType = DeviceBeloneType.A干接点;
                    info.ConcreteType = DeviceConcreteType.DryContact;
                }
            }
            //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;
                if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A开关)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
                    info.BeloneType = DeviceBeloneType.A开关;
                    info.ConcreteType = DeviceConcreteType.Switch;
                }
                else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A插座)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
                    info.BeloneType = DeviceBeloneType.A插座;
                    info.ConcreteType = DeviceConcreteType.Socket1;
                }
                else if (dicType[DeviceType.AirSwitch].DfunctionType == DeviceFunctionType.A灯光)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
                    info.BeloneType = DeviceBeloneType.A灯光;
                    info.ConcreteType = DeviceConcreteType.Light;
                }
            }
            //5继电器
            else if (dicType.ContainsKey(DeviceType.OnOffOutput) == true)
            {
                //默认值
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId2300;
                info.BeloneType = DeviceBeloneType.A继电器;
                info.ConcreteType = DeviceConcreteType.Relay;
                if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A开关)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId13;
                    info.BeloneType = DeviceBeloneType.A开关;
                    info.ConcreteType = DeviceConcreteType.Switch;
                }
                else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A插座)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId14;
                    info.BeloneType = DeviceBeloneType.A插座;
                    info.ConcreteType = DeviceConcreteType.Socket1;
                }
                else if (dicType[DeviceType.OnOffOutput].DfunctionType == DeviceFunctionType.A灯光)
                {
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId15;
                    info.BeloneType = DeviceBeloneType.A灯光;
                    info.ConcreteType = DeviceConcreteType.Light;
                }
            }
            //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.ColorLight;
            }
            //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;
            }
            //12包含传感器的话,当传感器处理
            else if (dicType.ContainsKey(DeviceType.IASZone) == true)
            {
                info.BeloneType = DeviceBeloneType.A传感器;
                info.ConcreteType = DeviceConcreteType.Sensor;
                info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId1200;
                //设置传感器具体的类型
                this.SetSensorDeviceSpecificType(ref info, listdevice);
            }
            //13包含温度传感器的话
            else if (dicType.ContainsKey(DeviceType.TemperatureSensor) == true)
            {
                bool temperatrue = false;
                bool humidity = false;
                //获取全部的回路
                var listTemp = this.GetDevicesByMac(listdevice[0].DeviceAddr, false);
                foreach (var device in listTemp)
                {
                    if (device is TemperatureSensor)
                    {
                        //温度传感器
                        if (((TemperatureSensor)device).SensorDiv == 1)
                        {
                            temperatrue = true;
                        }
                        //湿度传感器
                        else if (((TemperatureSensor)device).SensorDiv == 2)
                        {
                            humidity = true;
                        }
                    }
                }
                if (temperatrue == true && humidity == true)
                {
                    //设置传感器具体的类型
                    info.BeloneType = DeviceBeloneType.A温湿度传感器;
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId10;
                    info.ConcreteType = DeviceConcreteType.Sensor_TemperatureHumidity;
                }
                else if (temperatrue == true && humidity == false)
                {
                    //设置传感器具体的类型
                    info.BeloneType = DeviceBeloneType.A温度传感器;
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId11;
                    info.ConcreteType = DeviceConcreteType.Sensor_Temperature;
                }
                else if (temperatrue == false && humidity == true)
                {
                    //设置传感器具体的类型
                    info.BeloneType = DeviceBeloneType.A湿度传感器;
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId12;
                    info.ConcreteType = DeviceConcreteType.Sensor_Humidity;
                }
            }
            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)
        {
            //如果这个设备拥有多个回路的话,我也不知道怎么命名,只能给个默认名字
            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>
        private void InitRealDeviceRoomId()
        {
            this.dicDeviceRoomId = new Dictionary<string, string>();
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
            var strData = UserCenterLogic.LoadFileContent(fullName);
            if (strData != null)
            {
                this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
            }
        }
        /// <summary>
        /// 保存物理设备所属房间的记录
        /// </summary>
        /// <param name="listDevice">需要保存的设备对象</param>
        /// <param name="roomId">需要保存的哪个设备的房间ID</param>
        /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
        public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
        {
            if (listDevice != null)
            {
                this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
            }
            //保存记录
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
            UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
            //添加自动备份
            HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
            //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
            if (saveRoadDevice == true && listDevice != null && listDevice.Count == 1)
            {
                if (listDevice[0] is OTADevice)
                {
                    //单纯只是Ota设备则不处理
                    return;
                }
                Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId, false);
            }
        }
        /// <summary>
        /// 获取真实物理设备的房间名字
        /// </summary>
        /// <param name="device">设备的某一个回路</param>
        /// <returns></returns>
        public string GeteRealDeviceRoomName(CommonDevice device)
        {
            if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
            {
                //未分配区域
                return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
            }
            var room = Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
            if (room != null)
            {
                return room.Name;
            }
            //未分配区域
            return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
        }
        /// <summary>
        /// 获取真实物理设备属于哪个房间
        /// </summary>
        /// <param name="device">设备的某一个回路</param>
        /// <returns></returns>
        public Room GeteRealDeviceRoom(CommonDevice device)
        {
            if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
            {
                return null;
            }
            return Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
        }
        #endregion
        #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>
        /// 交换设备的模块ID
        /// </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)
        {
            //直接是10进制
            string txt10 = Convert.ToString(versionValue).PadLeft(4, '0');
            //这个是小数点前面的值
            int value1 = Convert.ToInt32(txt10.Substring(0, txt10.Length - 2));
            //这个是小数点后面的值
            int value2 = Convert.ToInt32(txt10.Substring(txt10.Length - 2, 2));
            //Ver.
            string ver = Language.StringByID(R.MyInternationalizationString.uVersionAbbreviation);
            return ver + value1 + "." + value2.ToString().PadLeft(2, '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>
        /// <para>从网关重新获取设备列表(返回的设备为虚拟出来的)</para>
        /// <para>statu状态 -1:异常,会返回null, 1:没有异常, 2:数据接收不全</para>
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        /// <param name="statu">状态-> -1:异常,会返回null, 1:没有异常, 2:数据接收不全</param>
        /// <param name="ignoreTime">是否无视时间(此变量是给获取在线状态用的),true:每次调用都去网关获取,false:3分钟内返回的是本地的设备</param>
        /// <param name="mode">是否显示错误</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;
        public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, ref int statu, bool ignoreTime, ShowErrorMode mode = ShowErrorMode.YES)
        {
            if (ignoreTime == false)
            {
                if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000)
                {
                    //不无视时间,返回本地设备列表
                    statu = 1;
                    return this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway));
                }
            }
            zbGateway.LastDateTime = DateTime.Now;
            //如果切换到了别的界面,则不显示错误信息
            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);
                }
                statu = -1;
                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>();
            //网关里面有可能会有重复的回路
            var listCheck = new HashSet<string>();
            Action<string, string> getDeviceAction = (topic, message) =>
            {
                if (topic == gatewayID + "/" + "DeviceInfoRespon")
                {
                    try
                    {
                        lock (listDevice)
                        {
                            //设备接收数
                            receiveCount++;
                            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;
                            }
                            var deviceID = (DeviceType)jobject.Value<int>("Device_ID");
                            //根据设备类型创建设备对象的实例
                            var device = this.NewDeviceObjectByDeviceId(deviceID, jobject, zbGateway);
                            if (device != null)
                            {
                                string mainkeys = this.GetDeviceMainKeys(device);
                                //网关里面有可能会有重复的回路
                                if (listCheck.Contains(mainkeys) == false)
                                {
                                    listDevice.Add(device);
                                    listCheck.Add(mainkeys);
                                }
                            }
                        }
                    }
                    //Log出力
                    catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                    if (receiveCount == deviceCount && deviceCount != -1)
                    {
                        //设备全部接收完成
                        canBreak = true;
                    }
                }
            };
            realWay.Actions += getDeviceAction;
            try
            {
                var jObject = new Newtonsoft.Json.Linq.JObject { { "Cluster_ID", 0 }, { "Command", 93 } };
                realWay.Send("GetDeviceInfo", jObject.ToString());
            }
            catch { canBreak = true; }
            while (canBreak == false && TimeOut < 60)
            {
                System.Threading.Thread.Sleep(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.ShowTipMsg(msg);
                    }
                    statu = -1;
                    return null;
                }
                else
                {
                    if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
                    {
                        //网络不稳定,设备列表信息缺损
                        string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
                        this.ShowTipMsg(msg);
                    }
                    statu = 2;
                }
            }
            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;
            }
            //是否拥有配置的模块ID
            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>
        /// 非公开,设置设备的Mac名字(此方法只是单存的变更缓存)
        /// </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>
        /// 单纯获取设备的Mac名字
        /// </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>
        /// 初始化R文件里面设备默认名字的ID
        /// </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)
        {
            if (device == null)
            {
                btnIcon.UnSelectedImagePath = "Device/ThirdPartyDevice.png";
                return;
            }
            string unSelectFilePath = string.Empty;
            string selectFilePath = string.Empty;
            //获取设备【图标】
            this.GetDeviceIcon(device, ref unSelectFilePath, ref selectFilePath);
            btnIcon.UnSelectedImagePath = unSelectFilePath;
            btnIcon.SelectedImagePath = selectFilePath;
        }
        /// <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";
                //如果它自己的共通图片还是不存在的话,则直接使用所有设备的共通图片
                if (string.IsNullOrEmpty(IO.FileUtils.GetImageFilePath(imageFilePath)) == true)
                {
                    imageFilePath = "RealDevice/CommonDevice.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>
        /// 获取设备所匹配的设备UI对象
        /// </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>
        /// 获取设备所匹配的设备UI对象
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public DeviceUI GetDeviceUI(string filePath)
        {
            string[] arry = filePath.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
            if (arry.Length != 4)
            {
                return null;
            }
            //创建一个新的东西给过去
            var deviceUi = new DeviceUI();
            deviceUi.DeviceAddr = arry[2];
            deviceUi.DeviceEpoint = Convert.ToInt32(arry[3]);
            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)
            {
                //拿拥有模块ID的那个回路来判断
                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)
            {
                //拿拥有模块ID的那个回路来判断
                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)
            {
                //没有匹配到模块ID,则直接走第三方设备的判断
                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.ColorLight;
            }
            //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;
            }
            //12包含传感器的话,当传感器处理
            else if (dicType.ContainsKey(DeviceType.IASZone) == true)
            {
                //设置传感器具体的类型
                info.BeloneType = DeviceBeloneType.A传感器;
                this.SetSensorDeviceSpecificType(ref info, listdevice);
            }
            //13包含温度传感器的话
            else if (dicType.ContainsKey(DeviceType.TemperatureSensor) == true)
            {
                bool temperatrue = false;
                bool humidity = false;
                foreach (var device in listdevice)
                {
                    if (device is TemperatureSensor)
                    {
                        //温度传感器
                        if (((TemperatureSensor)device).SensorDiv == 1)
                        {
                            temperatrue = true;
                        }
                        //湿度传感器
                        else if (((TemperatureSensor)device).SensorDiv == 2)
                        {
                            humidity = true;
                        }
                    }
                }
                if (temperatrue == true && humidity == true)
                {
                    //设置传感器具体的类型
                    info.BeloneType = DeviceBeloneType.A温湿度传感器;
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId10;
                    info.ConcreteType = DeviceConcreteType.Sensor_TemperatrueHumidity;
                }
                else if (temperatrue == true && humidity == false)
                {
                    //设置传感器具体的类型
                    info.BeloneType = DeviceBeloneType.A温度传感器;
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId11;
                    info.ConcreteType = DeviceConcreteType.Sensor_Temperatrue;
                }
                else if (temperatrue == false && humidity == true)
                {
                    //设置传感器具体的类型
                    info.BeloneType = DeviceBeloneType.A湿度传感器;
                    info.ConcreteTextId = R.MyInternationalizationString.uDeviceBelongId12;
                    info.ConcreteType = DeviceConcreteType.Sensor_Humidity;
                }
            }
            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>
        private void InitRealDeviceRoomId()
        {
            this.dicDeviceRoomId = new Dictionary<string, string>();
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
            var strData = UserCenterLogic.LoadFileContent(fullName);
            if (strData != null)
            {
                this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
            }
        }
        /// <summary>
        /// 保存物理设备所属房间的记录
        /// </summary>
        /// <param name="listDevice">需要保存的设备对象</param>
        /// <param name="roomId">需要保存的哪个设备的房间ID</param>
        public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId)
        {
            if (listDevice != null)
            {
                this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
            }
            //保存记录
            string fullName = UserCenterLogic.CombinePath(DirNameResourse.DeviceRoomIdFile);
            UserCenterLogic.SaveFileContent(fullName, this.dicDeviceRoomId);
            //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
            if (listDevice != null && listDevice.Count == 1)
            {
                Common.Room.CurrentRoom.ChangedRoom(listDevice[0], roomId);
            }
        }
        /// <summary>
        /// 获取真实物理设备的房间名字
        /// </summary>
        /// <param name="device">设备的某一个回路</param>
        /// <returns></returns>
        public string GeteRealDeviceRoomName(CommonDevice device)
        {
            if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
            {
                //未分配区域
                return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
            }
            var room = Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
            if (room != null)
            {
                return room.Name;
            }
            //未分配区域
            return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
        }
        /// <summary>
        /// 获取真实物理设备属于哪个房间
        /// </summary>
        /// <param name="device">设备的某一个回路</param>
        /// <returns></returns>
        public Room GeteRealDeviceRoom(CommonDevice device)
        {
            if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
            {
                return null;
            }
            return Room.CurrentRoom.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
        }
        #endregion
        #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>
        /// 交换设备的模块ID
        /// </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>
        /// 从网关重新获取设备列表(★★★★★★★接收到设备时的事件★★★★★★★)
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        /// <param name="ignoreTime">是否无视时间,true:每次调用都去网关获取,false:3分钟内返回的是本地的设备</param>
        /// <param name="deviceComingAction">接收到设备时的事件</param>
        /// <param name="mode">是否显示错误</param>
        /// <returns></returns>
        public List<CommonDevice> GetDeviceListFromGateway(ZbGateway zbGateway, bool ignoreTime, Action<CommonDevice> deviceComingAction = null, ShowErrorMode mode = ShowErrorMode.YES)
        {
            if (ignoreTime == false)
            {
                if ((DateTime.Now - zbGateway.LastDateTime).TotalMilliseconds < 3 * 60 * 1000)
                {
                    //不无视时间,返回本地设备列表
                    var listTemp = this.GetDeviceByGatewayID(HdlGatewayLogic.Current.GetGatewayId(zbGateway));
                    if (deviceComingAction != null)
                    {
                        for (int i = 0; i < listTemp.Count; i++)
                        {
                            try
                            {
                                //回调函数
                                deviceComingAction.Invoke(listTemp[i]);
                            }
                            //Log出力
                            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                        }
                    }
                    deviceComingAction = null;
                    return listTemp;
                }
            }
            zbGateway.LastDateTime = DateTime.Now;
            //如果切换到了别的界面,则不显示错误信息
            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)
                        {
                            try
                            {
                                //回调函数
                                deviceComingAction?.Invoke(device);
                            }
                            //Log出力
                            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
                            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 } };
                realWay.Send("GetDeviceInfo", jObject.ToString());
            }
            catch { canBreak = true; }
            while (canBreak == false && TimeOut < 60)
            {
                System.Threading.Thread.Sleep(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.ShowTipMsg(msg);
                    }
                    return null;
                }
                else
                {
                    if (nowFormId == UserCenterResourse.NowActionFormID && mode == ShowErrorMode.YES)
                    {
                        //网络不稳定,设备列表信息缺损
                        string msg = Language.StringByID(R.MyInternationalizationString.uNetworkUnStableAndDeviceInfoIsNotFull);
                        this.ShowTipMsg(msg);
                    }
                }
            }
            //回调函数(接收完成)
            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 = 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;
            //将DeviceInfo的属性设置到主属性中
            this.SetDeviceInfoToMain(device, device);
            return device;
        }
        /// <summary>
        /// 将DeviceInfo的属性设置到主属性中
        /// </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.Type = device.Type;
            //固件版本
            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);
            //如果是温度传感器
            if (mainDevice.Type == DeviceType.TemperatureSensor)
            {
                //输出族 1026:温度传感器 1029:湿度传感器
                foreach (var data in mainDevice.OutClusterList)
                {
                    if (data.OutCluster == 1029)
                    {
                        ((TemperatureSensor)mainDevice).SensorDiv = 2;
                    }
                    else if (data.OutCluster == 1026)
                    {
                        ((TemperatureSensor)mainDevice).SensorDiv = 1;
                    }
                }
            }
            //如果是调光器
            else if (mainDevice.Type == DeviceType.DimmableLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/Light.png";
                }
            }
            //如果是彩灯的话
            else if (mainDevice.Type == DeviceType.ColorDimmableLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/ColorLight.png";
                }
            }
        }
        /// <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.TemperatureSensor) { device = new TemperatureSensor(); }
            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 ■ 自定义设备模块ID___________________
        /// <summary>
        /// 初始化设备的模块ID的枚举
        /// </summary>
        private void InitDeviceModelIdEnum()
        {
            if (this.dicDeviceModelIdEnum != null)
            {
                return;
            }
            this.dicDeviceModelIdEnum = new Dictionary<string, string>();
            //定义规则:模块ID(已翻译)=设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
            //第一个值是: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.10"] = "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转buspro协议转换器
            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
    }
    #region ■ 自定义设备类型_________________________
    /// <summary>
    /// <para>仅限底层使用:设备的具体【设备类型】,自定义与模块id关联的枚举(值为LocalDevice里面dicDeviceModelIdEnum所指定的值)</para>
    /// <para>变量名可以作为【设备类型】图片,这个值是瞎写的,没什么特殊意义</para>
    /// </summary>
    public enum DeviceConcreteType
    {
        //定义规则:【设备类型】图片名字=LocalDevice里面dicDeviceModelIdEnum所指定的值
        /// <summary>
        /// 未知设备
        /// </summary>
        UnKownDevice = -1,
        //=========★★窗帘类(100-199)★★=========
        /// <summary>
        /// 窗帘
        /// </summary>
        Curtain = -100,
        /// <summary>
        /// 智能开合帘电机 镜像id:100
        /// </summary>
        Curtain_AutoOpen = 100,
        /// <summary>
        /// 智能管状电机 镜像id:101
        /// </summary>
        Curtain_Siphonate = 101,
        //=========★★按键面板类(200-1199)★★=========
        /// <summary>
        /// 按键面板
        /// </summary>
        ButtonPanel = -200,
        /// <summary>
        /// 4按键多功能触摸面板(带4路继电器底座) 镜像id:200
        /// </summary>
        ButtonPanel_Four = 200,
        /// <summary>
        /// 3按键多功能触摸面板(带3路继电器底座) 镜像id:201
        /// </summary>
        ButtonPanel_Three = 201,
        /// <summary>
        /// 2按键多功能触摸面板(带2路继电器底座) 镜像id:202
        /// </summary>
        ButtonPanel_Two = 202,
        /// <summary>
        /// 12按键多功能触摸面板(带1路继电器底座) 镜像id:203
        /// </summary>
        ButtonPanel_Twelve = 203,
        /// <summary>
        /// 4按键多功能触摸面板(只带电源底座) 镜像id:210
        /// </summary>
        ButtonPanel_FourNotPower = 210,
        //=========★★PIR传感器类(1200-1299)★★=========
        /// <summary>
        /// 传感器
        /// </summary>
        Sensor = -1200,
        /// <summary>
        /// pir传感器220 镜像id:1200
        /// </summary>
        Sensor_Pir = 1200,
        //=========★★安防类传感器类(1300-2299)★★=========
        /// <summary>
        /// 燃气传感器
        /// </summary>
        Sensor_CarbonMonoxide = 1300,
        /// <summary>
        /// 门窗传感器
        /// </summary>
        Sensor_DoorWindow = 1301,
        /// <summary>
        /// 烟雾传感器
        /// </summary>
        Sensor_Fire = 1302,
        /// <summary>
        /// 红外传感器
        /// </summary>
        Sensor_Infrared = 1303,
        /// <summary>
        /// 水侵传感器
        /// </summary>
        Sensor_Water = 1304,
        /// <summary>
        /// 紧急按钮
        /// </summary>
        Sensor_EmergencyButton = 1305,
        /// <summary>
        /// 运动传感器
        /// </summary>
        Sensor_Motion = -1306,
        /// <summary>
        /// 钥匙扣
        /// </summary>
        Sensor_Keyfob = -1307,
        /// <summary>
        /// 温湿度传感器
        /// </summary>
        Sensor_TemperatrueHumidity = -1308,
        /// <summary>
        /// 温度传感器
        /// </summary>
        Sensor_Temperatrue = -1309,
        /// <summary>
        /// 湿度传感器
        /// </summary>
        Sensor_Humidity = -1310,
        //=========★★继电器类(2300-2499)★★=========
        /// <summary>
        /// 继电器
        /// </summary>
        Relay = -2300,
        /// <summary>
        /// 三路继电器 镜像id:2300
        /// </summary>
        Relay_ThreeLoad = 2300,
        //=========★★调光器类(2500-2799)★★=========
        /// <summary>
        /// 调光器
        /// </summary>
        DimmableLight = -2500,
        /// <summary>
        /// 1路调光器小模块
        /// </summary>
        DimmableLight_OneLoad = 2500,
        //=========★★智能门锁类(2800-????)★★=========
        /// <summary>
        /// 智能门锁
        /// </summary>
        IntelligentLocks = -2800,
        /// <summary>
        /// H06C
        /// </summary>
        IntelligentLocks_H06C = 2800,
        //=========★★彩灯类(????-????)★★=========
        /// <summary>
        /// 彩灯
        /// </summary>
        ColorLight = -10,
        //=========★★空调(3600-3899)★★=========
        /// <summary>
        /// 空调
        /// </summary>
        AirConditioner = -3600,
        /// <summary>
        /// zigbee空调网关模块
        /// </summary>
        AirConditioner_ZbGateway = 3600,
        //=========★★中继器(3900-3999)★★=========
        /// <summary>
        /// 中继器
        /// </summary>
        Repeater = -3900,
        /// <summary>
        /// zigbee中继器 镜像id:3900
        /// </summary>
        Repeater_Zigbee = 3900,
        //=========★★空气开关类(4100-????)★★=========
        /// <summary>
        /// 智能空气开关
        /// </summary>
        AirSwitch = -4100,
        /// <summary>
        /// 微断云控制器 镜像id:4100
        /// </summary>
        AirSwitch_CloudContr = 4100,
        //=========★★转换器类(4200-4699)★★=========
        /// <summary>
        /// 转换器
        /// </summary>
        Converter = -4200,
        /// <summary>
        /// zigbee转485协议转换器
        /// </summary>
        Converter_Zb485 = 4200,
        /// <summary>
        /// zigbee转buspro协议转换器
        /// </summary>
        Converter_ZbBuspro = 4201,
    }
    /// <summary>
    /// <para>仅限底层使用:设备所属的【设备种类】,自定义与模块id关联的枚举(值为LocalDevice里面dicDeviceModelIdEnum所指定的值)</para>
    /// <para>这个值是瞎写的,没什么特殊意义</para>
    /// </summary>
    public enum DeviceBeloneType
    {
        /// <summary>
        /// 未知设备
        /// </summary>
        A未知设备 = 0,
        /// <summary>
        /// 窗帘(100-199)
        /// </summary>
        A窗帘 = 100,
        /// <summary>
        /// 按键面板(200-1199)
        /// </summary>
        A按键面板 = 200,
        /// <summary>
        /// 传感器(1200-2299)
        /// </summary>
        A传感器 = 1200,
        /// <summary>
        /// 继电器(2300-2499)
        /// </summary>
        A继电器 = 2300,
        /// <summary>
        /// 调光器(2500-2799)
        /// </summary>
        A调光器 = 2500,
        /// <summary>
        /// 智能门锁(2800-????)
        /// </summary>
        A智能门锁 = 2800,
        /// <summary>
        /// 空调(3600-3899)
        /// </summary>
        A空调 = 3600,
        /// <summary>
        /// 中继器(3900-3999)
        /// </summary>
        A中继器 = 3900,
        /// <summary>
        /// 空气开关(4100-4199)
        /// </summary>
        A空气开关 = 4100,
        /// <summary>
        /// 转换器(4200-4699)
        /// </summary>
        A转换器 = 4200,
        /// <summary>
        /// 彩灯
        /// </summary>
        A彩灯 = 9,
        /// <summary>
        /// 温湿度传感器
        /// </summary>
        A温湿度传感器 = 10,
        /// <summary>
        /// 温度传感器
        /// </summary>
        A温度传感器 = 11,
        /// <summary>
        /// 湿度传感器
        /// </summary>
        A湿度传感器 = 12
    }
    #endregion
}
        }
        #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;
            //将DeviceInfo的属性设置到主属性中
            this.SetDeviceInfoToMain(device, device);
            return device;
        }
        /// <summary>
        /// 将DeviceInfo的属性设置到主属性中
        /// </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.Type = device.Type;
            //固件版本
            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);
            //如果是温度传感器
            if (mainDevice.Type == DeviceType.TemperatureSensor)
            {
                //输出族 1026:温度传感器 1029:湿度传感器
                foreach (var data in mainDevice.OutClusterList)
                {
                    if (data.OutCluster == 1029)
                    {
                        ((TemperatureSensor)mainDevice).SensorDiv = 2;
                    }
                    else if (data.OutCluster == 1026)
                    {
                        ((TemperatureSensor)mainDevice).SensorDiv = 1;
                    }
                }
            }
            //如果是调光器
            else if (mainDevice.Type == DeviceType.DimmableLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/Light.png";
                }
            }
            //如果是彩灯的话
            else if (mainDevice.Type == DeviceType.ColorDimmableLight)
            {
                mainDevice.DfunctionType = DeviceFunctionType.A灯光;
                if (mainDevice.IsCustomizeImage == false)
                {
                    mainDevice.IconPath = "Device/ColorLight.png";
                }
            }
        }
        /// <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.TemperatureSensor) { device = new TemperatureSensor(); }
            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 ■ 自定义设备模块ID___________________
        /// <summary>
        /// 初始化设备的模块ID的枚举
        /// </summary>
        private void InitDeviceModelIdEnum()
        {
            if (this.dicDeviceModelIdEnum != null)
            {
                return;
            }
            this.dicDeviceModelIdEnum = new Dictionary<string, string>();
            //定义规则:模块ID(已翻译)=设备具体类型值-设备所属类型值(自定义的值,嘛,只要不重复就可以)
            //第一个值是:DeviceConcreteType  第二个值是:DeviceBeloneType
            //*********************************************************************
            //新设备添加方法:
            //1、在这里填写上模块ID,然后是 DeviceConcreteType ,然后是 DeviceBeloneType
            //2、然后在最下面添加【设备的具体类型】,【设备的所属类型】
            //3、已设备的具体类型为名字(去掉【-】)添加设备的【所属图片】,【真实物理图片】。回路图片需要特殊处理
            //4、添加R文件,添加Language文件
            //*********************************************************************
            //=========★★开合帘类(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按键触摸面板(只带电源底座)
            this.dicDeviceModelIdEnum["MPT4R4L/S-ZB.18"] = "220-200";//简约4按键面板
            this.dicDeviceModelIdEnum["MPT3R3L/S-ZB.18"] = "221-200";//简约3按键面板
            this.dicDeviceModelIdEnum["MPT2R2L/S-ZB.18"] = "222-200";//简约2按键面板
            //=========★★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.10"] = "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转buspro协议转换器
            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";//紧急按键
            //✩✩✩✩✩需要共有的图片对象✩✩✩✩✩
            this.dicPictrueShard = new Dictionary<string, string>();
            this.dicPictrueShard["ButtonPanel_SimpleFour"] = "ButtonPanel_Four";//简约4按键面板 沿用 4按键的图标
            this.dicPictrueShard["ButtonPanel_SimpleThree"] = "ButtonPanel_Three";//简约3按键面板 沿用 3按键的图标
            this.dicPictrueShard["ButtonPanel_SimpleTwo"] = "ButtonPanel_Two";//简约2按键面板 沿用 2按键的图标
        }
        #endregion
    }
    #region ■ 自定义设备类型_________________________
    /// <summary>
    /// <para>仅限底层使用:设备的具体【设备类型】,自定义与模块id关联的枚举(值为LocalDevice里面dicDeviceModelIdEnum所指定的值)</para>
    /// <para>变量名可以作为【设备类型】图片,这个值是瞎写的,没什么特殊意义</para>
    /// </summary>
    public enum DeviceConcreteType
    {
        //定义规则:【设备类型】图片名字=LocalDevice里面dicDeviceModelIdEnum所指定的值
        /// <summary>
        /// 未知设备
        /// </summary>
        UnKownDevice = -1,
        //=========★★窗帘类(100-199)★★=========
        /// <summary>
        /// 窗帘
        /// </summary>
        Curtain = -100,
        /// <summary>
        /// 智能开合帘电机 镜像id:100
        /// </summary>
        Curtain_AutoOpen = 100,
        /// <summary>
        /// 智能管状电机 镜像id:101
        /// </summary>
        Curtain_Siphonate = 101,
        //=========★★按键面板类(200-1199)★★=========
        /// <summary>
        /// 按键面板
        /// </summary>
        ButtonPanel = -200,
        /// <summary>
        /// 4按键多功能触摸面板(带4路继电器底座) 镜像id:200
        /// </summary>
        ButtonPanel_Four = 200,
        /// <summary>
        /// 3按键多功能触摸面板(带3路继电器底座) 镜像id:201
        /// </summary>
        ButtonPanel_Three = 201,
        /// <summary>
        /// 2按键多功能触摸面板(带2路继电器底座) 镜像id:202
        /// </summary>
        ButtonPanel_Two = 202,
        /// <summary>
        /// 12按键多功能触摸面板(带1路继电器底座) 镜像id:203
        /// </summary>
        ButtonPanel_Twelve = 203,
        /// <summary>
        /// 4按键多功能触摸面板(只带电源底座) 镜像id:210
        /// </summary>
        ButtonPanel_FourNotPower = 210,
        /// <summary>
        /// 简约4按键面板 镜像id:220
        /// </summary>
        ButtonPanel_SimpleFour = 220,
        /// <summary>
        /// 简约3按键面板 镜像id:221
        /// </summary>
        ButtonPanel_SimpleThree = 221,
        /// <summary>
        /// 简约2按键面板 镜像id:222
        /// </summary>
        ButtonPanel_SimpleTwo = 222,
        //=========★★PIR传感器类(1200-1299)★★=========
        /// <summary>
        /// 传感器
        /// </summary>
        Sensor = -1200,
        /// <summary>
        /// pir传感器220 镜像id:1200
        /// </summary>
        Sensor_Pir = 1200,
        //=========★★安防类传感器类(1300-2299)★★=========
        /// <summary>
        /// 燃气传感器
        /// </summary>
        Sensor_CarbonMonoxide = 1300,
        /// <summary>
        /// 门窗传感器
        /// </summary>
        Sensor_DoorWindow = 1301,
        /// <summary>
        /// 烟雾传感器
        /// </summary>
        Sensor_Fire = 1302,
        /// <summary>
        /// 红外传感器
        /// </summary>
        Sensor_Infrared = 1303,
        /// <summary>
        /// 水侵传感器
        /// </summary>
        Sensor_Water = 1304,
        /// <summary>
        /// 紧急按钮
        /// </summary>
        Sensor_EmergencyButton = 1305,
        /// <summary>
        /// 运动传感器
        /// </summary>
        Sensor_Motion = -1306,
        /// <summary>
        /// 钥匙扣
        /// </summary>
        Sensor_Keyfob = -1307,
        /// <summary>
        /// 温湿度传感器
        /// </summary>
        Sensor_TemperatureHumidity = -1308,
        /// <summary>
        /// 温度传感器
        /// </summary>
        Sensor_Temperature = -1309,
        /// <summary>
        /// 湿度传感器
        /// </summary>
        Sensor_Humidity = -1310,
        //=========★★继电器类(2300-2499)★★=========
        /// <summary>
        /// 继电器
        /// </summary>
        Relay = -2300,
        /// <summary>
        /// 三路继电器 镜像id:2300
        /// </summary>
        Relay_ThreeLoad = 2300,
        //=========★★调光器类(2500-2799)★★=========
        /// <summary>
        /// 调光器
        /// </summary>
        DimmableLight = -2500,
        /// <summary>
        /// 1路调光器小模块
        /// </summary>
        DimmableLight_OneLoad = 2500,
        //=========★★智能门锁类(2800-????)★★=========
        /// <summary>
        /// 智能门锁
        /// </summary>
        IntelligentLocks = -2800,
        /// <summary>
        /// H06C
        /// </summary>
        IntelligentLocks_H06C = 2800,
        //=========★★彩灯类(????-????)★★=========
        /// <summary>
        /// 彩灯
        /// </summary>
        ColorLight = -10,
        //=========★★空调(3600-3899)★★=========
        /// <summary>
        /// 空调
        /// </summary>
        AirConditioner = -3600,
        /// <summary>
        /// zigbee空调网关模块
        /// </summary>
        AirConditioner_ZbGateway = 3600,
        //=========★★中继器(3900-3999)★★=========
        /// <summary>
        /// 中继器
        /// </summary>
        Repeater = -3900,
        /// <summary>
        /// zigbee中继器 镜像id:3900
        /// </summary>
        Repeater_Zigbee = 3900,
        //=========★★空气开关类(4100-????)★★=========
        /// <summary>
        /// 智能空开
        /// </summary>
        AirSwitch = -4100,
        /// <summary>
        /// 智能空开 镜像id:4100
        /// </summary>
        AirSwitch_CloudContr = 4100,
        //=========★★转换器类(4200-4699)★★=========
        /// <summary>
        /// 转换器
        /// </summary>
        Converter = -4200,
        /// <summary>
        /// zigbee转485协议转换器
        /// </summary>
        Converter_Zb485 = 4200,
        /// <summary>
        /// zigbee转buspro协议转换器
        /// </summary>
        Converter_ZbBuspro = 4201,
        //=========★★其他类(????-????)★★=========
        /// <summary>
        /// 干接点(注意,它属于其他类,不是设备类型)
        /// </summary>
        DryContact = -10000,
        /// <summary>
        /// 灯光(注意,它属于其他类,不是设备类型)
        /// </summary>
        Light = -10001,
        /// <summary>
        /// 插座(注意,它属于其他类,不是设备类型)
        /// </summary>
        Socket1 = -10002,
        /// <summary>
        /// 开关(注意,它属于其他类,不是设备类型)
        /// </summary>
        Switch = -10003,
    }
    /// <summary>
    /// <para>仅限底层使用:设备所属的【设备种类】,自定义与模块id关联的枚举(值为LocalDevice里面dicDeviceModelIdEnum所指定的值)</para>
    /// <para>这个值是瞎写的,没什么特殊意义</para>
    /// </summary>
    public enum DeviceBeloneType
    {
        /// <summary>
        /// 未知设备
        /// </summary>
        A未知设备 = 0,
        /// <summary>
        /// 窗帘(100-199)
        /// </summary>
        A窗帘 = 100,
        /// <summary>
        /// 按键面板(200-1199)
        /// </summary>
        A按键面板 = 200,
        /// <summary>
        /// 传感器(1200-2299)
        /// </summary>
        A传感器 = 1200,
        /// <summary>
        /// 继电器(2300-2499)
        /// </summary>
        A继电器 = 2300,
        /// <summary>
        /// 调光器(2500-2799)
        /// </summary>
        A调光器 = 2500,
        /// <summary>
        /// 智能门锁(2800-????)
        /// </summary>
        A智能门锁 = 2800,
        /// <summary>
        /// 空调(3600-3899)
        /// </summary>
        A空调 = 3600,
        /// <summary>
        /// 中继器(3900-3999)
        /// </summary>
        A中继器 = 3900,
        /// <summary>
        /// 智能空开(4100-4199)
        /// </summary>
        A智能空开 = 4100,
        /// <summary>
        /// 转换器(4200-4699)
        /// </summary>
        A转换器 = 4200,
        /// <summary>
        /// 彩灯
        /// </summary>
        A彩灯 = 9,
        /// <summary>
        /// 温湿度传感器
        /// </summary>
        A温湿度传感器 = 10,
        /// <summary>
        /// 温度传感器
        /// </summary>
        A温度传感器 = 11,
        /// <summary>
        /// 湿度传感器
        /// </summary>
        A湿度传感器 = 12,
        /// <summary>
        /// 开关
        /// </summary>
        A开关 = 13,
        /// <summary>
        /// 插座
        /// </summary>
        A插座 = 14,
        /// <summary>
        /// 灯光
        /// </summary>
        A灯光 = 15,
        /// <summary>
        /// 干接点
        /// </summary>
        A干接点 = 16
    }
    #endregion
}