| | |
| | | /// <summary> |
| | | /// 房间对象 |
| | | /// </summary> |
| | | public class Room |
| | | public class Room |
| | | { |
| | | public static string FavoriteRoom = "FavoriteRoom"; |
| | | |
| | |
| | | { |
| | | GetRoomByFilePath (roomFilePath); |
| | | } |
| | | |
| | | |
| | | |
| | | // 房间命名规则 typeof (Room).Name + "_" + etNameBox.Text.Trim (); |
| | | /// <summary> |
| | |
| | | break; |
| | | } |
| | | } |
| | | //if( IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Split ('_').Length == 5 && obj.Split ('_') [0] == "Equipment" && obj.Split ('_') [1] == DeviceType.SuperWireless.ToString ()).Count > 0) { |
| | | // UserConfig.Instance.HideDeviceTypes.Remove (SimpleControl.R.MyInternationalizationString.SuperWireless); |
| | | // UserConfig.Instance.HideDeviceTypes.Remove (SimpleControl.R.MyInternationalizationString.Sonos); |
| | | // UserConfig.Instance.SaveUserConfig (); |
| | | //} |
| | | |
| | | return nowRoom; |
| | | } catch { |
| | | return null; |
| | |
| | | } else if (deviceType == DeviceType.LightSwitch.ToString ()){ |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightSwitch> (jsonInfo); |
| | | room.DeviceList.Add (common); |
| | | } else if (deviceType == DeviceType.LightMixSwitch.ToString () ){ |
| | | } |
| | | else if (deviceType == DeviceType.LogicModule.ToString()) |
| | | { |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicModule>(jsonInfo); |
| | | room.DeviceList.Add(common); |
| | | } |
| | | else if (deviceType == DeviceType.LightMixSwitch.ToString () ){ |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixSwitch> (jsonInfo); |
| | | room.DeviceList.Add (common); |
| | | } else if ( deviceType == DeviceType.LightEnergySocket.ToString ()) { |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySocket> (jsonInfo); |
| | | room.DeviceList.Add (common); |
| | | } else if (deviceType == DeviceType.LightEnergySwitch.ToString ()) { |
| | | } else if ( deviceType == DeviceType.LightEnergySwitch.ToString ()) { |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySwitch> (jsonInfo); |
| | | room.DeviceList.Add (common); |
| | | } else if (deviceType == DeviceType.CurtainModel.ToString ()) { |
| | |
| | | room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<SensorHumidity> (jsonInfo)); |
| | | } else if (deviceType == DeviceType.FreshAir.ToString ()) { |
| | | room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<FreshAir> (jsonInfo)); |
| | | } |
| | | } |
| | | //else if (deviceType == DeviceType.Thermostat.ToString ()) { |
| | | // room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<Thermostat> (jsonInfo)); |
| | | //} |
| | | //else if (deviceType == DeviceType.ACMerrill.ToString ()) {//2020-03-10 新增美林空调系统支持 |
| | | // room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<ACMerrill> (jsonInfo)); |
| | | //} |
| | | //else if (deviceType == DeviceType.DoorLockRelay.ToString ()) { //屏蔽继电器门锁 |
| | | // room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<LightDoorLock> (jsonInfo)); |
| | | //} |
| | | |
| | | for (int i = UserConfig.Instance.HideDeviceTypes.Count - 1; i >= 0; i--) { |
| | | var hideType = UserConfig.Instance.HideDeviceTypes [i]; |
| | |
| | | /// <summary> |
| | | /// 房间名 |
| | | /// </summary> |
| | | public string Name { get; set; } |
| | | public string Name { |
| | | get; |
| | | set; |
| | | } |
| | | |
| | | public string RoomFilePath { |
| | | get { |
| | |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 不选择到房间时候的背景图 |
| | | /// </summary> |
| | | public string UnSelectedBackgroundImage { |
| | | get; |
| | | set; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 选择到房间的时候背景图 |
| | | /// </summary> |
| | | public string SelectedBackgroundImage { |
| | | get; |
| | | set; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 不选择到房间下拉列表时候的背景图 |
| | | /// </summary> |
| | | public string UnSelectedListBackgroundImage { |
| | | get; |
| | | set; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 选择到房间的下拉列表时候背景图 |
| | | /// </summary> |
| | | public string SelectedListBackgroundImage { |
| | | get; |
| | | set; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 图标 |
| | | /// </summary> |
| | | public string IconPath = "DefaultRoomIcon.png"; |
| | | /// <summary> |
| | | /// 房间背景 |
| | | /// </summary> |
| | |
| | | { |
| | | roomFilePathList = new List<string> (); |
| | | } |
| | | |
| | | if (roomFilePathList.Contains (roomFilePath)) return; |
| | | |
| | | roomFilePathList.Add (roomFilePath); |
| | | |
| | | //var sssddsa = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Contains ("Room_")); |
| | |
| | | Save (newRoomFilePath); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 所有的房间列表路径 |
| | | /// </summary> |
| | | /// <value>The room file path list.</value> |
| | | public static System.Collections.Generic.List<string> FilePathList { |
| | | get { |
| | | var roomBytes = IO.FileUtils.ReadFile (roomListFilePath); |
| | | string roombyteString = System.Text.Encoding.UTF8.GetString (roomBytes); |
| | | var ddds = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (roombyteString); |
| | | if (ddds == null) |
| | | ddds = new List<string> (); |
| | | if (!ddds.Contains (FavoriteRoom)) { |
| | | ddds.Add (FavoriteRoom); |
| | | if (!IO.FileUtils.Exists (FavoriteRoom)) { |
| | | //默认添加对应的房间 |
| | | new Room () { Name = "" }.Save (FavoriteRoom); |
| | | } |
| | | IO.FileUtils.WriteFileByBytes (roomListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (ddds))); |
| | | } |
| | | return ddds; |
| | | var rommBytes = IO.FileUtils.ReadFile (roomListFilePath); |
| | | string rommbyteString = System.Text.Encoding.UTF8.GetString (rommBytes); |
| | | return Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (rommbyteString); |
| | | } |
| | | } |
| | | |
| | |
| | | public static void InitAllRoom () |
| | | { |
| | | Lists.Clear (); |
| | | if (null == Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (roomListFilePath)))) { |
| | | //初始化房间列表 |
| | | Shared.IO.FileUtils.WriteFileByBytes (roomListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new System.Collections.Generic.List<string> ()))); |
| | | } |
| | | var roomFilePathList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (roomListFilePath))); |
| | | if (!roomFilePathList.Contains (FavoriteRoom)) { |
| | | roomFilePathList.Add (FavoriteRoom); |
| | | if (!IO.FileUtils.Exists (FavoriteRoom)) { |
| | | //默认添加对应的房间 |
| | | new Room () { Name = "" }.Save (FavoriteRoom); |
| | | try { |
| | | if (null == Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (roomListFilePath)))) { |
| | | //初始化房间列表 |
| | | Shared.IO.FileUtils.WriteFileByBytes (roomListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new System.Collections.Generic.List<string> ()))); |
| | | } |
| | | var roomFilePathList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (roomListFilePath))); |
| | | if (!roomFilePathList.Contains (FavoriteRoom)) { |
| | | roomFilePathList.Add (FavoriteRoom); |
| | | if (!IO.FileUtils.Exists (FavoriteRoom)) { |
| | | //默认添加对应的房间 |
| | | new Room () { Name = "" }.Save (FavoriteRoom); |
| | | } |
| | | IO.FileUtils.WriteFileByBytes (roomListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (roomFilePathList))); |
| | | } |
| | | |
| | | IO.FileUtils.WriteFileByBytes (roomListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (roomFilePathList))); |
| | | |
| | | } |
| | | |
| | | foreach (var roomFilePath in roomFilePathList) { |
| | | var room = GetRoomByFilePath (roomFilePath); |
| | | if (null != room) { |
| | | Lists.Add (room); |
| | | } |
| | | } |
| | | |
| | | for (int i = UserConfig.Instance.HideDeviceTypes.Count - 1; i >= 0; i--) { |
| | | var hideType = UserConfig.Instance.HideDeviceTypes [i]; |
| | | foreach (var room in Room.Lists) { |
| | | var devices = room.DeviceList.Find ((obj) => { |
| | | return obj.DeviceTextID == hideType; |
| | | }); |
| | | if (devices != null) { |
| | | UserConfig.Instance.HideDeviceTypes.Remove (hideType); |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | break; |
| | | foreach (var roomFilePath in roomFilePathList) { |
| | | var room = GetRoomByFilePath (roomFilePath); |
| | | if (null != room) { |
| | | Lists.Add (room); |
| | | } |
| | | } |
| | | |
| | | for (int i = UserConfig.Instance.HideDeviceTypes.Count - 1; i >= 0; i--) { |
| | | var hideType = UserConfig.Instance.HideDeviceTypes [i]; |
| | | foreach (var room in Room.Lists) { |
| | | var devices = room.DeviceList.Find ((obj) => { |
| | | return obj.DeviceTextID == hideType; |
| | | }); |
| | | if (devices != null) { |
| | | UserConfig.Instance.HideDeviceTypes.Remove (hideType); |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } catch { |
| | | Utlis.WriteLine ("解析房间列表异常"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public void SaveLightScene (string roomFilePath, string SceneRemark, Scene scene) |
| | | { |
| | | IO.FileUtils.WriteFileByBytes (roomFilePath + "_" + SceneRemark, Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (scene))); |