| | |
| | | if (null == common) { |
| | | continue; |
| | | } |
| | | |
| | | var newName = CheckIfNameChanged (deviceFilePath, common.Type.ToString(), common.Name); |
| | | if (!string.IsNullOrEmpty (newName)) { |
| | | Utlis.WriteLine (common.Name + " 场景设备新备注:" + newName); |
| | | common.Name = newName; |
| | | } |
| | | |
| | | string iconPath = ""; |
| | | |
| | | if (common.Type == DeviceType.UniversalDevice) { |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 2021-03-26 |
| | | /// 检测判断备注名是否修改过,修改过则更新一次 |
| | | /// 修复测试反馈BUG(设备备注修改后,场景里面的设备备注没有同步,需删除原来设备重新添加,备注才更新。) |
| | | /// </summary> |
| | | /// <param name="deviceFilePath"></param> |
| | | /// <param name="deviceType"></param> |
| | | /// <param name="deviceName"></param> |
| | | string CheckIfNameChanged (string deviceFilePath, string deviceType, string deviceName) |
| | | { |
| | | try { |
| | | string [] str = deviceFilePath.Split (Constant.Equipment); |
| | | if (str == null || str.Length != 2) return ""; |
| | | //1.找出本地真实的设备 |
| | | string trueDeviceFilePath = Constant.Equipment + str [1]; |
| | | Common common = Newtonsoft.Json.JsonConvert.DeserializeObject<Common> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (trueDeviceFilePath))); |
| | | if (null == common) { |
| | | return ""; |
| | | } |
| | | //2.本地存在真实设备,判断备注是否一致 |
| | | if (deviceName.Equals (common.Name) || deviceName == common.Name) return ""; |
| | | //3.不一致更新备注保存到本地 |
| | | string newName = common.Name; |
| | | //4.这里注意:转换成当前设备类型的对象,不能转换成Common,不然保存后会丢失设置的控制状态值数据。 |
| | | if (deviceType == DeviceType.LightSwitch.ToString () || deviceType == DeviceType.LightEnergySocket.ToString () || deviceType == DeviceType.LightEnergySwitch.ToString () || deviceType == DeviceType.LightSwitchSocket.ToString ()) { |
| | | LightSwitch lightSwitch = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (null == lightSwitch) { |
| | | return ""; |
| | | } |
| | | lightSwitch.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightSwitch))); |
| | | |
| | | } else if (deviceType == DeviceType.LightMixSwitch.ToString ()) { |
| | | LightMixSwitch lightSwitch = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixSwitch> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (null == lightSwitch) { |
| | | return ""; |
| | | } |
| | | lightSwitch.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightSwitch))); |
| | | |
| | | } else if (deviceType == DeviceType.LightDimming.ToString ()) { |
| | | LightDimming lightDimming = Newtonsoft.Json.JsonConvert.DeserializeObject<LightDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (null == lightDimming) { |
| | | return ""; |
| | | } |
| | | lightDimming.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightDimming))); |
| | | |
| | | |
| | | } else if (deviceType == DeviceType.LightMixDimming.ToString ()) { |
| | | LightMixDimming lightDimming = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixDimming> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (null == lightDimming) { |
| | | return ""; |
| | | } |
| | | lightDimming.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightDimming))); |
| | | |
| | | |
| | | } else if (deviceType == DeviceType.LightRGB.ToString ()) { |
| | | LightLogic lightRGB = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (null == lightRGB) { |
| | | return ""; |
| | | } |
| | | |
| | | lightRGB.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (lightRGB))); |
| | | |
| | | } else if (deviceType == DeviceType.CurtainModel.ToString () || deviceType == DeviceType.CurtainTrietex.ToString () || deviceType == DeviceType.CurtainRoller.ToString ()) { |
| | | if (deviceType == DeviceType.CurtainModel.ToString ()) { |
| | | #region CurtainModelView |
| | | CurtainModel curtainmodel = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainModel> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (curtainmodel == null) { |
| | | return ""; |
| | | } |
| | | curtainmodel.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (curtainmodel))); |
| | | |
| | | #endregion |
| | | } else if (deviceType == DeviceType.CurtainTrietex.ToString ()) { |
| | | #region CurtainTrietexlView |
| | | CurtainTrietex curtaintretex = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainTrietex> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (curtaintretex == null) { |
| | | return ""; |
| | | } |
| | | curtaintretex.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (curtaintretex))); |
| | | |
| | | #endregion |
| | | } else if (deviceType == DeviceType.CurtainRoller.ToString ()) { |
| | | #region CurtainRollerlView |
| | | CurtainRoller curtainroller = Newtonsoft.Json.JsonConvert.DeserializeObject<CurtainRoller> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (curtainroller == null) { |
| | | return ""; |
| | | }; |
| | | curtainroller.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (curtainroller))); |
| | | |
| | | |
| | | } else { |
| | | return ""; |
| | | } |
| | | #endregion |
| | | } else if (deviceType == DeviceType.HVAC.ToString () || deviceType == DeviceType.ACInfrared.ToString () || deviceType == DeviceType.ACPanel.ToString ()) { |
| | | AC ac = Newtonsoft.Json.JsonConvert.DeserializeObject<AC> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (ac == null) { |
| | | return ""; |
| | | } |
| | | ac.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (ac))); |
| | | |
| | | } else if (deviceType == DeviceType.FoolHeat.ToString () || deviceType == DeviceType.FoolHeatPanel.ToString ()) { |
| | | FoolHeat fh = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (fh == null) |
| | | return ""; |
| | | |
| | | fh.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (fh))); |
| | | |
| | | } else if (deviceType == DeviceType.DryContact.ToString ()) { |
| | | |
| | | } else if (deviceType == DeviceType.MusicModel.ToString ()) { |
| | | |
| | | } else if (deviceType == DeviceType.FanModule.ToString ()) { |
| | | #region FanModuleView |
| | | FanModule fanModule = Newtonsoft.Json.JsonConvert.DeserializeObject<FanModule> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (fanModule == null) { |
| | | return ""; |
| | | } |
| | | fanModule.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (fanModule))); |
| | | |
| | | #endregion |
| | | } else if (deviceType == DeviceType.UniversalDevice.ToString ()) { |
| | | #region UniversalDevice |
| | | UniversalDevice udDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<UniversalDevice> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (deviceFilePath))); |
| | | if (udDevice == null) { |
| | | return ""; |
| | | } |
| | | udDevice.Name = newName; |
| | | IO.FileUtils.WriteFileByBytes (deviceFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (udDevice))); |
| | | #endregion |
| | | } else { |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | return newName; |
| | | } catch { |
| | | return ""; |
| | | } |
| | | } |
| | | } |
| | | } |