| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Threading; |
| | | using HDL_ON.Common; |
| | | using HDL_ON.DAL; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON.DriverLayer; |
| | | using Shared; |
| | | |
| | | 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 = FileUtlis.Files.ReadFiles(); |
| | | foreach (var filePath in filePathList) |
| | | { |
| | | _FunctionList.IniFunctionList(filePath); |
| | | } |
| | | #endregion |
| | | } |
| | | return _FunctionList; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 功能列表 |
| | | /// </summary> |
| | | public List<Function> Functions = new List<Function>(); |
| | | |
| | | /// <summary> |
| | | /// 空调列表 |
| | | /// </summary> |
| | | public List<AC> aCs = new List<AC>(); |
| | | /// <returns></returns> |
| | | public List<Function> GetAcList() |
| | | { |
| | | var spkList = SPK.AcSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 灯光列表 |
| | | /// </summary> |
| | | public List<Light> lights = new List<Light>(); |
| | | public List<Function> GetLightList() |
| | | { |
| | | var spkList = SPK.LightSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | /// <summary> |
| | | /// 窗帘列表 |
| | | /// </summary> |
| | | public List<Curtain> curtains = new List<Curtain>(); |
| | | public List<Function> GetCurtainList() |
| | | { |
| | | var spkList = SPK.CurtainSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 地热列表 |
| | | /// </summary> |
| | | public List<FloorHeating> floorHeatings = new List<FloorHeating>(); |
| | | public List<Function> GetFloorHeatingList() |
| | | { |
| | | var spkList = SPK.FhSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 新风列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<Function> GetAirFreshList() |
| | | { |
| | | var spkList = SPK.AirFreshSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 能源列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<Function> GetEnergyList() |
| | | { |
| | | var spkList = SPK.EnergySpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | #region 家电列表 electricals |
| | | /// <summary> |
| | | /// 家电列表 |
| | | /// </summary> |
| | | public List<Function> electricals |
| | | public List<Function> GetElectricals() |
| | | { |
| | | get |
| | | { |
| | | if(fans == null) |
| | | { |
| | | fans = new List<Fan>(); |
| | | } |
| | | if(switchSockets == null) |
| | | { |
| | | switchSockets = new List<SwitchSocket>(); |
| | | } |
| | | if(tVs == null) |
| | | { |
| | | tVs = new List<TV>(); |
| | | } |
| | | var list = new List<Function>(); |
| | | list.AddRange(fans); |
| | | list.AddRange(switchSockets); |
| | | list.AddRange(tVs); |
| | | return list; |
| | | } |
| | | var spkList = SPK.ElectricalSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 风扇列表 |
| | | /// 红外宝列表 |
| | | /// </summary> |
| | | public List<Fan> fans = new List<Fan>(); |
| | | /// <summary> |
| | | /// 电视列表 |
| | | /// </summary> |
| | | public List<TV> tVs = new List<TV>(); |
| | | /// <summary> |
| | | /// 家电列表 |
| | | /// </summary> |
| | | public List<SwitchSocket> switchSockets = new List<SwitchSocket>(); |
| | | public List<Function> GetIrModuleList() |
| | | { |
| | | return Functions.FindAll((obj) => obj.spk == SPK.IrModule); |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 音乐列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<Function> GetMusicList() |
| | | { |
| | | var spkList = SPK.MusicSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 环境传感器列表 |
| | | /// </summary> |
| | | public List<Sensor> sensorsEnvironmentalScience = new List<Sensor>(); |
| | | public List<Function> GetEnvirSensorsList() |
| | | { |
| | | var spkList = SPK.EnvironDeviceSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | /// <summary> |
| | | /// 安防设备列表 |
| | | /// </summary> |
| | | public List<Function> GetArmSensorList() |
| | | { |
| | | var spkList = SPK.ArmSensorSpkList(); |
| | | return Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 可视对讲列表,当为null或size为0则不显示可视对讲icon |
| | | /// </summary> |
| | | // public UI.UI2.FuntionControlView.Video.VideoClouds videoIntercom; |
| | | public List<UI.UI2.FuntionControlView.Video.Video> videoIntercom = new List<UI.UI2.FuntionControlView.Video.Video>(); |
| | | |
| | | List<Function> _OtherBrandFunction; |
| | | /// <summary> |
| | | /// 第三方品牌功能 |
| | | /// </summary> |
| | | public List<Function> OtherBrandFunction |
| | | { |
| | | get |
| | | { |
| | | if(_OtherBrandFunction == null) |
| | | { |
| | | _OtherBrandFunction = new List<Function>(); |
| | | var spkList = SPK.GetAll3tySPK(); |
| | | _OtherBrandFunction = Functions.FindAll((obj) => spkList.Contains(obj.spk)); |
| | | } |
| | | return _OtherBrandFunction; |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 场景列表 |
| | | /// </summary> |
| | | public List<Scene> scenes = new List<Scene>(); |
| | | /// <summary> |
| | | /// 功能列表 |
| | | /// </summary> |
| | | List<Function> deviceFunctionList; |
| | | //[Newtonsoft.Json.JsonIgnore] |
| | | //public List<Function> functions = new List<Function>(); |
| | | |
| | | /// <summary> |
| | | /// 安防列表 |
| | | /// </summary> |
| | | public List<SecurityAlarm> securities = new List<SecurityAlarm>(); |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取所有功能列表 |
| | | /// 加载功能列表 |
| | | /// </summary> |
| | | public List<Function> GetAllFunction() |
| | | /// <param name="filePath"></param> |
| | | /// <param name="checkRepeat"> |
| | | /// <para>考虑到性能问题追加此变量,是否检测重复,只对function有效</para> |
| | | /// <para>true:当重复存在时,替换掉</para> |
| | | /// <para>false:直接无条件添加</para></param> |
| | | public void IniFunctionList(string filePath, bool checkRepeat = false) |
| | | { |
| | | var fs = new List<Function>(); |
| | | fs.AddRange(GetAllDeviceFunctionList()); |
| | | fs.AddRange(scenes); |
| | | return fs; |
| | | try |
| | | { |
| | | // todo 增加设备,增加功能进功能列表 |
| | | if (filePath.StartsWith("FunctionData_")) |
| | | { |
| | | var functionDataBytes = FileUtlis.Files.ReadFile(filePath); |
| | | var functionDataString = System.Text.Encoding.UTF8.GetString(functionDataBytes); |
| | | var tempFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString); |
| | | if (tempFunction == null) |
| | | { |
| | | MainPage.Log("null"); |
| | | FileUtlis.Files.DeleteFile(filePath); |
| | | return; |
| | | } |
| | | //音乐部分要修改 |
| | | //if(tempFunction.spk.ToString() == SPK.MusicStandard) |
| | | //{ |
| | | // UI.Music.A31MusicModel.A31MusicModelList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<UI.Music.A31MusicModel>(functionDataString)); |
| | | //} |
| | | if (checkRepeat == true) |
| | | { |
| | | //检测重复 |
| | | for (int i = 0; i < Functions.Count; i++) |
| | | { |
| | | if (Functions[i].deviceId == tempFunction.deviceId) |
| | | { |
| | | //先移除掉再加 |
| | | Functions.RemoveAt(i); |
| | | Functions.Add(tempFunction); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | Functions.Add(tempFunction); |
| | | } |
| | | if (filePath.StartsWith("SceneData_")) |
| | | { |
| | | var sceneDataBytes = FileUtlis.Files.ReadFile(filePath); |
| | | var sceneDataString = System.Text.Encoding.UTF8.GetString(sceneDataBytes); |
| | | var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(sceneDataString); |
| | | List.scenes.Add(tempScene); |
| | | } |
| | | else if (filePath.StartsWith("SecurityData_")) |
| | | { |
| | | var dataBytes = FileUtlis.Files.ReadFile(filePath); |
| | | var dataString = System.Text.Encoding.UTF8.GetString(dataBytes); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityAlarm>(dataString); |
| | | if (temp == null) |
| | | { |
| | | MainPage.Log("null"); |
| | | FileUtlis.Files.DeleteFile(filePath); |
| | | return; |
| | | } |
| | | if (checkRepeat == true) |
| | | { |
| | | //检测重复 |
| | | for (int i = 0; i < securities.Count; i++) |
| | | { |
| | | if (securities[i].sid == temp.sid) |
| | | { |
| | | //先移除掉再加 |
| | | securities.RemoveAt(i); |
| | | securities.Add(temp); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | securities.Add(temp); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"IniFunctionList error : {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取设备功能列表 |
| | | /// </summary> |
| | | public List<Function> GetAllDeviceFunctionList() |
| | | public List<Function> GetDeviceFunctionList(SPK.BrandType brandType = SPK.BrandType.All) |
| | | { |
| | | //if (deviceFunctionList == null || deviceFunctionList.Count == 0) |
| | | List<Function> resultFunctions = new List<Function>(); |
| | | if (brandType == SPK.BrandType.All) |
| | | { |
| | | 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(); |
| | | else |
| | | { |
| | | switch (brandType) |
| | | { |
| | | case SPK.BrandType.Hdl: |
| | | foreach (var function in Functions) |
| | | { |
| | | if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(function.spk)) |
| | | { |
| | | resultFunctions.Add(function); |
| | | } |
| | | } |
| | | break; |
| | | |
| | | case SPK.BrandType.Tuya: |
| | | lock (Functions) |
| | | { |
| | | foreach (var function in Functions) |
| | | { |
| | | if (SPK.Get3tySpk(SPK.BrandType.Tuya).Contains(function.spk)) |
| | | { |
| | | resultFunctions.Add(function); |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | return resultFunctions; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"设备功能排序异常:{ex.Message}"); |
| | | } |
| | | return deviceFunctionList; |
| | | |
| | | return Functions; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 清空设备功能列表 |
| | | /// </summary> |
| | | public void ClearAllDeviceFunctionList() |
| | | public void Clear() |
| | | { |
| | | aCs = new List<AC>(); |
| | | lights = new List<Light>(); |
| | | curtains = new List<Curtain>(); |
| | | floorHeatings = new List<FloorHeating>(); |
| | | tVs = new List<TV>(); |
| | | switchSockets = new List<SwitchSocket>(); |
| | | fans = new List<Fan>(); |
| | | sensorsEnvironmentalScience = new List<Sensor>(); |
| | | //functions = new List<Function>(); |
| | | scenes = new List<Scene>(); |
| | | deviceFunctionList = null; |
| | | Functions = new List<Function>(); |
| | | _FunctionList = null; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 接收bus软件上传的功能 |
| | | /// tcp方式 |
| | | /// 功能绑定房间 |
| | | /// </summary> |
| | | /// <param name="sidObj"></param> |
| | | public void AddDeviceFunction(Function sidObj0) |
| | | public string FunctionsBindRooms(List<string> roomIds,List<string> deviceIds) |
| | | { |
| | | switch (sidObj0.functionType) |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.BindDeviceToRoom(deviceIds, roomIds); |
| | | if(pack.Code == StateCode.SUCCESS) |
| | | { |
| | | case FunctionType.AC: |
| | | var sidObj = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.aCs.Add(sidObj); |
| | | sidObj.SaveFunctionData(); |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | var sidObj1 = Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.floorHeatings.Add(sidObj1); |
| | | sidObj1.SaveFunctionData(); |
| | | break; |
| | | case FunctionType.Dimmer: |
| | | case FunctionType.RGB: |
| | | case FunctionType.Relay: |
| | | var sidObj2 = Newtonsoft.Json.JsonConvert.DeserializeObject<Light>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.lights.Add(sidObj2); |
| | | 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(); |
| | | break; |
| | | case FunctionType.TV: |
| | | var sidObj4 = Newtonsoft.Json.JsonConvert.DeserializeObject<TV>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.tVs.Add(sidObj4); |
| | | sidObj4.SaveFunctionData(); |
| | | break; |
| | | case FunctionType.Socket: |
| | | var sidObj5 = Newtonsoft.Json.JsonConvert.DeserializeObject<SwitchSocket>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.switchSockets.Add(sidObj5); |
| | | sidObj5.SaveFunctionData(); |
| | | break; |
| | | case FunctionType.Fan: |
| | | var sidObj6 = Newtonsoft.Json.JsonConvert.DeserializeObject<Fan>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.fans.Add(sidObj6); |
| | | sidObj6.SaveFunctionData(); |
| | | break; |
| | | case FunctionType.CO2: |
| | | case FunctionType.TVOC: |
| | | case FunctionType.PM25: |
| | | case FunctionType.Temp: |
| | | case FunctionType.Humidity: |
| | | var sidObj7 = Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(Newtonsoft.Json.JsonConvert.SerializeObject(sidObj0)); |
| | | DB_ResidenceData.functionList.sensorsEnvironmentalScience.Add(sidObj7); |
| | | sidObj7.SaveFunctionData(); |
| | | break; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 接收bus软件上传的功能 |
| | | /// http udp |
| | | /// </summary> |
| | | /// <param name="obj"></param> |
| | | public void AddFunction(object obj) |
| | | { |
| | | var f = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(obj.ToString()); |
| | | |
| | | switch (f.functionCategory) |
| | | } |
| | | else |
| | | { |
| | | case FunctionCategory.Thermostat: |
| | | switch (f.functionType) |
| | | { |
| | | case FunctionType.AC: |
| | | aCs.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(obj.ToString())); |
| | | break; |
| | | case FunctionType.FloorHeating: |
| | | floorHeatings.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(obj.ToString())); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Light: |
| | | lights.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Light>(obj.ToString())); |
| | | break; |
| | | case FunctionCategory.Curtain: |
| | | curtains.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Curtain>(obj.ToString())); |
| | | break; |
| | | case FunctionCategory.Electrical: |
| | | switch(f.functionType) |
| | | { |
| | | case FunctionType.TV: |
| | | electricals.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<TV>(obj.ToString())); |
| | | break; |
| | | case FunctionType.Socket: |
| | | electricals.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<SwitchSocket>(obj.ToString())); |
| | | break; |
| | | case FunctionType.Fan: |
| | | electricals.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Fan>(obj.ToString())); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionCategory.Sensor: |
| | | switch(f.functionType) |
| | | { |
| | | case FunctionType.TVOC: |
| | | case FunctionType.CO2: |
| | | case FunctionType.PM25: |
| | | case FunctionType.Humidity: |
| | | //case FunctionType.Noise: |
| | | sensorsEnvironmentalScience.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(obj.ToString())); |
| | | break; |
| | | } |
| | | break; |
| | | IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); |
| | | } |
| | | return pack.Code; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除场景 |
| | | /// todo |
| | | /// </summary> |
| | | public void DeleteScene(Scene scene,bool upSevser) |
| | | { |
| | | if (upSevser) |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var packCode = pm.DeleteScene(scene.userSceneId); |
| | | if (packCode == StateCode.SUCCESS) |
| | | { |
| | | FileUtlis.Files.DeleteFile(scene.savePath); |
| | | List.scenes.Remove(scene); |
| | | } |
| | | else |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter(packCode); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | FileUtlis.Files.DeleteFile(scene.savePath); |
| | | List.scenes.Remove(scene); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除本地功能及文件 |
| | | /// </summary> |
| | | public void DeleteFunction(Function delTemp) |
| | | { |
| | | Functions.Remove(Functions.Find((obj) => obj.deviceId == delTemp.deviceId)); |
| | | FileUtlis.Files.DeleteFile(delTemp.savePath); |
| | | } |
| | | |
| | | bool lockReadFunctionStatus = false; |
| | | |
| | | /// <summary> |
| | | /// 读取第三方设备状态 |
| | | /// </summary> |
| | | public void Read3tyFunctionStatus() |
| | | { |
| | | //读取涂鸦设备状态 |
| | | if (GetDeviceFunctionList(SPK.BrandType.Tuya).Count > 0) |
| | | { |
| | | var page = new List<string>(); |
| | | int count = 0; |
| | | foreach (var function in GetDeviceFunctionList(SPK.BrandType.Tuya)) |
| | | { |
| | | page.Add(function.deviceId); |
| | | count++; |
| | | if (count > 9) |
| | | { |
| | | DriverLayer.Control.Ins.ReadFunctionsInfo(page); |
| | | page.Clear(); |
| | | count = 0; |
| | | } |
| | | } |
| | | DriverLayer.Control.Ins.ReadFunctionsInfo(page); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取全部功能的状态 |
| | | /// </summary> |
| | | public void ReadAllFunctionStatus() |
| | | { |
| | | if (lockReadFunctionStatus) |
| | | { |
| | | MainPage.Log($"多次进入--返回"); |
| | | return; |
| | | } |
| | | new Thread(() => |
| | | { |
| | | if (lockReadFunctionStatus) |
| | | { |
| | | MainPage.Log($"多次进入--返回"); |
| | | return; |
| | | } |
| | | MainPage.Log($"进入--读取"); |
| | | lockReadFunctionStatus = true; |
| | | try |
| | | { |
| | | Read3tyFunctionStatus(); |
| | | |
| | | if(DriverLayer.Control.Ins.GatewayOnline_Local) |
| | | { |
| | | foreach (var function in GetDeviceFunctionList(SPK.BrandType.Hdl)) |
| | | { |
| | | MainPage.Log($"读取功能状态:{function.name} : {function.sid} "); |
| | | Control.Ins.SendReadCommand(function); |
| | | } |
| | | if(DB_ResidenceData.Instance.GatewayType == 1) |
| | | { |
| | | Dictionary<string, string> pairs = new Dictionary<string, string>(); |
| | | string sendId = Control.Ins.msg_id.ToString(); |
| | | pairs.Add("id", sendId); |
| | | pairs.Add("time_stamp", Utlis.GetTimestamp()); |
| | | var readSecurityStatusJson = Newtonsoft.Json.JsonConvert.SerializeObject(pairs); |
| | | var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.ct.ReadSecurityStatus, readSecurityStatusJson); |
| | | MainPage.Log($"本地通讯 读取安防状态:{readSecurityStatusJson}"); |
| | | new Control_Udp().SendLocalHdlLinkData(sendBytes, sendId); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var page = new List<string>(); |
| | | int count = 0; |
| | | |
| | | foreach (var function in GetDeviceFunctionList(SPK.BrandType.Hdl)) |
| | | { |
| | | page.Add(function.deviceId); |
| | | count++; |
| | | if (count > 9) |
| | | { |
| | | DriverLayer.Control.Ins.SendApiReadCommand(page); |
| | | page.Clear(); |
| | | count = 0; |
| | | } |
| | | } |
| | | DriverLayer.Control.Ins.SendApiReadCommand(page); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"Refresh Residence Function Status Error : {ex.Message}"); |
| | | } |
| | | finally |
| | | { |
| | | lockReadFunctionStatus = false; |
| | | MainPage.Log($"结束--读取"); |
| | | } |
| | | |
| | | |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | #region 场景相关 |
| | | /// <summary> |
| | | /// 添加场景 |
| | | /// </summary> |
| | | public string AddScene(Scene scene, out Scene result) |
| | | { |
| | | Scene tempScene = null; |
| | | var pm = new HttpServerRequest(); |
| | | var revPack = pm.AddScene(scene); |
| | | if (revPack.Code == StateCode.SUCCESS) |
| | | { |
| | | if (MainPage.NoLoginMode) |
| | | { |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(scene)); |
| | | FileUtlis.Files.WriteFileByBytes(scene.savePath, ssd); |
| | | result = scene; |
| | | } |
| | | else |
| | | { |
| | | var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(revPack.Data.ToString()); |
| | | tempScene = sceneList.Find((obj) => obj.sid == scene.sid); |
| | | var ssd = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(tempScene)); |
| | | FileUtlis.Files.WriteFileByBytes(scene.savePath, ssd); |
| | | result = tempScene; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | result = tempScene; |
| | | } |
| | | return revPack.Code; |
| | | } |
| | | #endregion |
| | | |
| | | #region 收藏功能 |
| | | |
| | | /// <summary> |
| | | /// 收藏场景 |
| | | /// </summary> |
| | | public string CollectScene(Scene scene) |
| | | { |
| | | var result = ""; |
| | | if (scene.collect) |
| | | { |
| | | result = ApiUtlis.Ins.HttpRequest.CollectDevice(scene.userSceneId).Code; |
| | | } |
| | | else |
| | | { |
| | | result = ApiUtlis.Ins.HttpRequest.CancelCollectDevice(scene.userSceneId).Code; |
| | | } |
| | | |
| | | //提示错误 |
| | | if (result != StateCode.SUCCESS) |
| | | { |
| | | IMessageCommon.Current.ShowErrorInfoAlter(result); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region |
| | | |
| | | |
| | | |
| | | #endregion |
| | | } |
| | | |
| | | } |