| | |
| | | /// <summary> |
| | | /// 房间对象 |
| | | /// </summary> |
| | | public class Room |
| | | public class Room |
| | | { |
| | | public static string FavoriteRoom = "FavoriteRoom"; |
| | | |
| | |
| | | { |
| | | GetRoomByFilePath (roomFilePath); |
| | | } |
| | | |
| | | |
| | | |
| | | // 房间命名规则 typeof (Room).Name + "_" + etNameBox.Text.Trim (); |
| | | /// <summary> |
| | |
| | | var nowRoom = Newtonsoft.Json.JsonConvert.DeserializeObject<Room> (System.Text.Encoding.UTF8.GetString (sdf)); |
| | | |
| | | if (null == nowRoom) { |
| | | System.Console.WriteLine ("房间文件路径不对,文件路径为:" + roomFilePath); |
| | | Utlis.WriteLine ("房间文件路径不对,文件路径为:" + roomFilePath); |
| | | return null; |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | common.CustomDelayTimeClose = 0; |
| | | } |
| | | room.DeviceList.Add (common); |
| | | } else if (deviceType == DeviceType.LightRGB.ToString ()) { |
| | | } else if (deviceType == DeviceType.LightRGB.ToString ()) { |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightLogic> (jsonInfo); |
| | | common.CurrentBrightness = 0; |
| | | string keyString = common.SubnetID.ToString () + "_" + common.DeviceID.ToString () + "_" + common.LoopID.ToString (); |
| | |
| | | common.CustomDelayTimeClose = 0; |
| | | } |
| | | room.DeviceList.Add (common); |
| | | } else if (deviceType == DeviceType.LightSwitch.ToString ()){ |
| | | } 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.LightMixSwitch.ToString ()) { |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightMixSwitch> (jsonInfo); |
| | | room.DeviceList.Add (common); |
| | | } else if ( deviceType == DeviceType.LightEnergySocket.ToString ()) { |
| | | } else if (deviceType == DeviceType.LightEnergySocket.ToString ()) { |
| | | var common = Newtonsoft.Json.JsonConvert.DeserializeObject<LightEnergySocket> (jsonInfo); |
| | | room.DeviceList.Add (common); |
| | | } else if (deviceType == DeviceType.LightEnergySwitch.ToString ()) { |
| | |
| | | room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<SensorCO2> (jsonInfo)); |
| | | } else if (deviceType == DeviceType.SensorTVOC.ToString ()) { |
| | | room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<SensorTVOC> (jsonInfo)); |
| | | } else if (deviceType == DeviceType.SensorPM25.ToString ()) { |
| | | } else if (deviceType == DeviceType.SensorPM25.ToString ()) { |
| | | room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<SensorPM25> (jsonInfo)); |
| | | } else if (deviceType == DeviceType.SensorTemperature.ToString ()) { |
| | | } else if (deviceType == DeviceType.SensorTemperature.ToString ()) { |
| | | room.DeviceList.Add (Newtonsoft.Json.JsonConvert.DeserializeObject<SensorTemperature> (jsonInfo)); |
| | | } else if (deviceType == DeviceType.SensorHumidity.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)); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | 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))); |