| | |
| | | List<CommonDevice> list = Common.LocalDevice.Current.GetDeviceByGatewayID(gatewayId);
|
| | | foreach (var device in list)
|
| | | {
|
| | | //删除设备,不删除房间信息
|
| | | Common.LocalDevice.Current.DeleteMemmoryDevice(device, false);
|
| | | //删除一般设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
|
| | | //删除Ota设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | }
|
| | | //删除网关文件
|
| | | this.DeleteGatewayFile(gatewayId);
|
| | |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public async Task<bool> AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | { |
| | | {
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO); |
| | | if (falge == false)
|
| | | {
|
| | | return falge;
|
| | | } |
| | | //执行添加网关到内存 |
| | | var result = await this.DoAddGatewayToMemory(zbGateway, mode); |
| | | //前的网关绑定在了当前账号下的不同住宅里面
|
| | |
| | | {
|
| | | return false;
|
| | | } |
| | | //设置网关的经纬度 |
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude); |
| | | return falge; |
| | | return true; |
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// 重新绑定网关(1:正常 -1:异常 0:当前的网关绑定在了当前账号下的不同住宅里面) |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="btnMsg">消息控件</param> |
| | | public async Task<int> ReBindNewGateway(ZbGateway zbGateway, NormalViewControl btnMsg = null) |
| | | {
|
| | | if (zbGateway == null)
|
| | |
| | | return -1;
|
| | | }
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude); |
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.YES); |
| | | if (falge == false)
|
| | | {
|
| | | return -1;
|
| | |
| | | }
|
| | |
|
| | | //获取全部设备
|
| | | bool result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
|
| | | int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(realWay);
|
| | | //关闭进度条
|
| | | ProgressBar.Close();
|
| | | if (result == false)
|
| | | if (result == -1)
|
| | | {
|
| | | return false;
|
| | | }
|
| | |
| | | {
|
| | | //删除设备文件
|
| | | Common.LocalDevice.Current.DeleteMemmoryDevice(device, true);
|
| | | //删除Ota设备
|
| | | Common.LocalDevice.Current.DeleteMemmoryOtaDevice(device.DeviceAddr);
|
| | | }
|
| | | //如果是主网关
|
| | | if (this.IsMainGateway(zbGatewayID) == 1)
|
| | | {
|
| | | foreach (var room in Shared.Common.Room.Lists)
|
| | | var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
|
| | | foreach (var room in listAllRoom)
|
| | | {
|
| | | //删除场景文件
|
| | | foreach (var scene in room.SceneUIFilePathList)
|
| | | foreach (var sceneId in room.ListSceneId)
|
| | | {
|
| | | if (Global.IsExistsByHomeId(scene) == true)
|
| | | if (Global.IsExistsByHomeId($"Scene_{sceneId}.json") == true)
|
| | | {
|
| | | Global.DeleteFilebyHomeId(scene);
|
| | | Global.DeleteFilebyHomeId($"Scene_{sceneId}.json");
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | if (mode == GetNameMode.SpecialGateway && localWay.getGwInfo != null)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | if (LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //没有名称时,则使用R文件里面设置的东西
|
| | | return Language.StringByID(Common.LocalDevice.Current.dicDeviceDefultNameID[keyName]);
|
| | | //没有名称时,则使用R文件里面设置的默认设备名称
|
| | | return Language.StringByID(LocalDevice.Current.dicDeviceAllNameID[keyName] + 20000);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | if (zbGateway.getGwInfo != null && zbGateway.getGwInfo.LinuxImageType != 0)
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
|
| | | button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | }
|
| | | }
|
| | | else
|
| | |
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + zbGateway.getGwInfo.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = LocalDevice.Current.dicDeviceDefultNameID[keyName];
|
| | | button.TextID = LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | }
|
| | | });
|
| | | }
|
| | |
| | | else
|
| | | {
|
| | | string keyName = Common.LocalDevice.deviceModelIdName + this.dicGateway[gwId].getGwInfo.LinuxImageType;
|
| | | if (Common.LocalDevice.Current.dicDeviceDefultNameID.ContainsKey(keyName) == true)
|
| | | if (Common.LocalDevice.Current.dicDeviceAllNameID.ContainsKey(keyName) == true)
|
| | | {
|
| | | //使用R文件里面设置的东西
|
| | | button.TextID = Common.LocalDevice.Current.dicDeviceDefultNameID[keyName];
|
| | | button.TextID = Common.LocalDevice.Current.dicDeviceAllNameID[keyName];
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 网关房间相关_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(ZbGateway zbGateway)
|
| | | {
|
| | | var gatewayId = this.GetGatewayId(zbGateway);
|
| | | return this.GetRoomByGateway(gatewayId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="gatewayId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(string gatewayId)
|
| | | {
|
| | | var localGateway = this.GetLocalGateway(gatewayId);
|
| | | if (localGateway == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 变更网关房间
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(ZbGateway zbGateway, string roomId)
|
| | | {
|
| | | var gatewayId = this.GetGatewayId(zbGateway);
|
| | | var localGateway = this.GetLocalGateway(gatewayId);
|
| | | if (localGateway != null)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | | localGateway.ReSave();
|
| | | //添加备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 清空真实网关列表___________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | this.GetGwInfoAttribute(localWay, "ZbImageType").ToString(),
|
| | | Convert.ToInt32(this.GetGwInfoAttribute(localWay, "ZbFWVersion")));
|
| | |
|
| | | var list = new List<FirmwareVersionInfo>();
|
| | | list.Add(gatewayFirmware);
|
| | | list.Add(coordinatorFirmware);
|
| | |
|
| | | //这个网关需要有虚拟驱动这个东西才行
|
| | | FirmwareVersionInfo virtualFirmware = null;
|
| | | string linImage = this.GetGwInfoAttribute(localWay, "LinuxImageType").ToString();
|
| | | if (linImage != "6")
|
| | | {
|
| | |
| | | var listvVode = await HdlGatewayLogic.Current.GetListVDDriveCode(localWay);
|
| | | if (listvVode != null && listvVode.Count > 0)
|
| | | {
|
| | | //添加虚拟驱动的升级固件(成不成功都无所谓)
|
| | | flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | listvVode[0].DriveHwVersion.ToString(),
|
| | | listvVode[0].DriveImageType.ToString());
|
| | |
|
| | | //虚拟驱动
|
| | | virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | listvVode[0].DriveHwVersion.ToString(),
|
| | | listvVode[0].DriveImageType.ToString(),
|
| | | listvVode[0].DriveFwVersion);
|
| | |
|
| | | if (virtualFirmware != null)
|
| | | foreach (var data in listvVode)
|
| | | {
|
| | | virtualFirmware.VirtualCode = listvVode[0].DriveCode;
|
| | | //添加虚拟驱动的升级固件(成不成功都无所谓)
|
| | | flage = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString());
|
| | |
|
| | | //虚拟驱动
|
| | | var virtualFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.VirtualDevice,
|
| | | data.DriveHwVersion.ToString(),
|
| | | data.DriveImageType.ToString(),
|
| | | data.DriveFwVersion);
|
| | |
|
| | | if (virtualFirmware != null)
|
| | | {
|
| | | virtualFirmware.VirtualCode = data.DriveCode;
|
| | | list.Add(virtualFirmware);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | var list = new List<FirmwareVersionInfo>();
|
| | | list.Add(gatewayFirmware);
|
| | | list.Add(coordinatorFirmware);
|
| | | list.Add(virtualFirmware);
|
| | |
|
| | | if (list.Count == 2)
|
| | | {
|
| | | //虚拟驱动如果没有新版本的话,固定添加一个空的
|
| | | list.Add(null);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | |
| | | /// <param name="gateway">网关对象</param>
|
| | | /// <param name="Longitude">经度</param>
|
| | | /// <param name="Latitude">维度</param>
|
| | | /// <param name="mode">显示错误</param>
|
| | | /// <returns></returns>
|
| | | public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude)
|
| | | public bool SetGatewaySite(ZbGateway gateway, double Longitude, double Latitude, ShowErrorMode mode)
|
| | | {
|
| | | ZbGateway realWay = null;
|
| | | if (this.GetRealGateway(ref realWay, gateway) == false)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
| | | this.ShowTipMsg(msg);
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | //错误:网关对象丢失
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uErrorGatewayLostMsg);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | realWay.Actions -= action;
|
| | | if (result != 0)
|
| | | {
|
| | | //设置网关经纬度失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
|
| | | if (result == -1)
|
| | | if (mode == ShowErrorMode.YES)
|
| | | {
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | //设置网关经纬度失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetGatewaySiteFail);
|
| | | if (result == -1)
|
| | | {
|
| | | msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, null, "回复超时");
|
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | /// <returns></returns>
|
| | | public async Task<bool> UpLoadDeviceBackupDataToGateway(CommonDevice device, GatewayBackupEnum backupEnum, object upLaodData)
|
| | | {
|
| | | //ZbGateway realWay = null;
|
| | | //if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
|
| | | //{
|
| | | // //没有找到真实物理网关
|
| | | // return false;
|
| | | //}
|
| | | //string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
|
| | | ////创建文件对象
|
| | | //var result = await realWay.CreateFileAsync(fileName);
|
| | | //if (result == null || result.Result != 0)
|
| | | //{
|
| | | // return false;
|
| | | //}
|
| | | ////发送数据流
|
| | | //var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
|
| | | //var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | //var result2 = await realWay.SendFileAsync(byteData);
|
| | | //if (result2 == null || result2.Result != 0)
|
| | | //{
|
| | | // return false;
|
| | | //}
|
| | | ZbGateway realWay = null;
|
| | | if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, device.CurrentGateWayId) == false)
|
| | | {
|
| | | //没有找到真实物理网关
|
| | | return false;
|
| | | }
|
| | | string fileName = device.FilePath + ((int)backupEnum).ToString().PadLeft(5, '0');
|
| | | //创建文件对象
|
| | | var result = await realWay.CreateFileAsync(fileName);
|
| | | if (result == null || result.Result != 0)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | //发送数据流
|
| | | var data = Newtonsoft.Json.JsonConvert.SerializeObject(upLaodData);
|
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(data);
|
| | | var result2 = await realWay.SendFileAsync(byteData);
|
| | | if (result2 == null || result2.Result != 0)
|
| | | {
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | else if (backType == GatewayBackupEnum.APir灯光配置)
|
| | | {
|
| | | var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.ConfigureParamates>(System.Text.Encoding.UTF8.GetString(byteData));
|
| | | result = await HdlDevicePirSensorLogic.Current.SetPirSensorLightSettion((IASZone)device, recoverData);
|
| | | result = await HdlDevicePirSensorLogic.Current.SetPirSensorSettion((IASZone)device, recoverData);
|
| | | }
|
| | | else if (backType == GatewayBackupEnum.A干接点颜色调节)
|
| | | {
|
| | |
| | | int level = Convert.ToInt32(recoverData["level"]);
|
| | | result = await HdlDevicePanelLogic.Current.SetDeviceEnergyConservationMode((Panel)device, modeEnable, modeTime, level);
|
| | | }
|
| | | else if (backType == GatewayBackupEnum.A干接点私有属性)
|
| | | else if (backType == GatewayBackupEnum.A干接点第三级别私有属性)
|
| | | {
|
| | | var recoverData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(System.Text.Encoding.UTF8.GetString(byteData));
|
| | | result = await HdlDevicePanelLogic.Current.EditorDryContactFunction((Panel)device, recoverData);
|
| | | result = await HdlDevicePanelLogic.Current.EditorDryContactThirdFunction((Panel)device, recoverData);
|
| | | }
|
| | | else if (backType == GatewayBackupEnum.A窗帘方向)
|
| | | {
|