| | |
| | | { |
| | | _FunctionList = new FunctionList(); |
| | | #region 恢复数据 |
| | | var filePathList = FileUtils.ReadFiles(); |
| | | var filePathList = Common.FileUtlis.Files.ReadFiles(); |
| | | foreach (var filePath in filePathList) |
| | | { |
| | | _FunctionList.IniFunctionList(filePath); |
| | |
| | | { |
| | | if (filePath.StartsWith("FunctionData_")) |
| | | { |
| | | var functionDataBytes = FileUtils.ReadFile(filePath); |
| | | var functionDataBytes = Common.FileUtlis.Files.ReadFile(filePath); |
| | | var functionDataString = System.Text.Encoding.UTF8.GetString(functionDataBytes); |
| | | var tempFunction = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(functionDataString); |
| | | if (tempFunction == null) |
| | | { |
| | | Common.FileUtlis.Files.DeleteFile(filePath); |
| | | return; |
| | | } |
| | | if (tempFunction.DeleteSign) |
| | | { |
| | | //todo 删除云端数据 20201203--App不能删除功能数据 |
| | |
| | | } |
| | | if (filePath.StartsWith("SceneData_")) |
| | | { |
| | | var sceneDataBytes = FileUtils.ReadFile(filePath); |
| | | var sceneDataBytes = Common.FileUtlis.Files.ReadFile(filePath); |
| | | var sceneDataString = System.Text.Encoding.UTF8.GetString(sceneDataBytes); |
| | | var tempScene = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(sceneDataString); |
| | | List.scenes.Add(tempScene); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 功能绑定房间 |
| | | /// </summary> |
| | | public string FunctionsBindRooms(List<string> roomIds,List<string> deviceIds) |
| | | { |
| | | var pm = new HttpServerRequest(); |
| | | var pack = pm.BindDeviceToRoom(deviceIds, roomIds); |
| | | if(pack.Code == StateCode.SUCCESS) |
| | | { |
| | | |
| | | } |
| | | else |
| | | { |
| | | Utlis.ShowTip(Shared.Language.StringByID(StringId.EditFunctionInfoFail) + "\r\nCode:" + pack.Code); |
| | | } |
| | | return pack.Code; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下来云端设备数据 |
| | | /// </summary> |
| | | public void DownloadFunctionList() |
| | |
| | | // } |
| | | //}) |
| | | //{ IsBackground = true }.Start(); |
| | | foreach (var localFunction in List.GetAllDeviceFunctionList()) |
| | | for (int i =0;i < List.GetAllDeviceFunctionList().Count;) |
| | | { |
| | | var localFunction = List.GetAllDeviceFunctionList()[i]; |
| | | var newFunction = deviceList.list.Find((obj) => obj.deviceId == localFunction.deviceId); |
| | | if (newFunction == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录 |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | i++; |
| | | if (localFunction.modifyTime != newFunction.modifyTime) |
| | | { |
| | | localFunction.name = newFunction.name; |
| | |
| | | List.IniFunctionList(newFunction.savePath); |
| | | } |
| | | } |
| | | MainPage.Log($"读取云端设备数据:\r\n{ pack.Data.ToString()}"); |
| | | //MainPage.Log($"读取云端设备数据:\r\n{ pack.Data.ToString()}"); |
| | | } |
| | | else |
| | | { |
| | |
| | | var pack = pm.GetSceneList(); |
| | | if(pack.Code == StateCode.SUCCESS) |
| | | { |
| | | MainPage.Log($"读取云端场景数据:\r\n{pack.Data.ToString()}"); |
| | | //MainPage.Log($"读取云端场景数据:\r\n{pack.Data.ToString()}"); |
| | | var sceneList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Scene>>(pack.Data.ToString()); |
| | | if (sceneList != null) |
| | | { |
| | |
| | | // } |
| | | //}) |
| | | //{ IsBackground = true }.Start(); |
| | | foreach (var localScene in List.scenes) |
| | | for(int i=0;i<List.scenes.Count;) |
| | | { |
| | | var localScene = List.scenes[i]; |
| | | var newScene = sceneList.Find((obj) => obj.userSceneId == localScene.userSceneId); |
| | | if (newScene == null)//如果云端最新数据没有该条数据,则本地需要删掉该数据记录 |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | i++; |
| | | if (localScene.modifyTime != newScene.modifyTime) |
| | | { |
| | | localScene.name = newScene.name; |
| | |
| | | /// </summary> |
| | | public void DelAllFunctionData() |
| | | { |
| | | var filePathList = FileUtils.ReadFiles(); |
| | | var filePathList = Common.FileUtlis.Files.ReadFiles(); |
| | | foreach (var filePath in filePathList) |
| | | { |
| | | if (filePath.StartsWith("FunctionData_") && filePath.Length == 13 + 28) |
| | | { |
| | | FileUtils.DeleteFile(filePath); |
| | | Common.FileUtlis.Files.DeleteFile(filePath); |
| | | } |
| | | } |
| | | _FunctionList = new FunctionList(); |
| | |
| | | var packCode = pm.DeleteScene(scene.userSceneId); |
| | | if (packCode == StateCode.SUCCESS) |
| | | { |
| | | FileUtils.DeleteFile(scene.savePath); |
| | | Common.FileUtlis.Files.DeleteFile(scene.savePath); |
| | | List.scenes.Remove(scene); |
| | | } |
| | | else |
| | |
| | | } |
| | | else |
| | | { |
| | | FileUtils.DeleteFile(scene.savePath); |
| | | Common.FileUtlis.Files.DeleteFile(scene.savePath); |
| | | List.scenes.Remove(scene); |
| | | } |
| | | } |
| | |
| | | _FunctionList.fans.Remove(_FunctionList.fans.Find((obj) => obj.deviceId == delTemp.deviceId)); |
| | | break; |
| | | } |
| | | FileUtils.DeleteFile(delTemp.savePath); |
| | | Common.FileUtlis.Files.DeleteFile(delTemp.savePath); |
| | | } |
| | | |
| | | bool lockReadFunctionStatus = false; |
| | |
| | | lockReadFunctionStatus = true; |
| | | try |
| | | { |
| | | foreach (var function in GetAllDeviceFunctionList()) |
| | | if (DriverLayer.Control.Ins.IsRemote) |
| | | { |
| | | switch (function.functionCategory) |
| | | var functionIds = new List<string>(); |
| | | foreach (var function in GetAllDeviceFunctionList()) |
| | | { |
| | | case FunctionCategory.Light: |
| | | case FunctionCategory.Electrical: |
| | | case FunctionCategory.SwitchDevice: |
| | | case FunctionCategory.Curtain: |
| | | case FunctionCategory.Thermostat: |
| | | DriverLayer.Control.Ins.SendReadCommand(function); |
| | | break; |
| | | functionIds.Add(function.deviceId); |
| | | } |
| | | DriverLayer.Control.Ins.SendApiReadCommand(functionIds); |
| | | } |
| | | else |
| | | { |
| | | foreach (var function in GetAllDeviceFunctionList()) |
| | | { |
| | | switch (function.functionCategory) |
| | | { |
| | | case FunctionCategory.Light: |
| | | case FunctionCategory.Electrical: |
| | | case FunctionCategory.SwitchDevice: |
| | | case FunctionCategory.Curtain: |
| | | case FunctionCategory.Thermostat: |
| | | DriverLayer.Control.Ins.SendReadCommand(function); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |