| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using HDL_ON.DAL; |
| | | using HDL_ON.DAL.Server; |
| | | |
| | | namespace HDL_ON.Entity |
| | | { |
| | | public class FunctionList |
| | | { |
| | | public FunctionList() |
| | | static FunctionList _FunctionList; |
| | | public static FunctionList List |
| | | { |
| | | |
| | | get |
| | | { |
| | | if(_FunctionList == null) |
| | | { |
| | | _FunctionList = new FunctionList(); |
| | | #region 恢复数据 |
| | | var filePathList = FileUtils.ReadFiles(); |
| | | foreach (var filePath in filePathList) |
| | | { |
| | | _FunctionList.IniFunctionList(filePath); |
| | | } |
| | | #endregion |
| | | } |
| | | return _FunctionList; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 功能列表 |
| | | /// </summary> |
| | | List<Function> deviceFunctionList; |
| | | //[Newtonsoft.Json.JsonIgnore] |
| | | //public List<Function> functions = new List<Function>(); |
| | | |
| | | |
| | | /// <summary> |
| | | /// 加载功能列表 |
| | | /// todo 需要优化,后期不能保证能使用sid解析出是什么类型的设备 |
| | | /// </summary> |
| | | /// <param name="filePath"></param> |
| | | public void IniFunctionList(string filePath) |
| | | { |
| | | if (filePath.StartsWith("FunctionData_")) |
| | | { |
| | | var functionDataBytes = FileUtils.ReadFile(filePath); |
| | | var functionDataString = System.Text.Encoding.UTF8.GetString(functionDataBytes); |
| | | var tempFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString); |
| | | if (tempFunction.DeleteSign) |
| | | { |
| | | //todo 删除云端数据 20201203--App不能删除功能数据 |
| | | } |
| | | else |
| | | { |
| | | switch (tempFunction.spk) |
| | | { |
| | | case SPK.LightSwitch: |
| | | case SPK.LightDimming: |
| | | case SPK.LightRGB: |
| | | case SPK.LightRGBW: |
| | | case SPK.LightCCT: |
| | | List.lights.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Light>(functionDataString)); |
| | | break; |
| | | case SPK.CurtainRoller: |
| | | case SPK.CurtainShades: |
| | | case SPK.CurtainSwitch: |
| | | case SPK.CurtainTrietex: |
| | | List.curtains.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Curtain>(functionDataString)); |
| | | break; |
| | | case SPK.AcStandard: |
| | | List.aCs.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(functionDataString)); |
| | | break; |
| | | case SPK.FloorHeatStandard: |
| | | //恢复地热数据 |
| | | List.floorHeatings.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(functionDataString)); |
| | | break; |
| | | case SPK.SensorPm25: |
| | | case SPK.SensorCO2: |
| | | case SPK.SensorTVOC: |
| | | case SPK.SensorTemperature: |
| | | case SPK.SensorHumidity: |
| | | //恢复环境数据 |
| | | List.sensorsEnvironmentalScience.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(functionDataString)); |
| | | break; |
| | | case SPK.ElectricSocket: |
| | | //恢复插座数据 |
| | | List.switchSockets.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<SwitchSocket>(functionDataString)); |
| | | break; |
| | | case SPK.ElectricTV: |
| | | //恢复电视数据 |
| | | List.tVs.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<TV>(functionDataString)); |
| | | break; |
| | | case SPK.ElectricFan: |
| | | //恢复风扇数据 |
| | | List.fans.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Fan>(functionDataString)); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | if (filePath.StartsWith("SceneData_")) |
| | | { |
| | | var sceneDataBytes = FileUtils.ReadFile(filePath); |
| | | var sceneDataString = System.Text.Encoding.UTF8.GetString(sceneDataBytes); |
| | | var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(sceneDataString); |
| | | if (tempScene.DeleteSign) |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | pm.DeleteScene(tempScene.userSceneId); |
| | | } |
| | | else |
| | | { |
| | | List.scenes.Add(tempScene); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | var fs = new List<Function>(); |
| | | fs.AddRange(GetAllDeviceFunctionList()); |
| | | fs.AddRange(scenes); |
| | | return fs; |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | public List<Function> GetAllDeviceFunctionList() |
| | | { |
| | | if (deviceFunctionList == null) |
| | | { |
| | | deviceFunctionList = new List<Function>(); |
| | | deviceFunctionList.AddRange(aCs); |
| | | deviceFunctionList.AddRange(lights); |
| | | deviceFunctionList.AddRange(curtains); |
| | | deviceFunctionList.AddRange(floorHeatings); |
| | | deviceFunctionList.AddRange(electricals); |
| | | deviceFunctionList.AddRange(sensorsEnvironmentalScience); |
| | | deviceFunctionList.AddRange(UI.Music.A31MusicModel.A31MusicModelList); |
| | | } |
| | | deviceFunctionList = new List<Function>(); |
| | | deviceFunctionList.AddRange(aCs); |
| | | deviceFunctionList.AddRange(lights); |
| | | deviceFunctionList.AddRange(curtains); |
| | | deviceFunctionList.AddRange(floorHeatings); |
| | | deviceFunctionList.AddRange(electricals); |
| | | deviceFunctionList.AddRange(sensorsEnvironmentalScience); |
| | | deviceFunctionList.AddRange(UI.Music.A31MusicModel.A31MusicModelList); |
| | | try |
| | | { |
| | | deviceFunctionList.OrderByDescending(o => o.usageCount).ToList(); |
| | |
| | | switchSockets = new List<SwitchSocket>(); |
| | | fans = new List<Fan>(); |
| | | sensorsEnvironmentalScience = new List<Sensor>(); |
| | | //functions = new List<Function>(); |
| | | scenes = new List<Scene>(); |
| | | deviceFunctionList = null; |
| | | } |
| | |
| | | sidObj2.SaveFunctionData(); |
| | | break; |
| | | case FunctionType.Curtain: |
| | | case FunctionType.RollingShutter: |
| | | case FunctionType.MotorCurtain: |
| | | var sidObj3 = Newtonsoft.Json.JsonConvert.DeserializeObject<Curtain>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.curtains.Add(sidObj3 ); |
| | | sidObj3.SaveFunctionData(); |
| | |
| | | public void AddFunction(object obj) |
| | | { |
| | | var f = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(obj.ToString()); |
| | | |
| | | if (f == null) |
| | | return; |
| | | switch (f.functionCategory) |
| | | { |
| | | case FunctionCategory.Thermostat: |
| | |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下来云端设备数据 |
| | | /// </summary> |
| | | public void DownloadFunctionList() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.GetDeviceList(); |
| | | if (pack.Code == StateCode.SUCCESS) |
| | | { |
| | | var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(pack.Data.ToString()); |
| | | if (deviceList != null) |
| | | { |
| | | foreach (var function in deviceList.list) |
| | | { |
| | | var localFunction = DB_ResidenceData.functionList.GetAllDeviceFunctionList().Find((obj) => obj.deviceId == function.deviceId); |
| | | if (localFunction != null) |
| | | { |
| | | if (localFunction.modifyTime != function.modifyTime) |
| | | { |
| | | localFunction.name = function.name; |
| | | localFunction.collect = function.collect; |
| | | localFunction.modifyTime = function.modifyTime; |
| | | localFunction.createTime = function.createTime; |
| | | localFunction.roomIds = function.roomIds; |
| | | localFunction.bus_Data = function.bus_Data; |
| | | } |
| | | localFunction.SaveFunctionData(); |
| | | } |
| | | else |
| | | { |
| | | function.SaveFunctionData(); |
| | | List.IniFunctionList(function.savePath); |
| | | } |
| | | |
| | | var funcitonInfoPack = pm.GetDeviceInfoList(new List<string>() { function.deviceId }); |
| | | var funcitonInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(funcitonInfoPack.Data.ToString()); |
| | | if (funcitonInfo != null) |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | MainPage.Log($"读取云端设备数据:\r\n{ pack.Data.ToString()}"); |
| | | }else |
| | | { |
| | | MainPage.Log($"读取云端设备数据失败:\r\nCode:{pack.Code}; Msg:{pack.message}"); |
| | | } |
| | | |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载云端场景数据 |
| | | /// </summary> |
| | | public void DownloadSceneList() |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.GetSceneList(); |
| | | if(pack.Code == StateCode.SUCCESS) |
| | | { |
| | | |
| | | MainPage.Log($"读取云端场景数据:\r\n{pack.Data.ToString()}"); |
| | | } |
| | | else |
| | | { |
| | | |
| | | MainPage.Log($"读取云端场景数据失败:\r\nCode:{pack.Code}; Msg:{pack.message}"); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 删除手机存储都所有缓存功能数据 |
| | | /// </summary> |
| | | public void DelAllFunctionData() |
| | | { |
| | | var filePathList = FileUtils.ReadFiles(); |
| | | foreach (var filePath in filePathList) |
| | | { |
| | | if (filePath.StartsWith("FunctionData_") && filePath.Length == 13 + 28) |
| | | { |
| | | FileUtils.DeleteFile(filePath); |
| | | } |
| | | } |
| | | _FunctionList = new FunctionList(); |
| | | } |
| | | /// <summary> |
| | | /// 删除场景 |
| | | /// </summary> |
| | | public void DeleteScene(Scene scene) |
| | | { |
| | | scene.DeleteSign = true; |
| | | List.scenes.Remove(scene); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |