| | |
| | | using System.Threading; |
| | | using HDL_ON.DAL; |
| | | using HDL_ON.DAL.Server; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.Entity |
| | | { |
| | |
| | | case SPK.LightRGB: |
| | | case SPK.LightRGBW: |
| | | case SPK.LightCCT: |
| | | _FunctionList.lights.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Light>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Light>(functionDataString)); |
| | | var light = Newtonsoft.Json.JsonConvert.DeserializeObject<Light>(functionDataString); |
| | | _FunctionList.lights.Add(light); |
| | | deviceFunctionList.Add(light); |
| | | break; |
| | | case SPK.CurtainRoller: |
| | | case SPK.CurtainShades: |
| | | case SPK.CurtainSwitch: |
| | | case SPK.CurtainTrietex: |
| | | _FunctionList.curtains.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Curtain>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Curtain>(functionDataString)); |
| | | var curtain = Newtonsoft.Json.JsonConvert.DeserializeObject<Curtain>(functionDataString); |
| | | _FunctionList.curtains.Add(curtain); |
| | | deviceFunctionList.Add(curtain); |
| | | break; |
| | | case SPK.AcStandard: |
| | | _FunctionList.aCs.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(functionDataString)); |
| | | var ac = Newtonsoft.Json.JsonConvert.DeserializeObject<AC>(functionDataString); |
| | | _FunctionList.aCs.Add(ac); |
| | | deviceFunctionList.Add(ac); |
| | | break; |
| | | case SPK.FloorHeatStandard: |
| | | //恢复地热数据 |
| | | _FunctionList.floorHeatings.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(functionDataString)); |
| | | var fh = Newtonsoft.Json.JsonConvert.DeserializeObject<FloorHeating>(functionDataString); |
| | | _FunctionList.floorHeatings.Add(fh); |
| | | deviceFunctionList.Add(fh); |
| | | break; |
| | | case SPK.SensorPm25: |
| | | case SPK.SensorCO2: |
| | | case SPK.SensorTVOC: |
| | | case SPK.SensorTemperature: |
| | | case SPK.SensorHumidity: |
| | | //恢复环境数据 |
| | | _FunctionList.sensorsEnvironmentalScience.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(functionDataString)); |
| | | var sensor = Newtonsoft.Json.JsonConvert.DeserializeObject<Sensor>(functionDataString); |
| | | _FunctionList.sensorsEnvironmentalScience.Add(sensor); |
| | | deviceFunctionList.Add(sensor); |
| | | break; |
| | | case SPK.ElectricSocket: |
| | | //恢复插座数据 |
| | | _FunctionList.switchSockets.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<SwitchSocket>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<SwitchSocket>(functionDataString)); |
| | | var ele = Newtonsoft.Json.JsonConvert.DeserializeObject<SwitchSocket>(functionDataString); |
| | | _FunctionList.switchSockets.Add(ele); |
| | | deviceFunctionList.Add(ele); |
| | | break; |
| | | case SPK.ElectricTV: |
| | | //恢复电视数据 |
| | | _FunctionList.tVs.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<TV>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<TV>(functionDataString)); |
| | | var tv = Newtonsoft.Json.JsonConvert.DeserializeObject<TV>(functionDataString); |
| | | _FunctionList.tVs.Add(tv); |
| | | deviceFunctionList.Add(tv); |
| | | break; |
| | | case SPK.ElectricFan: |
| | | //恢复风扇数据 |
| | | _FunctionList.fans.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Fan>(functionDataString)); |
| | | deviceFunctionList.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<Fan>(functionDataString)); |
| | | var fan = Newtonsoft.Json.JsonConvert.DeserializeObject<Fan>(functionDataString); |
| | | _FunctionList.fans.Add(fan); |
| | | deviceFunctionList.Add(fan); |
| | | break; |
| | | } |
| | | } |
| | |
| | | } |
| | | try |
| | | { |
| | | deviceFunctionList.OrderByDescending(o => o.usageCount).ToList(); |
| | | deviceFunctionList = deviceFunctionList.OrderByDescending(o => o.usageCount).ToList(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | /// </summary> |
| | | 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>(); |
| | | scenes = new List<Scene>(); |
| | | deviceFunctionList = null; |
| | | _FunctionList.aCs = new List<AC>(); |
| | | _FunctionList.lights = new List<Light>(); |
| | | _FunctionList.curtains = new List<Curtain>(); |
| | | _FunctionList.floorHeatings = new List<FloorHeating>(); |
| | | _FunctionList.tVs = new List<TV>(); |
| | | _FunctionList.switchSockets = new List<SwitchSocket>(); |
| | | _FunctionList.fans = new List<Fan>(); |
| | | _FunctionList.sensorsEnvironmentalScience = new List<Sensor>(); |
| | | _FunctionList.scenes = new List<Scene>(); |
| | | _FunctionList.deviceFunctionList = null; |
| | | _FunctionList = null; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(pack.Data.ToString()); |
| | | if (deviceList != null) |
| | | { |
| | | foreach(var serverFunction in deviceList.list) |
| | | if (List.GetDeviceFunctionList().Count > 0) |
| | | { |
| | | MainPage.Log($"deviceId:{serverFunction.deviceId}"); |
| | | } |
| | | |
| | | ////将下载到到数据全部保存 |
| | | //new Thread(() => { |
| | | // foreach (var temp in deviceList.list) |
| | | // { |
| | | // temp.SaveFunctionData(); |
| | | // } |
| | | //}) |
| | | //{ IsBackground = true }.Start(); |
| | | for (int i =0;i < List.GetDeviceFunctionList().Count;) |
| | | { |
| | | var localFunction = List.GetDeviceFunctionList()[i]; |
| | | var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); |
| | | if (newFunction == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录 |
| | | for (int i = 0; i < List.GetDeviceFunctionList().Count;) |
| | | { |
| | | List.DeleteFunction(localFunction); |
| | | } |
| | | else |
| | | { |
| | | i++; |
| | | if (localFunction.modifyTime != newFunction.modifyTime) |
| | | var localFunction = List.GetDeviceFunctionList()[i]; |
| | | if (localFunction.functionCategory == FunctionCategory.Music) |
| | | { |
| | | localFunction.name = newFunction.name; |
| | | localFunction.collect = newFunction.collect; |
| | | localFunction.modifyTime = newFunction.modifyTime; |
| | | localFunction.roomIds = newFunction.roomIds; |
| | | localFunction.bus_Data = newFunction.bus_Data; |
| | | localFunction.SaveFunctionData(false); |
| | | i++; |
| | | continue; |
| | | } |
| | | deviceList.list.Remove(newFunction);//操作完的数据清理掉,剩下的就是新增的功能 |
| | | var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); |
| | | if (newFunction == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录 |
| | | { |
| | | List.DeleteFunction(localFunction); |
| | | } |
| | | else |
| | | { |
| | | MainPage.Log($"deviceType:{localFunction.spk} local:{localFunction.modifyTime} server:{newFunction.modifyTime}"); |
| | | i++; |
| | | if (localFunction.modifyTime != newFunction.modifyTime) |
| | | { |
| | | localFunction.name = newFunction.name; |
| | | localFunction.collect = newFunction.collect; |
| | | localFunction.modifyTime = newFunction.modifyTime; |
| | | localFunction.roomIds = newFunction.roomIds; |
| | | localFunction.bus = newFunction.bus; |
| | | localFunction.SaveFunctionData(false); |
| | | } |
| | | deviceList.list.Remove(newFunction);//操作完的数据清理掉,剩下的就是新增的功能 |
| | | } |
| | | } |
| | | } |
| | | //处理剩下的新增功能 |
| | |
| | | var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString()); |
| | | if (sceneList != null) |
| | | { |
| | | ////将下载到到数据全部保存 |
| | | //new Thread(() => { |
| | | // foreach (var temp in sceneList) |
| | | // { |
| | | // temp.SaveSceneData(); |
| | | // } |
| | | //}) |
| | | //{ IsBackground = true }.Start(); |
| | | for(int i=0;i<List.scenes.Count;) |
| | | for (int i=0;i<List.scenes.Count;) |
| | | { |
| | | var localScene = List.scenes[i]; |
| | | if (localScene == null) |
| | | { |
| | | List.scenes.Remove(localScene); |
| | | continue; |
| | | } |
| | | var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId); |
| | | if (newScene == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录 |
| | | { |
| | |
| | | { |
| | | if (DriverLayer.Control.Ins.IsRemote) |
| | | { |
| | | var functionIds = new List<string>(); |
| | | var page = new List<string>(); |
| | | int count = 0; |
| | | |
| | | foreach (var function in GetDeviceFunctionList()) |
| | | { |
| | | functionIds.Add(function.deviceId); |
| | | page.Add(function.deviceId); |
| | | count++; |
| | | if (count > 9) |
| | | { |
| | | DriverLayer.Control.Ins.SendApiReadCommand(page); |
| | | page.Clear(); |
| | | } |
| | | } |
| | | DriverLayer.Control.Ins.SendApiReadCommand(functionIds); |
| | | DriverLayer.Control.Ins.SendApiReadCommand(page); |
| | | } |
| | | else |
| | | { |
| | |
| | | }) |
| | | { 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) |
| | | { |
| | | 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)); |
| | | Common.FileUtlis.Files.WriteFileByBytes(scene.savePath, ssd); |
| | | } |
| | | result = tempScene; |
| | | return revPack.Code; |
| | | } |
| | | #endregion |
| | | |
| | | #region 功能文本相关 |
| | | /// <summary> |
| | | /// 属性名称显示文本 |
| | | /// 中英文显示 |
| | | /// </summary> |
| | | public string GetNameText(string key) |
| | | { |
| | | string text = ""; |
| | | switch (key) |
| | | { |
| | | case FunctionAttributeKey.OnOff: |
| | | text = Language.StringByID(StringId.OnOff); |
| | | break; |
| | | case FunctionAttributeKey.Brightness: |
| | | text = Language.StringByID(StringId.Brightness); |
| | | break; |
| | | case FunctionAttributeKey.RGB: |
| | | text = Language.StringByID(StringId.ColorValue); |
| | | break; |
| | | case FunctionAttributeKey.Mode: |
| | | text = Language.StringByID(StringId.Mode); |
| | | break; |
| | | case FunctionAttributeKey.FanSpeed: |
| | | text = Language.StringByID(StringId.FanSpeed); |
| | | break; |
| | | case FunctionAttributeKey.SetTemp: |
| | | text = Language.StringByID(StringId.Temp); |
| | | break; |
| | | case FunctionAttributeKey.IndoorTemp: |
| | | text = Language.StringByID(StringId.IndoorTemp); |
| | | break; |
| | | case FunctionAttributeKey.Delay: |
| | | text = Language.StringByID(StringId.Delay); |
| | | break; |
| | | case FunctionAttributeKey.CCT: |
| | | text = "CCT"; |
| | | break; |
| | | case FunctionAttributeKey.Percent: |
| | | text = Language.StringByID(StringId.PercentAdjustment); |
| | | break; |
| | | case FunctionAttributeKey.FadeTime: |
| | | text = Language.StringByID(StringId.FadeSpeed); |
| | | break; |
| | | } |
| | | return text; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 属性值单位 |
| | | /// </summary> |
| | | public string GetUintString(string key) |
| | | { |
| | | var us = ""; |
| | | switch (key) |
| | | { |
| | | case FunctionAttributeKey.SetTemp: |
| | | case FunctionAttributeKey.IndoorTemp: |
| | | us = "°C"; |
| | | break; |
| | | case FunctionAttributeKey.Percent: |
| | | case FunctionAttributeKey.Brightness: |
| | | us = "%"; |
| | | break; |
| | | } |
| | | return us; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取指定属性的显示文本 |
| | | /// 中英文显示 |
| | | /// </summary> |
| | | public string GetValueText(string key, string value) |
| | | { |
| | | string text = ""; |
| | | switch (key) |
| | | { |
| | | case FunctionAttributeKey.OnOff: |
| | | text = value == "on" ? Language.StringByID(StringId.On) : Language.StringByID(StringId.OFF); |
| | | break; |
| | | case FunctionAttributeKey.SetTemp: |
| | | case FunctionAttributeKey.IndoorTemp: |
| | | case FunctionAttributeKey.Brightness: |
| | | case FunctionAttributeKey.Percent: |
| | | if (value == "") |
| | | { |
| | | value = "0"; |
| | | } |
| | | text = value; |
| | | break; |
| | | case FunctionAttributeKey.Mode: |
| | | switch (value) |
| | | { |
| | | //----空调 |
| | | case "auto": |
| | | text = Language.StringByID(StringId.Auto); |
| | | break; |
| | | case "cool": |
| | | text = Language.StringByID(StringId.Cool); |
| | | break; |
| | | case "heat": |
| | | text = Language.StringByID(StringId.Heat); |
| | | break; |
| | | case "dry": |
| | | text = Language.StringByID(StringId.Dry); |
| | | break; |
| | | case "fan": |
| | | text = Language.StringByID(StringId.AirSupply); |
| | | break; |
| | | //-----地热 |
| | | case "day": |
| | | text = Language.StringByID(StringId.Day); |
| | | break; |
| | | case "night": |
| | | text = Language.StringByID(StringId.Night); |
| | | break; |
| | | case "away": |
| | | text = Language.StringByID(StringId.Away); |
| | | break; |
| | | case "normal": |
| | | text = Language.StringByID(StringId.Normal); |
| | | break; |
| | | case "timer": |
| | | text = Language.StringByID(StringId.Timer); |
| | | break; |
| | | } |
| | | break; |
| | | case FunctionAttributeKey.FanSpeed: |
| | | switch (value) |
| | | { |
| | | case "high": |
| | | text = Language.StringByID(StringId.HighWindSpeed); |
| | | break; |
| | | case "medium": |
| | | text = Language.StringByID(StringId.MiddleWindSpeed); |
| | | break; |
| | | case "low": |
| | | text = Language.StringByID(StringId.LowWindSpeed); |
| | | break; |
| | | case "auto": |
| | | text = Language.StringByID(StringId.Auto); |
| | | break; |
| | | default: |
| | | text = "low"; |
| | | break; |
| | | } |
| | | break; |
| | | case "high": |
| | | text = Language.StringByID(StringId.HighWindSpeed); |
| | | break; |
| | | case "medium": |
| | | text = Language.StringByID(StringId.MiddleWindSpeed); |
| | | break; |
| | | case "low": |
| | | text = Language.StringByID(StringId.LowWindSpeed); |
| | | break; |
| | | case "auto": |
| | | text = Language.StringByID(StringId.Auto); |
| | | break; |
| | | } |
| | | return text; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 延时显示的文本 |
| | | /// </summary> |
| | | public string GetDelayText(string delay) |
| | | { |
| | | string text = ""; |
| | | switch (delay) |
| | | { |
| | | case "0": |
| | | text = Language.StringByID(StringId.NoDelay); |
| | | break; |
| | | case "30": |
| | | text = "30s"; |
| | | break; |
| | | case "60": |
| | | text = "1min"; |
| | | break; |
| | | case "120": |
| | | text = "2min"; |
| | | break; |
| | | case "300": |
| | | text = "5min"; |
| | | break; |
| | | } |
| | | return text; |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | |
| | | } |