| | |
| | | }
|
| | | }
|
| | | /// <summary>
|
| | | /// 本地所有设备的缓存(排序)
|
| | | /// 本地所有设备的缓存
|
| | | /// </summary>
|
| | | public List<CommonDevice> listAllDevice
|
| | | {
|
| | |
| | |
|
| | | //获取这个网关的本地所有设备
|
| | | string gwID = HdlGatewayLogic.Current.GetGatewayId(zbGateway);
|
| | | List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID);
|
| | | List<CommonDevice> listLocalDevices = this.GetDeviceByGatewayID(gwID, true);
|
| | | Dictionary<string, CommonDevice> dicExist = new Dictionary<string, CommonDevice>();
|
| | | foreach (var device in listLocalDevices)
|
| | | {
|
| | |
| | | for (int i = 0; i < listDevice.Count; i++)
|
| | | {
|
| | | var device = listDevice[i];
|
| | | //对未命名的设备重新命名
|
| | | if (this.GetSimpleEpointName(device) == string.Empty)
|
| | | //对未命名的虚拟设备重新命名
|
| | | if (device.DriveCode > 0 && 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) + ")";
|
| | | }
|
| | | //在端点名字的后面附加【回路】字样
|
| | | dName += "(" + device.DeviceEpoint + Language.StringByID(R.MyInternationalizationString.uDeviceCircuit) + ")";
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | |
| | | }
|
| | |
|
| | | //只有完全获取的时候,才会去处理删除的问题
|
| | | if (statu == 1)
|
| | | if (statu != 1)
|
| | | {
|
| | | //如果本地和网关的设备不一致的时候,删除本地的设备
|
| | | foreach (var device in dicExist.Values)
|
| | | return statu;
|
| | | }
|
| | |
|
| | | //如果本地和网关的设备不一致的时候,删除本地的设备
|
| | | foreach (var device in dicExist.Values)
|
| | | {
|
| | | if (device is OTADevice)
|
| | | {
|
| | | this.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | }
|
| | | else
|
| | | {
|
| | | this.DeleteMemmoryDevice(device, true);
|
| | | }
|
| | |
| | | lock (dicAllDevice)
|
| | | {
|
| | | string mainKeys = this.GetDeviceMainKeys(device);
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == false)
|
| | | if (this.dicAllDevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | | device.ReSave();
|
| | | //一般设备
|
| | | this.dicAllDevice[mainKeys] = device;
|
| | | device.ReSave();
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | | }
|
| | | else if (this.dicOTADevice.ContainsKey(mainKeys) == true)
|
| | | {
|
| | | //Ota设备
|
| | | this.dicOTADevice[mainKeys] = (OTADevice)device;
|
| | | device.ReSave();
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(device.FilePath);
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | //删除文件
|
| | | //删除缓存的Ota设备
|
| | | this.DeleteMemmoryOtaDevice(listdevice[0].DeviceAddr);
|
| | | //删除一般设备文件
|
| | | foreach (CommonDevice device in listdevice)
|
| | | {
|
| | | this.DeleteMemmoryDevice(device);
|
| | | }
|
| | |
|
| | | if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
|
| | | {
|
| | | //移除真实设备的房间索引
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 删除缓存的设备
|
| | | /// 删除缓存的一般设备
|
| | | /// </summary>
|
| | | /// <param name="device">设备对象</param>
|
| | | /// <param name="deleteRoom">是否从房间删除</param>
|
| | |
| | | {
|
| | | this.dicAllDevice.Remove(mainKeys);
|
| | | }
|
| | | if (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true)
|
| | | {
|
| | | //变更端点数
|
| | | this.dicDeviceEpoint[device.DeviceAddr].Remove(device.DeviceEpoint);
|
| | | }
|
| | | }
|
| | |
|
| | | //删除设备文件
|
| | |
| | | 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(device.DeviceAddr, 200);
|
| | | string otaKeys = this.GetDeviceMainKeys(macAdrr, ePoint);
|
| | | if (this.dicOTADevice.ContainsKey(otaKeys) == true)
|
| | | {
|
| | | string otaFile = this.dicOTADevice[otaKeys].FilePath;
|
| | |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 3)
|
| | | {
|
| | | //成员的话,直接删除,没有商量的余地
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | Global.DeleteFilebyHomeId(otaFile);
|
| | | }
|
| | | else
|
| | | {
|
| | | //变更:搞掉它,不留了
|
| | | Global.DeleteFilebyHomeId(filePath);
|
| | | Global.DeleteFilebyHomeId(otaFile);
|
| | | //删除自动备份
|
| | | HdlAutoBackupLogic.DeleteFile(otaFile);
|
| | | }
|
| | |
| | | /// 根据网关ID获取所有的设备
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关ID</param>
|
| | | /// <param name="getOtaDevice">是否获取ota设备</param>
|
| | | /// <returns></returns>
|
| | | public List<CommonDevice> GetDeviceByGatewayID(string gwId)
|
| | | public List<CommonDevice> GetDeviceByGatewayID(string gwId, bool getOtaDevice = false)
|
| | | {
|
| | | List<CommonDevice> list = new List<CommonDevice>();
|
| | | lock (dicAllDevice)
|
| | |
| | | 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 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 ■ 获取设备名称_______________________
|
| | |
| | | return dName;
|
| | | }
|
| | | //根据设备类型获取名称
|
| | | dName = this.GetDeviceObjectText(new List<CommonDevice>() { device }, false);
|
| | | 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
|
| | | || (this.dicDeviceEpoint.ContainsKey(device.DeviceAddr) == true && this.dicDeviceEpoint[device.DeviceAddr].Count > 1))
|
| | | if (device.DriveCode > 0)
|
| | | {
|
| | | var arry = dName.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | dName = arry[0].Trim();
|
| | | //在端点名字的后面附加【回路】字样
|
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | 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>
|
| | | DryContact = -10000,
|
| | | /// <summary>
|
| | | /// 灯光(注意,它输入其他类,不是设备类型)
|
| | | /// 灯光(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Light = -10001,
|
| | | /// <summary>
|
| | | /// 插座
|
| | | /// 插座(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Socket1 = -10002,
|
| | | /// <summary>
|
| | | /// 开关
|
| | | /// 开关(注意,它属于其他类,不是设备类型)
|
| | | /// </summary>
|
| | | Switch = -10003,
|
| | | }
|